MessageClient

MessageClient

Chat completion client wrapper. Builds the conversation payload, sends it to an OpenAI-compatible chat completion endpoint, and returns the reply with a self-reported confidence score. Pointing `opts.baseURL` at a local server (e.g. a vMLX OpenAI-compatible endpoint) allows a local LLM to be used instead of OpenAI.

Constructor

new MessageClient(messageApiKey, optsopt)

Initializes a new message client.
Source:
Parameters:
Name Type Attributes Default Description
messageApiKey string API key for the chat completion endpoint. Any placeholder value works for local LLM servers that don't require authentication.
opts object <optional>
{} Client options.
Name Type Attributes Default Description
model string <optional>
'gpt-5.6' Chat completion model. The minimum supported OpenAI model is GPT-5.6.
instructions string <optional>
Base developer instructions.
enableSecurityInstructions boolean <optional>
true Append security instructions to the base instructions.
baseURL string <optional>
Base URL of the chat completion endpoint. Set this to use a local OpenAI-compatible LLM server (e.g. vMLX) instead of OpenAI.

Methods

_parseStructuredReply(message) → {Object}

Parse and validate a structured reply returned by the model. The API enforces the JSON schema for supported models. Validation here keeps failures explicit when an OpenAI-compatible endpoint does not.
Source:
Parameters:
Name Type Description
message object OpenAI completion message.
Returns:
Type:
Object
Structured reply.

(async) chat(memory, player, message) → {Promise.<{reply: string, confidenceScore: number}>}

Send a message to the chat completion endpoint and return the generated reply.
Source:
Parameters:
Name Type Description
memory Memory Per-player conversation memory.
player string Player name or id.
message string Player message.
Returns:
Type:
Promise.<{reply: string, confidenceScore: number}>
Reply and confidence score.