Skip to main content

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

BaseEngine

Properties

PropertyModifierTypeDescription
_hooksprotectedRecord<"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

ParameterTypeDescription
event"chat"Hook event name.
contextHookContextMutable hook context.
iterationnumberCurrent 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

ParameterTypeDescription
messagesChatMessage[]Message history presented to the engine.
optionsChatOptionsAdditional 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

ParameterTypeDescription
optionsGenerateImageOptionsPrompt 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

ParameterTypeDescription
event"chat"Hook event name.
hookHookHook callback to remove.

Returns

void


on()

on(event, hook): void

Registers a hook to run during specific engine orchestration events.

Parameters

ParameterTypeDescription
event"chat"Hook event name.
hookHookHook 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

ParameterTypeDescription
_optionsVoiceSessionStartOptionsVoice 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

ParameterTypeDescription
_handleVoiceSessionHandleVoice 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

ParameterTypeDescription
_paramsobjectDetails describing the tool invocation to summarize.
_params.callChatFunctionCall-
_params.model?string-
_params.resultTextstring-
_params.successboolean-

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.

Returns

EngineSupportedFeatures