export class ProviderSuccessCenter {
    listeners = new Set();
    subscribe(listener) {
        this.listeners.add(listener);
        return () => {
            this.listeners.delete(listener);
        };
    }
    emit(event) {
        const enriched = this.normalize(event);
        for (const listener of this.listeners) {
            try {
                listener(enriched);
            }
            catch {
                // Listener failures should not break propagation
            }
        }
        return enriched;
    }
    normalize(event) {
        const timestamp = typeof event.timestamp === 'number' ? event.timestamp : Date.now();
        const runtime = event.runtime || {};
        return {
            runtime,
            timestamp,
            metadata: event.metadata,
            details: event.details
        };
    }
}
export const providerSuccessCenter = new ProviderSuccessCenter();
