promptPreprocessor.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.promptPreprocessor = promptPreprocessor;
const os_1 = require("os");
const path_1 = require("path");
const store_1 = require("./store");
// Uses default path — custom dataPath from config only applies to tool calls.
const DEFAULT_DATA_PATH = (0, path_1.join)((0, os_1.homedir)(), ".lmstudio-alerts");
async function promptPreprocessor(ctl, userMessage) {
const history = await ctl.pullHistory();
// Only inject on the first message of a session
if (history.length !== 0)
return userMessage;
try {
const all = await (0, store_1.loadAlerts)(DEFAULT_DATA_PATH);
const due = (0, store_1.getDueAlerts)(all);
if (due.length === 0)
return userMessage;
const sorted = [...due].sort((a, b) => {
const priority = { high: 0, normal: 1, low: 2 };
return (priority[a.priority] - priority[b.priority]) ||
new Date(a.dueAt).getTime() - new Date(b.dueAt).getTime();
});
const lines = sorted.map(a => {
const overdue = new Date(a.dueAt) < new Date();
const timeStr = new Date(a.dueAt).toLocaleString([], { dateStyle: "short", timeStyle: "short" });
const flag = a.priority === "high" ? "[HIGH]" : a.priority === "normal" ? "[NORMAL]" : "[LOW]";
const status = overdue ? `OVERDUE (was due ${timeStr})` : `due ${timeStr}`;
return ` ${flag} [id:${a.id}] ${a.message} — ${status}`;
});
const alertBlock = `[ALERTS — ${due.length} pending reminder${due.length > 1 ? "s" : ""}:\n${lines.join("\n")}\nTo dismiss: alert(action="dismiss", id="<id>")]`;
return `${alertBlock}\n\n${userMessage.getText()}`;
}
catch {
return userMessage;
}
}