import { nexusEventBus } from '../../engines/event-bus.js';
/**
 * Wrap providers.coordination.publish() so a coordination failure can never
 * abort a sortie or mandate. Failures are emitted as a structured event so
 * they remain observable instead of being silently swallowed.
 */
export function safePublish(coordination, signal, stage = 'coordination') {
    if (!coordination)
        return;
    try {
        coordination.publish(signal);
    }
    catch (err) {
        nexusEventBus.emit('synapse.coordination.publish.failed', {
            stage,
            phase: signal.phase,
            operativeId: signal.operativeId,
            missionId: signal.workItemId,
            sortieId: signal.sortieId,
            error: err instanceof Error ? err.message : String(err),
        });
    }
}
