Skip to content

Abstract Class: AIAdapter<TBus, TConnector, TAgent>

Makaio Framework


Makaio Framework / ai-adapters-core / AIAdapter

Abstract Class: AIAdapter<TBus, TConnector, TAgent>

Section titled “Abstract Class: AIAdapter<TBus, TConnector, TAgent>”

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:38

Base class for AI adapters.

An adapter manages a set of agents, handles adapter.* subjects as RPC endpoints, and provides clear file-to-subject mapping.

Three-layer architecture:

  • AIAdapter: Handles adapter.* global subjects, owns agent tracking
  • AIAgent: Handles agent.* global subjects (filtered by agentId), wraps connector
  • AIAgentConnector: Owns adapter-specific namespace, SDK-level bridge

Subject Ownership:

  • adapter.startAgent - Creates and starts new agents (owned by AIAdapter)
  • adapter.initialized - Emitted when adapter is ready (owned by AIAdapter)
  • adapter.session.created - Emitted after agent starts (owned by AIAdapter)
  • session.agent.added - Emitted to notify global session service (owned by AIAdapter)
  • agent.* subjects - Owned by agent instances (see ai-agent.ts)

TBus extends ScopedBus<string> = ScopedBus<string>

Scoped bus type for adapter-specific events

TConnector extends AIAgentConnector<TBus> = AIAgentConnector<TBus>

Connector type bridging to the AI SDK

TAgent extends AIAgent<TBus, TConnector> = AIAgent<TBus, TConnector>

Agent implementation type (must extend AIAgent)

protected new AIAdapter<TBus, TConnector, TAgent>(config): AIAdapter<TBus, TConnector, TAgent>

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:86

Create a new AIAdapter instance. Constructor is synchronous - stores config only. Call init() to complete setup.

AIAdapterConstructorConfig<TBus, TConnector, TAgent>

Adapter configuration

AIAdapter<TBus, TConnector, TAgent>

protected adapterBus: TBus

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:56

Scoped bus for adapter-specific communication. Created in init().


readonly adapterId: string

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:44

Unique identifier for this adapter instance.


protected agentFactory: (agentConfig) => TAgent

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:71

AIAgentConfig<TBus, TConnector>

TAgent


readonly capabilities: string[]

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:48

Adapter capabilities for runtime feature detection.


protected readonly optional clientId?: string

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:66

Client identifier for the application this adapter belongs to (e.g., ‘claude-code’, ‘codex’).


protected configFactory: (input) => Promise<BaseAgentConnectorConfig<TBus, object> & object>

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:73

Config factory - transforms partial input into full adapter-specific config (includes adapterId)

ConfigFactoryInput<TBus>

Promise<BaseAgentConnectorConfig<TBus, object> & object>


protected connectorFactory: (config) => TConnector | Promise<TConnector>

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:77

Connector factory - creates connector from full config (includes adapterId)

BaseAgentConnectorConfig<TBus, object> & object

TConnector | Promise<TConnector>


protected readonly definitionProviders: readonly AdapterProviderDefinition[]

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:70

Provider definitions for model lookup. Injected by runtime.


protected readonly globalBus: IMakaioBus

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:54

Global bus for cross-adapter communication.


readonly name: string

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:46

Adapter name (e.g., ‘openai-node’, ‘claude-code’).


protected readonly namespace: AdapterNamespace

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:52

Adapter namespace for creating scoped bus.


readonly nativeTools: string[]

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:50

Native tools built into the adapter (e.g., [‘shell_command’, ‘apply_patch’]).


protected optional platformDefaults?: PlatformDefaults

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:68

Platform-provided defaults (cwd, env) injected by runtime. Lowest priority.

close(): void

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:380

Cleanup resources and unsubscribe from bus. Runs cleanup functions, aborts agents, allows subclass cleanup via onClose hook.

void


closeAsync(): Promise<void>

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:346

Asynchronous cleanup for awaitable shutdown. Runs cleanup functions, aborts agents, allows subclass cleanup via onClose hook.

Promise<void>

Promise that resolves when cleanup is complete


protected createAgent(agentId, sessionId, request): Promise<TAgent>

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:283

Create an agent instance.

Subclasses implement this to instantiate their specific AIAgent subclass. The agent should NOT be started yet - that’s handled by startAgent after creation.

string

Pre-generated agent ID (use this, don’t generate your own)

string

Makaio session ID (created or provided based on mode)

AgentCreationOptions

The startAgent request payload

Promise<TAgent>

The agent instance (NOT started yet)


disposeAgent(agentId): boolean

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:408

Dispose resources for an agent.

Aborts the agent and removes it from the tracking map.

string

Agent identifier

boolean

true if agent was found and disposed, false otherwise


getActiveAgents(): TAgent & object[]

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:416

Get all active agents managed by this adapter.

TAgent & object[]

Array of active agents with session info


getAgent(agentId): TAgent & object | undefined

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:392

Get an agent by ID with session info.

string

Agent identifier

TAgent & object | undefined

Agent with session info, or undefined if not found


init(): Promise<void>

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:248

Initialize adapter - call after construction. Creates scoped bus, sets up handlers, and emits adapter.initialized event. Safe to call multiple times - subsequent calls are no-ops.

Note: Agents are NOT eagerly rehydrated on startup. They are rehydrated on-demand when messages arrive (lazy rehydration via handleRehydrateAgent).

Promise<void>


isInitialized(): boolean

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:429

Check if the adapter has been initialized.

boolean

true if init() has been called successfully


protected onClose(): Promise<void>

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:385

Hook for subclass cleanup. Override to perform async teardown (close connections, etc.).

Promise<void>


protected onInit(): Promise<void>

Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:271

Hook for subclass initialization. Override to perform async setup (connections, auth, etc.).

Promise<void>