/**
 * Event Ring Buffer
 * Phase 2: Track meaningful operational events for Live Operations Feed
 */
import { updateAppState, getState } from './store.js';
const MAX_EVENTS = 10; // Ring buffer size
/**
 * Add event to operations feed
 * Events are structured objects, not strings
 */
export function addOperationEvent(event) {
    const state = getState();
    const events = [...state.operationEvents, event];
    // Keep only last MAX_EVENTS
    const trimmedEvents = events.slice(-MAX_EVENTS);
    updateAppState({ operationEvents: trimmedEvents });
}
/**
 * Helper: Create event for run started
 */
export function eventRunStarted(agentName, runId) {
    return {
        type: 'RUN_STARTED',
        description: `Execution started: ${agentName}`,
        timestamp: Date.now(),
        severity: 'info',
        metadata: { agentName, runId },
    };
}
/**
 * Helper: Create event for run completed
 */
export function eventRunCompleted(agentName, runId, status) {
    return {
        type: 'RUN_COMPLETED',
        description: `Execution ${status.toLowerCase()}: ${agentName}`,
        timestamp: Date.now(),
        severity: status === 'FAILED' ? 'warning' : 'info',
        metadata: { agentName, runId, status },
    };
}
/**
 * Helper: Create event for error detected
 */
export function eventErrorDetected(description, metadata, severity = 'warning') {
    return {
        type: 'ERROR_DETECTED',
        description,
        timestamp: Date.now(),
        severity,
        metadata,
    };
}
/**
 * Helper: Create event for connection established
 */
export function eventConnectionEstablished(target) {
    return {
        type: 'CONNECTION_ESTABLISHED',
        description: `Connected to ${target}`,
        timestamp: Date.now(),
        severity: 'info',
        metadata: { target },
    };
}
/**
 * Helper: Create event for connection lost
 */
export function eventConnectionLost() {
    return {
        type: 'CONNECTION_LOST',
        description: 'Connection lost',
        timestamp: Date.now(),
        severity: 'warning',
    };
}
/**
 * Helper: Create event for system state change
 */
export function eventSystemStateChange(description, metadata) {
    return {
        type: 'SYSTEM_STATE_CHANGE',
        description,
        timestamp: Date.now(),
        severity: 'info',
        metadata,
    };
}
//# sourceMappingURL=events.js.map