"use strict";
/**
* @file Merged preprocessor — runs memory injection first, then tools RAG/docs injection.
*
* Order: [user message] + [memories] + [tools docs / RAG / delegation hints]
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.maestroPreprocessor = maestroPreprocessor;
const preprocessor_1 = require("./memory/preprocessor");
const promptPreprocessor_1 = require("./tools/promptPreprocessor");
async function maestroPreprocessor(ctl, userMessage) {
// Extract text from whatever the SDK gives us
let messageText;
if (typeof userMessage === "string") {
messageText = userMessage;
}
else if (typeof userMessage?.getText === "function") {
messageText = userMessage.getText();
}
else {
messageText = String(userMessage);
}
// Stage 1: inject memories (string → string)
let afterMemory;
try {
const memResult = await (0, preprocessor_1.promptPreprocessor)(ctl, messageText);
afterMemory = typeof memResult === "string" ? memResult : messageText;
}
catch (e) {
try {
ctl.debug(`Memory preprocessor failed: ${e instanceof Error ? e.message : String(e)}`);
}
catch { /* ignore */ }
afterMemory = messageText;
}
// Stage 2: run tools preprocessor — pass the memory-enriched string directly.
// The tools preprocessor now accepts both ChatMessage and string.
let finalContent;
try {
const toolsResult = await (0, promptPreprocessor_1.promptPreprocessor)(ctl, afterMemory);
if (typeof toolsResult === "string") {
finalContent = toolsResult;
}
else if (toolsResult && typeof toolsResult.getText === "function") {
finalContent = toolsResult.getText();
}
else {
finalContent = afterMemory;
}
}
catch (e) {
try {
ctl.debug(`Tools preprocessor failed: ${e instanceof Error ? e.message : String(e)}`);
}
catch { /* ignore */ }
finalContent = afterMemory;
}
return finalContent;
}
//# sourceMappingURL=preprocessor.js.map