/** * Playground Service * * Handles API interactions for the Playground feature including * session management, message handling, and polling for updates. * * @module services/playgroundService */ import type { PlaygroundSession, PlaygroundMessage, PlaygroundMessagesApiResponse, PlaygroundSessionStatus } from '../types/playground.js'; /** * Pagination options for {@link PlaygroundService.getMessages}. * `since`, `before`, and `latest` are mutually exclusive. */ export interface GetMessagesOptions { /** Forward cursor — only messages with sequenceNumber greater than this value */ since?: number; /** Backward cursor — the page of messages immediately older than this sequence number */ before?: number; /** Return the most recent `limit` messages (conversation tail) */ latest?: boolean; /** Maximum number of messages to return */ limit?: number; } /** * Playground Service class * * Provides methods to interact with the playground API endpoints * including session management, message handling, and polling. */ export declare class PlaygroundService { private static instance; private pollingInterval; private pollingSessionId; private currentBackoff; private lastSequenceNumber; private constructor(); /** * Get the singleton instance of PlaygroundService * * @returns The PlaygroundService singleton instance */ static getInstance(): PlaygroundService; /** * Get the endpoint configuration * * @throws Error if endpoint configuration is not set * @returns The endpoint configuration */ private getConfig; /** * Generic API request helper * * @param url - The URL to fetch * @param options - Fetch options * @returns The parsed JSON response */ private request; /** * List all playground sessions for a workflow * * @param workflowId - The workflow UUID * @param options - Optional pagination parameters * @returns Array of playground sessions */ listSessions(workflowId: string, options?: { limit?: number; offset?: number; }): Promise; /** * Create a new playground session * * @param workflowId - The workflow UUID * @param name - Optional session name * @param metadata - Optional session metadata * @returns The created session */ createSession(workflowId: string, name?: string, metadata?: Record): Promise; /** * Get a playground session by ID * * @param sessionId - The session UUID * @returns The session details */ getSession(sessionId: string): Promise; /** * Delete a playground session * * @param sessionId - The session UUID */ deleteSession(sessionId: string): Promise; /** * Get messages from a playground session. * * Three pagination modes (see the OpenAPI spec for the contract): * - `since`: forward cursor, returns messages with sequenceNumber > value (polling the live tail) * - `before`: backward cursor, returns the page immediately older than the value (scroll-up) * - `latest`: returns the most recent `limit` messages (initial load) * `since`, `before`, and `latest` are mutually exclusive. * * @param sessionId - The session UUID * @param options - Pagination options * @returns Messages and session status */ getMessages(sessionId: string, options?: GetMessagesOptions): Promise; /** * Send a message to a playground session * * @param sessionId - The session UUID * @param content - The message content * @param inputs - Optional additional inputs for workflow nodes * @returns The created message */ sendMessage(sessionId: string, content: string, inputs?: Record): Promise; /** * Stop execution in a playground session * * @param sessionId - The session UUID */ stopExecution(sessionId: string): Promise; /** * Start polling for new messages * * @param sessionId - The session UUID to poll * @param callback - Callback function to handle new messages * @param interval - Polling interval in milliseconds (default: 1500) * @param shouldStopPolling - Optional override for stop conditions (default: defaultShouldStopPolling) * @param initialSequenceNumber - Optional sequence number to seed polling from (avoids re-fetching already loaded messages) */ startPolling(sessionId: string, callback: (response: PlaygroundMessagesApiResponse) => void, interval?: number, shouldStopPolling?: (status: PlaygroundSessionStatus) => boolean, initialSequenceNumber?: number | null): void; /** * Stop polling for messages */ stopPolling(): void; /** * Check if polling is active * * @returns True if polling is active */ isPolling(): boolean; /** * Get the current polling session ID * * @returns The session ID being polled, or null */ getPollingSessionId(): string | null; /** * Get the last sequence number used as cursor for incremental polling * * @returns The last sequence number, or null */ getLastSequenceNumber(): number | null; } /** * Export singleton instance */ export declare const playgroundService: PlaygroundService;