All files / lib/reflection observe.ts

36.36% Statements 8/22
100% Branches 0/0
0% Functions 0/5
36.36% Lines 8/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 361x   1x 1x               1x                 1x       1x       1x       1x      
// lib/reflection/observe.ts
 
import { publish as publishToAwarenessBus } from '@/lib/awareness';
import { isReflectionEnabled } from './flags';
import type {
  Signal,
  EvaluationResult,
  FeedbackDecision,
  PolicyState,
  ReflectionEventPayload,
} from './types';
import { ReflectionEvent } from './types';
 
function publish(payload: ReflectionEventPayload) {
  if (!isReflectionEnabled()) return;
  // This is a bit of a type hack, as the main bus expects AwarenessEventPayload.
  // In a larger system, we might have a more generic event bus.
  publishToAwarenessBus(payload as any);
}
 
export function publishSignal(signal: Signal): void {
  publish({ type: ReflectionEvent.SIGNAL_COMPUTED, payload: signal });
}
 
export function publishEvaluation(evaluation: EvaluationResult): void {
  publish({ type: ReflectionEvent.EVALUATION_PERFORMED, payload: evaluation });
}
 
export function publishDecision(decision: FeedbackDecision): void {
  publish({ type: ReflectionEvent.DECISION_MADE, payload: decision });
}
 
export function publishPolicyChange(oldState: PolicyState, newState: PolicyState): void {
  publish({ type: ReflectionEvent.POLICY_CHANGED, payload: { old: oldState, new: newState } });
}