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): OpenAiEngineParameters
| Parameter | Type |
|---|---|
options | OpenAiEngineOptions |
Returns
Overrides
Properties
| Property | Modifier | Type | Description | Inherited from |
|---|---|---|---|---|
_hooks | protected | Map<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
| Parameter | Type | Description |
|---|---|---|
event | "chat" | Hook event name. |
context | ChatHookContext | Mutable hook context. |
Returns
Promise<void>
Latest message array after all hooks have run.
Inherited from
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
| Parameter | Type | Description |
|---|---|---|
event | "reply" | Hook event name. |
context | ReplyHookContext | Mutable hook context. |
Returns
Promise<void | ChatReply>
Latest message array after all hooks have run.
Inherited from
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
| Parameter | Type | Description |
|---|---|---|
messages | ChatMessage[] | Ordered dialogue history culminating in the latest user prompt. |
options | ChatOptions | Per-request overrides such as model, temperature, or conversation key. |
Returns
Promise<ChatResult>
Parsed chat result containing assistant text, tool calls, and metadata.
Overrides
generateImage()
generateImage(options): Promise<{
images: {
base64: string;
}[];
}>Generates an image using the backing provider.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | { model: string; prompt: string; } | Prompt and configuration for the image request. |
options.model? | string | - |
options.prompt | string | - |
Returns
Promise<{
images: {
base64: string;
}[];
}>
Generated images represented as base64 payloads or URLs.
Overrides
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;
}Overrides
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
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
off()
off(event, hook): voidRemoves a previously registered hook from the engine.
Parameters
Returns
void
Inherited from
on()
on(event, hook): voidRegisters a hook to run during specific engine orchestration events.
Parameters
Returns
void
Inherited from
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
| Parameter | Type | Description |
|---|---|---|
options | VoiceSessionStartOptions | Voice 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
stopVoiceSession()
stopVoiceSession(handle): Promise<void>Stops a realtime voice session previously started by BaseEngine.startVoiceSession.
Parameters
| Parameter | Type |
|---|---|
handle | VoiceSessionHandle |
Returns
Promise<void>
Throws
Always throws when voice is unsupported.
Overrides
summarizeToolResult()
summarizeToolResult(params): Promise<{
responseId: null | string;
summary: string;
}>Optionally summarize tool execution results for provider-specific follow-up prompts.
Parameters
| Parameter | Type |
|---|---|
params | { call: ChatFunctionCall; model: string; resultText: string; success: boolean; } |
params.call | ChatFunctionCall |
params.model? | string |
params.resultText | string |
params.success | boolean |
Returns
Promise<{
responseId: null | string;
summary: string;
}>
Summary text and an optional response identifier for traceability.
Overrides
BaseEngine.summarizeToolResult
supportedFeatures()
supportedFeatures(): EngineSupportedFeaturesReturns the supported feature flags for the engine. Override to enable capabilities.
