meshcore.js

ai

/ask <question> answered by an OpenAI-compatible model, with memory and cooldown.

Someone sends /ask where is Toulouse to the bot. The bot asks the model and answers in one or two sentences.

Install

npm install @meshcorejs/plugin-ai

Configure

plugins/ai.ts
import ai from '@meshcorejs/plugin-ai';

export default ai.configure({ apiKey: process.env.OPENAI_API_KEY ?? '' });

Another provider and French replies:

plugins/ai.ts
import { frenchReplies } from '@meshcorejs/plugin-ai';

export const openrouter = ai.configure({
  apiKey: process.env.OPENROUTER_KEY ?? '',
  baseURL: 'https://openrouter.ai/api/v1',
  model: 'mistralai/mistral-small',
  cooldown: 60,
  replies: frenchReplies,
});

On the air

/ask <question> in a DM, @Bot ask <question> on a channel. Everyone can ask, once every 30 seconds. The model remembers the last six exchanges of each author for ten minutes, so a follow-up question works.

A long answer is split in two radio messages at most. When the model fails, the bot says ⚠️ The assistant is unavailable, try again later and nothing else.

/ask with no text at all is refused by the framework's own missing-argument reply, before the plugin runs. The plugin's empty reply only answers a quoted empty question, such as /ask "".

Options

OptionDefaultRole
apiKeyrequiredThe provider's API key. Read it from your own environment.
modelgpt-5-miniModel name.
baseURLOpenAIBase URL of an OpenAI-compatible provider.
systemPromptsee belowReplaces the instruction. The bot's name is always appended.
cooldown30Seconds between two /ask by the same author.
permissionnonePermission required to ask. Without it everyone can.
history6Exchanges remembered per author. 0 disables memory.
historyTtl600Seconds before an author's memory is forgotten.
maxParts2Radio messages an answer may take, 1 to 3.
repliesEnglishfrenchReplies, or a partial override.
openaiReplaces the SDK client. For tests.

Default instruction: You answer over a LoRa radio. Reply in one or two short sentences, plain text, no markdown, no lists.

Without baseURL, the openai SDK still reads its own environment fallbacks, while the plugin itself never reads process.env.

Replies

KeyEnglish
unavailable⚠️ The assistant is unavailable, try again later
empty❓ Ask me something: /ask <question>

Reference

On this page