/**
 * Messaging Types Module
 *
 * Type definitions for the centralized message queue system.
 * All chat and Slack messages are enqueued into a FIFO queue,
 * processed one-at-a-time, and responses are routed back to the
 * correct source (WebSocket for chat, thread reply for Slack).
 *
 * @module types/messaging
 */
import { MESSAGE_SOURCES, type MessageSource } from '../constants.js';
export { MESSAGE_SOURCES, type MessageSource };
/**
 * Valid message source values as a tuple (for .includes() validation).
 * Derived from the canonical MESSAGE_SOURCES object in constants.ts.
 */
export declare const MESSAGE_SOURCE_VALUES: readonly MessageSource[];
/**
 * Valid queue message statuses
 */
export declare const QUEUE_MESSAGE_STATUSES: readonly ["pending", "processing", "completed", "failed", "cancelled"];
/**
 * Status of a message in the queue
 */
export type QueueMessageStatus = (typeof QUEUE_MESSAGE_STATUSES)[number];
/**
 * Metadata specific to the source of a message.
 * For Slack messages, includes a resolve callback to unblock the Slack bridge.
 */
export interface SourceMetadata {
    /** Slack resolve callback to unblock the bridge's blocking promise */
    slackResolve?: (response: string) => void;
    /** Slack user ID */
    userId?: string;
    /** Slack channel ID */
    channelId?: string;
    /** Additional source-specific metadata */
    [key: string]: unknown;
}
/**
 * Input for enqueuing a new message
 */
export interface EnqueueMessageInput {
    /** Message content */
    content: string;
    /** Conversation ID for routing */
    conversationId: string;
    /** Source of the message */
    source: MessageSource;
    /** Source-specific metadata */
    sourceMetadata?: SourceMetadata;
    /** Target agent session for delivery (defaults to orchestrator if omitted) */
    targetSession?: string;
}
/**
 * A message in the queue
 */
export interface QueuedMessage {
    /** Unique queue entry ID */
    id: string;
    /** Message content */
    content: string;
    /** Conversation ID for routing */
    conversationId: string;
    /** Source of the message */
    source: MessageSource;
    /** Current status in the queue */
    status: QueueMessageStatus;
    /** Source-specific metadata */
    sourceMetadata?: SourceMetadata;
    /** ISO timestamp when enqueued */
    enqueuedAt: string;
    /** ISO timestamp when processing started */
    processingStartedAt?: string;
    /** ISO timestamp when completed or failed */
    completedAt?: string;
    /** Error message if failed */
    error?: string;
    /** Response content from the orchestrator */
    response?: string;
    /** Number of times this message has been re-queued due to agent-not-ready */
    retryCount?: number;
    /** ISO timestamp when the message was delivered to the orchestrator terminal */
    deliveredAt?: string;
    /** Target agent session for delivery (defaults to orchestrator if omitted) */
    targetSession?: string;
}
/**
 * Queue status summary for monitoring
 */
export interface QueueStatus {
    /** Number of messages waiting */
    pendingCount: number;
    /** Whether a message is currently being processed */
    isProcessing: boolean;
    /** The message currently being processed, if any */
    currentMessage?: QueuedMessage;
    /** Total messages processed since startup */
    totalProcessed: number;
    /** Total messages that failed since startup */
    totalFailed: number;
    /** Number of completed messages in history */
    historyCount: number;
}
/**
 * Queue event types emitted by MessageQueueService
 */
export interface QueueEvents {
    /** Emitted when a message is enqueued */
    enqueued: QueuedMessage;
    /** Emitted when a message starts processing */
    processing: QueuedMessage;
    /** Emitted when a message completes successfully */
    completed: QueuedMessage;
    /** Emitted when a message fails */
    failed: QueuedMessage;
    /** Emitted when queue status changes */
    statusUpdate: QueueStatus;
}
/** Current version of the persisted queue state format */
export declare const PERSISTED_QUEUE_VERSION = 1;
/**
 * A message stripped of non-serializable fields for disk persistence.
 * Function-valued sourceMetadata entries (like slackResolve) are removed.
 */
export interface PersistedMessage {
    /** Unique queue entry ID */
    id: string;
    /** Message content */
    content: string;
    /** Conversation ID for routing */
    conversationId: string;
    /** Source of the message */
    source: MessageSource;
    /** Current status in the queue */
    status: QueueMessageStatus;
    /** Serializable source-specific metadata (functions stripped) */
    sourceMetadata?: Record<string, string | number | boolean | null | undefined>;
    /** ISO timestamp when enqueued */
    enqueuedAt: string;
    /** ISO timestamp when processing started */
    processingStartedAt?: string;
    /** ISO timestamp when completed or failed */
    completedAt?: string;
    /** Error message if failed */
    error?: string;
    /** Response content from the orchestrator */
    response?: string;
    /** Number of times this message has been re-queued due to agent-not-ready */
    retryCount?: number;
    /** ISO timestamp when the message was delivered to the orchestrator terminal */
    deliveredAt?: string;
}
/**
 * Full persisted state of the message queue, written to disk after every mutation.
 */
export interface PersistedQueueState {
    /** Schema version for forward compatibility */
    version: typeof PERSISTED_QUEUE_VERSION;
    /** ISO timestamp of when this state was saved */
    savedAt: string;
    /** Pending messages in FIFO order */
    queue: PersistedMessage[];
    /** The message that was being processed at save time, if any */
    currentMessage: PersistedMessage | null;
    /** Completed/failed/cancelled message history (most recent first) */
    history: PersistedMessage[];
    /** Total messages processed since last counter reset */
    totalProcessed: number;
    /** Total messages that failed since last counter reset */
    totalFailed: number;
}
/**
 * Convert a QueuedMessage to a PersistedMessage by stripping function-valued
 * sourceMetadata entries (e.g. slackResolve callbacks that can't be serialized).
 *
 * @param msg - The queued message to convert
 * @returns A serializable PersistedMessage
 */
export declare function toPersistedMessage(msg: QueuedMessage): PersistedMessage;
/**
 * Check if a value is a valid message source
 *
 * @param value - Value to check
 * @returns True if value is a valid MessageSource
 */
export declare function isValidMessageSource(value: unknown): value is MessageSource;
/**
 * Check if a value is a valid queue message status
 *
 * @param value - Value to check
 * @returns True if value is a valid QueueMessageStatus
 */
export declare function isValidQueueMessageStatus(value: unknown): value is QueueMessageStatus;
/**
 * Check if an object is a valid EnqueueMessageInput
 *
 * @param value - Value to check
 * @returns True if value is a valid EnqueueMessageInput
 */
export declare function isValidEnqueueMessageInput(value: unknown): value is EnqueueMessageInput;
/**
 * Check if an object is a valid QueuedMessage
 *
 * @param value - Value to check
 * @returns True if value is a valid QueuedMessage
 */
export declare function isValidQueuedMessage(value: unknown): value is QueuedMessage;
/**
 * Check if an object is a valid QueueStatus
 *
 * @param value - Value to check
 * @returns True if value is a valid QueueStatus
 */
export declare function isValidQueueStatus(value: unknown): value is QueueStatus;
/**
 * Check if an object is a valid PersistedQueueState for safe restoration.
 *
 * @param value - Value to check
 * @returns True if value is a valid PersistedQueueState
 */
export declare function isValidPersistedQueueState(value: unknown): value is PersistedQueueState;
//# sourceMappingURL=messaging.types.d.ts.map