/** * Playground Store * * Svelte 5 rune-based state for managing playground state including sessions, * messages, and execution status. * * @module stores/playgroundStore */ import type { PlaygroundSession, PlaygroundMessage, PlaygroundInputField, PlaygroundSessionStatus, PlaygroundMessagesApiResponse } from '../types/playground.js'; import type { Workflow } from '../types/index.js'; /** * Get the current session */ export declare function getCurrentSession(): PlaygroundSession | null; /** * Get all sessions */ export declare function getSessions(): PlaygroundSession[]; /** * Get all messages */ export declare function getMessages(): PlaygroundMessage[]; /** * Get executing state */ export declare function getIsExecuting(): boolean; /** * Get loading state */ export declare function getIsLoading(): boolean; /** * Get error state */ export declare function getError(): string | null; /** * Get the current workflow */ export declare function getCurrentWorkflow(): Workflow | null; /** * Get the last poll timestamp */ export declare function getLastPollTimestamp(): string | null; /** * Get current session status */ export declare function getSessionStatus(): PlaygroundSessionStatus; /** * Get message count */ export declare function getMessageCount(): number; /** * Get chat messages (excludes log messages) */ export declare function getChatMessages(): PlaygroundMessage[]; /** * Get log messages only */ export declare function getLogMessages(): PlaygroundMessage[]; /** * Get the latest message */ export declare function getLatestMessage(): PlaygroundMessage | null; /** * Get input fields from workflow input nodes * * Analyzes the workflow to extract input nodes and their configuration * schemas for auto-generating input forms. */ export declare function getInputFields(): PlaygroundInputField[]; /** * Check if workflow has a chat input */ export declare function getHasChatInput(): boolean; /** * Get session count */ export declare function getSessionCount(): number; /** * Playground store actions for modifying state */ export declare const playgroundActions: { /** * Set the current workflow * * @param workflow - The workflow to test */ setWorkflow: (workflow: Workflow | null) => void; /** * Set the current session * * @param session - The session to set as active */ setCurrentSession: (session: PlaygroundSession | null) => void; /** * Update session status * * @param status - The new status */ updateSessionStatus: (status: PlaygroundSessionStatus) => void; /** * Set the sessions list * * @param sessionList - Array of sessions */ setSessions: (sessionList: PlaygroundSession[]) => void; /** * Add a new session to the list * * @param session - The session to add */ addSession: (session: PlaygroundSession) => void; /** * Remove a session from the list * * @param sessionId - The session ID to remove */ removeSession: (sessionId: string) => void; /** * Set messages for the current session * Messages are automatically sorted chronologically * * @param messageList - Array of messages */ setMessages: (messageList: PlaygroundMessage[]) => void; /** * Add a message to the current session * Messages are automatically sorted chronologically after adding * * @param message - The message to add */ addMessage: (message: PlaygroundMessage) => void; /** * Add multiple messages to the current session * Messages are deduplicated and automatically sorted chronologically * * @param newMessages - Array of messages to add */ addMessages: (newMessages: PlaygroundMessage[]) => void; /** * Clear all messages */ clearMessages: () => void; /** * Set the executing state * * @param executing - Whether execution is in progress */ setExecuting: (executing: boolean) => void; /** * Set the loading state * * @param loading - Whether loading is in progress */ setLoading: (loading: boolean) => void; /** * Set an error message * * @param errorMessage - The error message or null to clear */ setError: (errorMessage: string | null) => void; /** * Update the last poll timestamp * * @param timestamp - ISO 8601 timestamp */ updateLastPollTimestamp: (timestamp: string) => void; /** * Reset all playground state */ reset: () => void; /** * Switch to a different session * * @param sessionId - The session ID to switch to */ switchSession: (sessionId: string) => void; }; /** * Create a polling callback that processes poll responses. * This is the single source of truth for how poll responses update stores. * Used by mount.ts, Playground.svelte, and refreshSessionMessages. * * @param isTerminalStatus - Function to determine if a status clears isExecuting (default: defaultIsTerminalStatus) * @returns A callback suitable for playgroundService.startPolling() or pushMessages() */ export declare function createPollingCallback(isTerminalStatus?: (status: PlaygroundSessionStatus) => boolean): (response: PlaygroundMessagesApiResponse) => void; /** * Get the current session ID * * @returns The current session ID or null */ export declare function getCurrentSessionId(): string | null; /** * Check if a specific session is selected * * @param sessionId - The session ID to check * @returns True if the session is currently selected */ export declare function isSessionSelected(sessionId: string): boolean; /** * Get all messages as a snapshot * * @returns Array of all messages */ export declare function getMessagesSnapshot(): PlaygroundMessage[]; /** * Get the latest message timestamp for polling * * @returns ISO 8601 timestamp of the latest message, or null */ export declare function getLatestMessageTimestamp(): string | null; /** * Subscribe to session status changes using $effect.root. * This is designed for use in non-component contexts (e.g., mount.ts). * * @param callback - Called when session status changes * @returns Cleanup function to stop the subscription */ export declare function subscribeToSessionStatus(callback: (status: PlaygroundSessionStatus, previousStatus: PlaygroundSessionStatus) => void): () => void; /** * Refresh messages for the current session * * This function is useful after interrupt resolution when polling * has stopped but new messages may exist on the server. * * @param fetchMessages - Async function to fetch messages from the API * @param isTerminalStatus - Optional override for terminal status check * @returns Promise that resolves when messages are refreshed */ export declare function refreshSessionMessages(fetchMessages: (sessionId: string) => Promise, isTerminalStatus?: (status: PlaygroundSessionStatus) => boolean): Promise;