/**
 * Message Replay Service
 *
 * Replays pending user messages after orchestrator restarts (#247).
 * When the orchestrator goes offline (backend restart, session crash, etc.),
 * user messages sent via Slack or Chat UI may be silently lost. This service
 * scans chat conversation history on startup for unreplied user messages
 * that arrived after the last queue persistence timestamp and re-enqueues
 * them so the orchestrator can process them.
 *
 * Flow:
 * 1. On startup, read `savedAt` from persisted queue state to determine
 *    when the backend last persisted state (proxy for "last alive" time).
 * 2. Scan all active chat conversations for user messages sent after `savedAt`.
 * 3. Filter out messages that already have an orchestrator/system reply after them.
 * 4. Filter out messages already pending in the restored queue (by conversationId+content).
 * 5. Enqueue surviving messages with a [REPLAYED] prefix.
 *
 * @module services/messaging/message-replay
 */
import type { MessageQueueService } from './message-queue.service.js';
import type { ChatMessage } from '../../types/chat.types.js';
/**
 * Result of a replay scan, containing details about what was found and replayed.
 */
export interface ReplayResult {
    /** Number of unreplied messages found */
    foundCount: number;
    /** Number of messages actually replayed (after filtering duplicates) */
    replayedCount: number;
    /** Number skipped because they were already in the queue */
    skippedDuplicate: number;
    /** The savedAt timestamp used to determine offline start */
    offlineSince: string;
    /** Duration the backend was offline (ms) */
    offlineDurationMs: number;
}
/**
 * MessageReplayService scans chat history on startup and replays
 * unreplied user messages that arrived while the orchestrator was offline.
 *
 * @example
 * ```typescript
 * const replayService = new MessageReplayService(
 *   messageQueueService,
 *   chatService,
 *   '~/.crewly'
 * );
 * const result = await replayService.replayPendingMessages();
 * if (result.replayedCount > 0) {
 *   logger.info(`Replayed ${result.replayedCount} missed messages`);
 * }
 * ```
 */
export declare class MessageReplayService {
    private logger;
    private messageQueueService;
    private chatV2;
    private crewlyHome;
    /**
     * Create a new MessageReplayService.
     *
     * @param messageQueueService - The message queue to enqueue replayed messages into
     * @param crewlyHome - Path to the crewly home directory (e.g. ~/.crewly)
     */
    constructor(messageQueueService: MessageQueueService, crewlyHome: string);
    /**
     * Scan chat history for unreplied user messages and replay them into the queue.
     *
     * This method should be called once during startup, after the queue has been
     * restored from persisted state but before the orchestrator starts processing.
     *
     * @returns Result containing counts of found, replayed, and skipped messages
     */
    replayPendingMessages(): Promise<ReplayResult>;
    /**
     * Read the `savedAt` timestamp from the persisted queue state file.
     * This is the proxy for "when the backend was last alive."
     *
     * @returns ISO timestamp string or null if no persisted state exists
     */
    getLastPersistedTimestamp(): Promise<string | null>;
    /**
     * Find user messages in a sorted message list that have no orchestrator/system
     * reply after them. A message is considered "replied" if any message from the
     * orchestrator or system appears after it in the conversation.
     *
     * @param messages - Sorted messages (oldest first) from a single conversation
     * @returns Array of user messages with no subsequent reply
     */
    findUnrepliedUserMessages(messages: ChatMessage[]): ChatMessage[];
    /**
     * Infer the message source from the chat message metadata or content.
     * Falls back to 'web_chat' if the source cannot be determined.
     *
     * @param message - The chat message to analyze
     * @returns The message source string for queue enqueuing
     */
    private inferMessageSource;
}
//# sourceMappingURL=message-replay.service.d.ts.map