/** * 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, PlaygroundExecution } 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 sequence number cursor */ export declare function getLastPollSequenceNumber(): number | null; /** * Get current session status */ export declare function getSessionStatus(): PlaygroundSessionStatus; /** * Whether the user can currently send a message. * False when executing, when awaiting input, or when no session exists. */ export declare function getCanSendMessage(): boolean; /** * 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; export declare function getPinnedExecutionId(): string | null; export declare function getLatestExecutionId(): string | null; export declare function getActiveExecutionId(): string | null; /** * Main pipeline runs for the run-switcher. Excludes sub-flow runs, which can't * render their own graph and so aren't user-selectable. */ export declare function getSelectableExecutions(): PlaygroundExecution[]; /** * Counter that increments whenever new messages arrive and the pipeline display * should re-fetch — i.e. when following latest or pinned to the latest execution. * Pass to PipelinePanel's refreshTrigger prop. */ export declare function getPipelineRefreshTrigger(): number; /** * Whether log messages should be shown in the execution console */ export declare function getShowLogs(): boolean; /** * 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 * Uses binary search insertion for O(log n) instead of full sort. * * @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 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 */ updateLastPollSequenceNumber: (seq: number) => void; /** * Reset all playground state */ reset: () => void; /** * Switch to a different session * * @param sessionId - The session ID to switch to */ switchSession: (sessionId: string) => void; pinExecution(executionId: string | null): void; setShowLogs(value: boolean): void; toggleShowLogs(): void; }; /** * Apply a server response to the store. All message and status updates from * the server flow through here — polling callback, manual fetches, interrupt * resolution. Nothing updates messages or session status except this function. * * Pass `sessionId` (the session the response was fetched for) so a response * that resolves after the user switched sessions is dropped instead of writing * the old session's status/messages onto the new current session. Pass `null` * to deliberately opt out of the guard (non-session-scoped callers only) — the * argument is required so every new caller has to make that choice explicitly. */ export declare function applyServerResponse(response: PlaygroundMessagesApiResponse, sessionId: string | null): 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 sequence number of the latest message, used to seed incremental polling. * * @returns Sequence number of the last message, or null */ export declare function getLatestSequenceNumber(): number | null; /** * Get the sequence number of the oldest loaded message, used as the cursor * for backward "load older" pagination. * * @returns Sequence number of the first message, or null */ export declare function getOldestSequenceNumber(): number | null; /** * Whether older messages exist before the oldest one currently loaded. */ export declare function getHasOlder(): boolean; /** * Set whether older messages remain to be loaded, derived from a * backward-pagination response. */ export declare function setHasOlder(hasOlder: boolean): void; /** * 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 * @returns Promise that resolves when messages are refreshed */ export declare function refreshSessionMessages(fetchMessages: (sessionId: string) => Promise): Promise;