Agent Event Bus
Typed cross-agent publish/subscribe on top of b.pubsub (or any pubsub-shaped instance with publish / subscribe / unsubscribe). Substrate for every agent-to-agent reaction the mail stack + future agents need: mail.scan.malware-detected → MX refuses source, mail.crypto.key-rotated → vault invalidates cached recipient keys, ai.classify.prompt-injection-detected → agent quarantines, etc.
The bus owns:
- **Topic registry** — registerTopic(name, { schema, posture, permissions, tenantScope }) declares the wire contract at boot. Unknown topics refuse publish + subscribe so typos fail loudly. - **Schema enforcement** — every payload validated against the declared schema before publish AND at each delivery (defends in-flight tampering). - **Permission gating** — b.permissions.check(actor, scope) on every publish + subscribe. - **Posture re-validation at delivery** — same shape as v0.9.20 cross-queue posture check. - **Audit lifecycle** — publish / subscribe / delivery / refused events emit to the operator's audit chain.
var bus = b.agent.eventBus.create({
pubsub: myPubsub,
audit: b.audit,
permissions: myPerms,
});
bus.registerTopic("mail.scan.malware-detected", {
schema: {
source: "string",
confidence: "number",
detectedAt: "isoDateTime",
},
posture: "soc2",
permissions: {
publish: ["mail-scan:write"],
subscribe: ["mail-mx:write"],
},
});
await bus.publish("mail.scan.malware-detected", {
source: "1.2.3.4", confidence: 0.95, detectedAt: new Date().toISOString(),
}, { actor: { id: "scan-agent", roles: ["mail-scan-internal"] } });
b.agent.eventBus.create(opts) #
{
pubsub: { publish, subscribe, unsubscribe }, // required
audit: b.audit namespace, // optional
permissions: b.permissions instance, // optional
requireMac: boolean, // default: true — keyed-MAC envelope auth; false only for single-process unit tests with no vault
}
Create the bus facade. Returns an instance with registerTopic / publish / subscribe / listTopics. Operator supplies a pubsub- shaped backend; framework owns schema validation, permission gating, posture re-validation, audit lifecycle.
var bus = b.agent.eventBus.create({ pubsub: myPubsub });
bus.registerTopic("mail.scan.malware-detected", {
schema: { source: "string" },
});
await bus.publish("mail.scan.malware-detected", { source: "1.2.3.4" });
Last updated 2026-08-08T16:39:49.652Z by seeder.