LogoRobo.js
Packages@robojs/ai

OpenAiEngine

Class: OpenAiEngine

Coordinates OpenAI powered chat, tool calling, voice, and media capabilities for Robo.js.

The engine keeps Flashcore-backed conversation state in sync, mirrors knowledge documents into the OpenAI vector store, brokers Responses API calls for text, images, and tools, and orchestrates realtime voice sessions with usage metering across chat and audio workloads.

Extends

Constructors

new OpenAiEngine()

new OpenAiEngine(options): OpenAiEngine

Parameters

ParameterType
optionsOpenAiEngineOptions

Returns

OpenAiEngine

Overrides

BaseEngine.constructor

Properties

PropertyModifierTypeDescriptionInherited from
_hooksprotectedMap<HookEvent, Hook[]>Registered hooks keyed by event type.BaseEngine._hooks

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.

Inherited from

BaseEngine.callHooks

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.

Inherited from

BaseEngine.callHooks


chat()

chat(messages, options): Promise<ChatResult>

Executes a chat turn against OpenAI's Responses API while maintaining Flashcore conversation state, rotating response ids around tool calls, and logging usage.

Parameters

ParameterTypeDescription
messagesChatMessage[]Ordered dialogue history culminating in the latest user prompt.
optionsChatOptionsPer-request overrides such as model, temperature, or conversation key.

Returns

Promise<ChatResult>

Parsed chat result containing assistant text, tool calls, and metadata.

Overrides

BaseEngine.chat


generateImage()

generateImage(options): Promise<{
  images: {
     base64: string;
    }[];
}>

Generates an image using the backing provider.

Parameters

ParameterTypeDescription
options{ model: string; prompt: string; }Prompt and configuration for the image request.
options.model?string-
options.promptstring-

Returns

Promise<{ images: { base64: string; }[]; }>

Generated images represented as base64 payloads or URLs.

Overrides

BaseEngine.generateImage


getFunctionHandlers()

getFunctionHandlers(): Record<string, Command>

Returns a mapping of function names to Robo command handlers invoked during tool execution.

Returns

Record<string, Command>

Overrides

BaseEngine.getFunctionHandlers


getInfo()

getInfo(): {
  name: string;
  version: any;
}

Provides descriptive information about the engine for diagnostics or inspection tooling.

Returns

{
  name: string;
  version: any;
}
NameTypeDefault value
namestring'OpenAI'
versionanypackageJson.version

Overrides

BaseEngine.getInfo


getMCPTools()

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.

Overrides

BaseEngine.getMCPTools


init()

init(): Promise<void>

Loads plugin command functions and primes the knowledge vector store so chat sessions have tool metadata and embeddings ready before handling traffic.

Returns

Promise<void>

Overrides

BaseEngine.init


off()

off(event, hook): void

Removes a previously registered hook from the engine.

Parameters

ParameterTypeDescription
eventHookEventHook event name.
hookHookHook callback to remove.

Returns

void

Inherited from

BaseEngine.off


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

Inherited from

BaseEngine.on


startVoiceSession()

startVoiceSession(options): Promise<VoiceSessionHandle>

Establishes a realtime voice session, wiring audio transport, transcript capture, Flashcore state, and tool-call forwarding between Discord voice channels and OpenAI.

Parameters

ParameterTypeDescription
optionsVoiceSessionStartOptionsVoice session configuration including guild context and endpoints.

Returns

Promise<VoiceSessionHandle>

Handle used by the runtime to stream audio frames and tear down the session.

Overrides

BaseEngine.startVoiceSession


stopVoiceSession()

stopVoiceSession(handle): Promise<void>

Stops a realtime voice session previously started by BaseEngine.startVoiceSession.

Parameters

ParameterType
handleVoiceSessionHandle

Returns

Promise<void>

Throws

Always throws when voice is unsupported.

Overrides

BaseEngine.stopVoiceSession


summarizeToolResult()

summarizeToolResult(params): Promise<{
  responseId: null | string;
  summary: string;
}>

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

Parameters

ParameterType
params{ call: ChatFunctionCall; model: string; resultText: string; success: boolean; }
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.

Overrides

BaseEngine.summarizeToolResult


supportedFeatures()

supportedFeatures(): EngineSupportedFeatures

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

Returns

EngineSupportedFeatures

Overrides

BaseEngine.supportedFeatures

On this page