Abstract Class: AIAdapter<TBus, TConnector, TAgent>
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)
Type Parameters
Section titled “Type Parameters”TBus extends ScopedBus<string> = ScopedBus<string>
Scoped bus type for adapter-specific events
TConnector
Section titled “TConnector”TConnector extends AIAgentConnector<TBus> = AIAgentConnector<TBus>
Connector type bridging to the AI SDK
TAgent
Section titled “TAgent”TAgent extends AIAgent<TBus, TConnector> = AIAgent<TBus, TConnector>
Agent implementation type (must extend AIAgent)
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”
protectednew 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.
Parameters
Section titled “Parameters”config
Section titled “config”AIAdapterConstructorConfig<TBus, TConnector, TAgent>
Adapter configuration
Returns
Section titled “Returns”AIAdapter<TBus, TConnector, TAgent>
Properties
Section titled “Properties”adapterBus
Section titled “adapterBus”
protectedadapterBus:TBus
Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:56
Scoped bus for adapter-specific communication. Created in init().
adapterId
Section titled “adapterId”
readonlyadapterId:string
Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:44
Unique identifier for this adapter instance.
agentFactory
Section titled “agentFactory”
protectedagentFactory: (agentConfig) =>TAgent
Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:71
Parameters
Section titled “Parameters”agentConfig
Section titled “agentConfig”AIAgentConfig<TBus, TConnector>
Returns
Section titled “Returns”TAgent
capabilities
Section titled “capabilities”
readonlycapabilities:string[]
Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:48
Adapter capabilities for runtime feature detection.
clientId?
Section titled “clientId?”
protectedreadonlyoptionalclientId?: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’).
configFactory
Section titled “configFactory”
protectedconfigFactory: (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)
Parameters
Section titled “Parameters”ConfigFactoryInput<TBus>
Returns
Section titled “Returns”Promise<BaseAgentConnectorConfig<TBus, object> & object>
connectorFactory
Section titled “connectorFactory”
protectedconnectorFactory: (config) =>TConnector|Promise<TConnector>
Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:77
Connector factory - creates connector from full config (includes adapterId)
Parameters
Section titled “Parameters”config
Section titled “config”BaseAgentConnectorConfig<TBus, object> & object
Returns
Section titled “Returns”TConnector | Promise<TConnector>
definitionProviders
Section titled “definitionProviders”
protectedreadonlydefinitionProviders: readonlyAdapterProviderDefinition[]
Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:70
Provider definitions for model lookup. Injected by runtime.
globalBus
Section titled “globalBus”
protectedreadonlyglobalBus:IMakaioBus
Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:54
Global bus for cross-adapter communication.
readonlyname:string
Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:46
Adapter name (e.g., ‘openai-node’, ‘claude-code’).
namespace
Section titled “namespace”
protectedreadonlynamespace:AdapterNamespace
Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:52
Adapter namespace for creating scoped bus.
nativeTools
Section titled “nativeTools”
readonlynativeTools:string[]
Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:50
Native tools built into the adapter (e.g., [‘shell_command’, ‘apply_patch’]).
platformDefaults?
Section titled “platformDefaults?”
protectedoptionalplatformDefaults?:PlatformDefaults
Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:68
Platform-provided defaults (cwd, env) injected by runtime. Lowest priority.
Methods
Section titled “Methods”close()
Section titled “close()”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.
Returns
Section titled “Returns”void
closeAsync()
Section titled “closeAsync()”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.
Returns
Section titled “Returns”Promise<void>
Promise that resolves when cleanup is complete
createAgent()
Section titled “createAgent()”
protectedcreateAgent(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.
Parameters
Section titled “Parameters”agentId
Section titled “agentId”string
Pre-generated agent ID (use this, don’t generate your own)
sessionId
Section titled “sessionId”string
Makaio session ID (created or provided based on mode)
request
Section titled “request”AgentCreationOptions
The startAgent request payload
Returns
Section titled “Returns”Promise<TAgent>
The agent instance (NOT started yet)
disposeAgent()
Section titled “disposeAgent()”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.
Parameters
Section titled “Parameters”agentId
Section titled “agentId”string
Agent identifier
Returns
Section titled “Returns”boolean
true if agent was found and disposed, false otherwise
getActiveAgents()
Section titled “getActiveAgents()”getActiveAgents():
TAgent&object[]
Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:416
Get all active agents managed by this adapter.
Returns
Section titled “Returns”TAgent & object[]
Array of active agents with session info
getAgent()
Section titled “getAgent()”getAgent(
agentId):TAgent&object|undefined
Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:392
Get an agent by ID with session info.
Parameters
Section titled “Parameters”agentId
Section titled “agentId”string
Agent identifier
Returns
Section titled “Returns”TAgent & object | undefined
Agent with session info, or undefined if not found
init()
Section titled “init()”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).
Returns
Section titled “Returns”Promise<void>
isInitialized()
Section titled “isInitialized()”isInitialized():
boolean
Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:429
Check if the adapter has been initialized.
Returns
Section titled “Returns”boolean
true if init() has been called successfully
onClose()
Section titled “onClose()”
protectedonClose():Promise<void>
Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:385
Hook for subclass cleanup. Override to perform async teardown (close connections, etc.).
Returns
Section titled “Returns”Promise<void>
onInit()
Section titled “onInit()”
protectedonInit():Promise<void>
Defined in: ../../../adapters/core/src/adapter/ai-adapter.ts:271
Hook for subclass initialization. Override to perform async setup (connections, auth, etc.).
Returns
Section titled “Returns”Promise<void>