agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
54 lines • 2.16 kB
JavaScript
;
/**
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmitBridge = void 0;
const eventMeta_js_1 = require("../../bridge/eventMeta.js");
const eventSourcePosition_js_1 = require("../../bridge/eventSourcePosition.js");
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 = (0, eventMeta_js_1.buildEventMeta)({
runtimeStageId: event.runtimeStageId,
subflowPath: event.subflowPath,
timestamp: event.timestamp,
sourcePosition: (0, eventSourcePosition_js_1.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,
});
}
}
exports.EmitBridge = EmitBridge;
//# sourceMappingURL=EmitBridge.js.map