src / promptPreprocessor.ts
import { type ChatMessage, type PromptPreprocessorController } from "@lmstudio/sdk";
import { pluginConfigSchematics } from "./config";
import { getConfiguredAccounts } from "./accounts";
import { donationManager } from "./donations";
const SYSTEM_RULES = `\
[System: Email Plugin — Multi-Account]
• email_accounts — list configured accounts and their slot numbers/labels
• email_list(account) — recent emails from a folder
• email_search(account, query/from/subject/since/...) — search emails
• email_read(uid, account) — full email body + attachments
• email_list_folders(account) — all mailbox folders for an account
• email_delete(uids, account) — move email(s) to Trash (recoverable, confirm first)
• email_send(account, to, subject, body) — send/reply via SMTP
account param: slot number ("1","2","3"), label ("Work","Personal"), or blank for first account.
Always confirm with user before email_send — it is irreversible.
On tool_error "not configured": tell the user to add credentials in plugin settings.`;
export async function promptPreprocessor(
ctl: PromptPreprocessorController,
userMessage: ChatMessage,
): Promise<string | ChatMessage> {
const history = await ctl.pullHistory();
if (history.length !== 0) return userMessage;
const cfg = ctl.getPluginConfig(pluginConfigSchematics);
const accounts = getConfiguredAccounts(cfg);
let accountInfo: string;
if (accounts.length === 0) {
accountInfo = `\n\n[Setup required: No email accounts configured. Add IMAP Host, Email Address, and Password for at least one account in plugin settings.]`;
} else {
const list = accounts.map(a => ` • ${a.slot} — ${a.label} (${a.imap.user})${a.smtp ? " [send enabled]" : " [read-only]"}`).join("\n");
accountInfo = `\n\n[Configured accounts:\n${list}]`;
}
let prompt = `${SYSTEM_RULES}${accountInfo}\n\n${userMessage.getText()}`;
if (donationManager.shouldShowDonationPrompt()) {
prompt += `\n\n${donationManager.getDonationPrompt()}`;
}
return prompt;
}
src / promptPreprocessor.ts
import { type ChatMessage, type PromptPreprocessorController } from "@lmstudio/sdk";
import { pluginConfigSchematics } from "./config";
import { getConfiguredAccounts } from "./accounts";
import { donationManager } from "./donations";
const SYSTEM_RULES = `\
[System: Email Plugin — Multi-Account]
• email_accounts — list configured accounts and their slot numbers/labels
• email_list(account) — recent emails from a folder
• email_search(account, query/from/subject/since/...) — search emails
• email_read(uid, account) — full email body + attachments
• email_list_folders(account) — all mailbox folders for an account
• email_delete(uids, account) — move email(s) to Trash (recoverable, confirm first)
• email_send(account, to, subject, body) — send/reply via SMTP
account param: slot number ("1","2","3"), label ("Work","Personal"), or blank for first account.
Always confirm with user before email_send — it is irreversible.
On tool_error "not configured": tell the user to add credentials in plugin settings.`;
export async function promptPreprocessor(
ctl: PromptPreprocessorController,
userMessage: ChatMessage,
): Promise<string | ChatMessage> {
const history = await ctl.pullHistory();
if (history.length !== 0) return userMessage;
const cfg = ctl.getPluginConfig(pluginConfigSchematics);
const accounts = getConfiguredAccounts(cfg);
let accountInfo: string;
if (accounts.length === 0) {
accountInfo = `\n\n[Setup required: No email accounts configured. Add IMAP Host, Email Address, and Password for at least one account in plugin settings.]`;
} else {
const list = accounts.map(a => ` • ${a.slot} — ${a.label} (${a.imap.user})${a.smtp ? " [send enabled]" : " [read-only]"}`).join("\n");
accountInfo = `\n\n[Configured accounts:\n${list}]`;
}
let prompt = `${SYSTEM_RULES}${accountInfo}\n\n${userMessage.getText()}`;
if (donationManager.shouldShowDonationPrompt()) {
prompt += `\n\n${donationManager.getDonationPrompt()}`;
}
return prompt;
}