Class: abstract BaseEngine
Abstract base class to be extended by AI engine implementations. Provides hook orchestration, default capability flags, and optional voice-session helpers.
Examples
class MyEngine extends BaseEngine {
public async chat(messages: ChatMessage[], options: ChatOptions) {
// Call provider API and translate the result to ChatResult
return provider.complete(messages, options)
}
public getFunctionHandlers() {
return {}
}
public getInfo() {
return { name: 'my-engine', version: '1.0.0' }
}
}
engine.on('chat', async (ctx) => {
return ctx.messages.filter(Boolean)
})
if (engine.supportedFeatures().voice) {
await engine.startVoiceSession(options)
}
Remarks
Subclasses must implement BaseEngine.chat, BaseEngine.generateImage, BaseEngine.getFunctionHandlers, and BaseEngine.getInfo. Override optional voice methods when providing realtime functionality.
Constructors
new BaseEngine()
new BaseEngine(): BaseEngine
Returns
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
_hooks | protected | Record<"chat", Hook[]> | Registered hooks keyed by event type. |
Methods
callHooks()
callHooks(
event,
context,
iteration): Promise<ChatMessage[]>
Sequentially executes registered hooks for the given event while allowing each hook to mutate the message array.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | "chat" | Hook event name. |
context | HookContext | Mutable hook context. |
iteration | number | Current retry iteration. |
Returns
Promise<ChatMessage[]>
Latest message array after all hooks have run.
chat()
abstract chat(messages, options): Promise<ChatResult>
Produces a conversational response based on supplied messages and options.
Parameters
| Parameter | Type | Description |
|---|---|---|
messages | ChatMessage[] | Message history presented to the engine. |
options | ChatOptions | Additional configuration for the completion request. |
Returns
Promise<ChatResult>
Chat response including tool calls, conversation state, and voice metadata.
generateImage()
abstract generateImage(options): Promise<GenerateImageResult>
Generates an image using the backing provider.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | GenerateImageOptions | Prompt and configuration for the image request. |
Returns
Promise<GenerateImageResult>
Generated images represented as base64 payloads or URLs.
getFunctionHandlers()
abstract getFunctionHandlers(): Record<string, Command>
Returns a mapping of function names to Robo command handlers invoked during tool execution.
Returns
Record<string, Command>
getInfo()
abstract getInfo(): Record<string, unknown>
Provides descriptive information about the engine for diagnostics or inspection tooling.
Returns
Record<string, unknown>
init()
init(): Promise<void>
Perform asynchronous initialization prior to handling requests. Override for custom setup.
Returns
Promise<void>
off()
off(event, hook): void
Removes a previously registered hook from the engine.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | "chat" | Hook event name. |
hook | Hook | Hook callback to remove. |
Returns
void
on()
on(event, hook): void
Registers a hook to run during specific engine orchestration events.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | "chat" | Hook event name. |
hook | Hook | Hook callback to register. |
Returns
void
startVoiceSession()
startVoiceSession(_options): Promise<VoiceSessionHandle>
Starts a realtime voice session. Engines without voice capabilities should override BaseEngine.supportedFeatures or this method to avoid throwing.
Parameters
| Parameter | Type | Description |
|---|---|---|
_options | VoiceSessionStartOptions | Voice session options supplied by the caller. |
Returns
Promise<VoiceSessionHandle>
Throws
Always throws when not overridden by subclasses.
stopVoiceSession()
stopVoiceSession(_handle): Promise<void>
Stops a realtime voice session previously started by BaseEngine.startVoiceSession.
Parameters
| Parameter | Type | Description |
|---|---|---|
_handle | VoiceSessionHandle | Voice session handle. |
Returns
Promise<void>
Throws
Always throws when voice is unsupported.
summarizeToolResult()?
optional summarizeToolResult(_params): Promise<object>
Optionally summarize tool execution results for provider-specific follow-up prompts.
Parameters
| Parameter | Type | Description |
|---|---|---|
_params | object | Details describing the tool invocation to summarize. |
_params.call | ChatFunctionCall | - |
_params.model? | string | - |
_params.resultText | string | - |
_params.success | boolean | - |
Returns
Promise<object>
Summary text and an optional response identifier for traceability.
responseId
responseId: null | string;
summary
summary: string;
supportedFeatures()
supportedFeatures(): EngineSupportedFeatures
Returns the supported feature flags for the engine. Override to enable capabilities.