LogoRobo.js
Packages@robojs/ai

abstract BaseEngine

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.

Extended by

Constructors

new BaseEngine()

new BaseEngine(): BaseEngine

Returns

BaseEngine

Properties

PropertyModifierTypeDescription
_hooksprotectedMap<HookEvent, Hook[]>Registered hooks keyed by event type.

Methods

callHooks()

Call Signature

callHooks(event, context): Promise<void>

Sequentially executes registered hooks for the given event while allowing each hook to mutate the message array.

Parameters
ParameterTypeDescription
event"chat"Hook event name.
contextChatHookContextMutable hook context.
Returns

Promise<void>

Latest message array after all hooks have run.

Call Signature

callHooks(event, context): Promise<void | ChatReply>

Sequentially executes registered hooks for the given event while allowing each hook to mutate the message array.

Parameters
ParameterTypeDescription
event"reply"Hook event name.
contextReplyHookContextMutable hook context.
Returns

Promise<void | ChatReply>

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>


getMCPTools()?

optional getMCPTools(): MCPTool[]

Optionally returns MCP (Model Context Protocol) tool configurations for this engine. Engines that support MCP should override this method to return their configured MCP servers.

Returns

MCPTool[]

Array of MCP tool configurations, or empty array if MCP is not supported.


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
eventHookEventHook 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
eventHookEventHook 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<{
  responseId: null | string;
  summary: string;
}>

Optionally summarize tool execution results for provider-specific follow-up prompts.

Parameters

ParameterTypeDescription
_params{ call: ChatFunctionCall; model: string; resultText: string; success: boolean; }Details describing the tool invocation to summarize.
_params.callChatFunctionCall-
_params.model?string-
_params.resultTextstring-
_params.successboolean-

Returns

Promise<{ responseId: null | string; summary: string; }>

Summary text and an optional response identifier for traceability.


supportedFeatures()

supportedFeatures(): EngineSupportedFeatures

Returns the supported feature flags for the engine. Override to enable capabilities.

Returns

EngineSupportedFeatures

On this page