Skip to content

Variable: MakaioBus

Makaio Framework


Makaio Framework / bus-core / MakaioBus

const MakaioBus: 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 schemas
  • on() - Subscribe to events or requests with typed handlers
  • emit() - Fire-and-forget event broadcasting
  • request() - Request-response with middleware chain
  • scoped() - 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
import { MakaioBus } from '@makaio/bus-core';
import { z } from 'zod';
// Register namespace with typed subjects
const { 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 events
MakaioBus.on(subjects.started, (context) => {
console.debug('Agent started:', context.payload.agentId);
});
// Emit events
await MakaioBus.emit(subjects.started, { agentId: 'agent-123' });
// Handle requests
MakaioBus.on(subjects.toolApprove, (context) => {
context.setResult({ approved: true });
});
// Make requests
const result = await MakaioBus.request(subjects.toolApprove, {
toolName: 'deleteFile',
});