UNPKG

agentfootprint

Version:

The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.

50 lines • 1.98 kB
/** * EmitBridge — forwards footprintjs emits whose name starts with a given * prefix to the EventDispatcher, enriched with EventMeta. * * Pattern: Adapter (GoF) + Pipes & Filters (Hohpe & Woolf, 2003). * Role: Single reusable translation layer for every "pass-through" * prefix recorder (StreamRecorder, AgentRecorder, and any * future domain whose events are emitted via typedEmit()). * Emits: Any event whose name matches `prefix` — type derived from the * emit name and validated by the consumer's EventMap subscription. */ import { buildEventMeta } from '../../bridge/eventMeta.js'; import { projectEventSourcePosition } from '../../bridge/eventSourcePosition.js'; export class EmitBridge { id; dispatcher; prefixes; getRunContext; constructor(options) { this.dispatcher = options.dispatcher; this.id = options.id; this.prefixes = typeof options.prefix === 'string' ? [options.prefix] : options.prefix; this.getRunContext = options.getRunContext; } onEmit(event) { if (typeof event.name !== 'string') return; const name = event.name; if (!this.prefixes.some((p) => name.startsWith(p))) return; const type = event.name; if (!this.dispatcher.hasListenersFor(type)) return; const payload = event.payload; const meta = buildEventMeta({ runtimeStageId: event.runtimeStageId, subflowPath: event.subflowPath, timestamp: event.timestamp, sourcePosition: projectEventSourcePosition(event), }, this.getRunContext()); // The payload was served at its source (`src/redaction/runRedaction.ts` · // `emitServed`, before `$emit`), so this hop serves only the meta. this.dispatcher.dispatchServed({ type, payload, meta, }); } } //# sourceMappingURL=EmitBridge.js.map