Variable: MakaioBus
Makaio Framework / bus-core / MakaioBus
Variable: MakaioBus
Section titled “Variable: MakaioBus”
constMakaioBus:IMakaioBus
Defined in: ../../../packages/bus-core/src/bus.ts:606
Main bus instance with unified API for events and request/response flows.
Provides a singleton bus that manages schema-backed messaging with type-safe subjects, namespace isolation, and transport routing. Use this as the central coordination point for all cross-component communication.
Core Methods:
registerNamespace()- Register typed subjects with Zod schemason()- Subscribe to events or requests with typed handlersemit()- Fire-and-forget event broadcastingrequest()- Request-response with middleware chainscoped()- Create namespace-scoped bus instance
Key Features:
- Type-safe SubjectDefinition objects (no raw strings)
- Runtime validation in development (Zod schemas)
- Wildcard pattern matching with
.$all - Transport-backed remote messaging
- Hierarchical namespace support (e.g.,
adapter:claudeCode) - Middleware chains for request processing
Example
Section titled “Example”import { MakaioBus } from '@makaio/bus-core';import { z } from 'zod';
// Register namespace with typed subjectsconst { subjects } = MakaioBus.registerNamespace('agent', { started: z.object({ agentId: z.string() }), toolApprove: { request: z.object({ toolName: z.string() }), response: z.object({ approved: z.boolean() }), },});
// Subscribe to eventsMakaioBus.on(subjects.started, (context) => { console.debug('Agent started:', context.payload.agentId);});
// Emit eventsawait MakaioBus.emit(subjects.started, { agentId: 'agent-123' });
// Handle requestsMakaioBus.on(subjects.toolApprove, (context) => { context.setResult({ approved: true });});
// Make requestsconst result = await MakaioBus.request(subjects.toolApprove, { toolName: 'deleteFile',});