Skip to content

Class: SessionOrchestrator

Makaio Framework


Makaio Framework / services-core / SessionOrchestrator

Defined in: ../../../packages/services/core/src/session/session-orchestrator.ts:81

Slim framework session orchestrator.

Composes with SessionTurnManager (turn lifecycle, usage accumulation, completion), AdapterRegistry (adapterName to adapterId mapping), and the adapter-subsystem reverse lookup for canonical adapterId to adapterName validation when callers select a direct adapter instance.

Registers the core session.sendMessage handler only:

  1. Get or create session (via getOrCreateSession)
  2. Start agent if session has no agents — resolves the canonical adapterName from direct selections, uses adapterId directly when provided, otherwise resolves it via AdapterRegistry, then calls bare AdapterSubjects.startAgent
  3. Resolve target agents (via resolveTargetAgents)
  4. Verify agent liveness and build recovery context for dead agents (requestOptional AdapterSubjects.getAgent + buildRecoveryContext)
  5. Get or create turn (via SessionTurnManager)
  6. Generate message ID and store user message + routing records (requestOptional, fire-and-forget)
  7. Emit session.turn.started + session.user_message.sent
  8. Route to agents (via routeToAgentsCore, single shared context)
  9. Return result with messageId, turnId, sessionId

Host-specific features (personas, MCP, execution targets, container spawn, connector swap, CWD/model enforcement, fork context, TurnContextEnricher) are handled by a host-provided orchestrator.

const orchestrator = new SessionOrchestrator(MakaioBus, 'machine-id');
const { messageId, turnId, sessionId } = await MakaioBus.request(
SessionSubjects.sendMessage,
{ sessionId: crypto.randomUUID(), adapterName: 'openai-node', message: 'Hello!' },
);

new SessionOrchestrator(bus?, _machineId): SessionOrchestrator

Defined in: ../../../packages/services/core/src/session/session-orchestrator.ts:92

IMakaioBus = MakaioBus

Event bus used for handler registration and message routing

string

Machine identifier (reserved for future routing use)

SessionOrchestrator

destroy(): void

Defined in: ../../../packages/services/core/src/session/session-orchestrator.ts:368

Stop the orchestrator and clean up all subscriptions and composition utilities.

void

ISessionOrchestrator.destroy