src / promptPreprocessor.ts
import { type ChatMessage, type PromptPreprocessorController } from "@lmstudio/sdk";
import { ragPeerStatus } from "./peers";
import { donationManager } from "./donations";
const SYSTEM_RULES = `\
[System: Document Parser Plugin]
• parse_document — extract full text from PDF, DOCX, spreadsheet, or plain text files.
• search_document — keyword/regex search inside a document with surrounding context lines.
• Output tool results directly; do not paraphrase or truncate document content unless asked.
• On tool_error, read the error field and correct the parameter before retrying.`;
export async function promptPreprocessor(
ctl: PromptPreprocessorController,
userMessage: ChatMessage,
): Promise<string | ChatMessage> {
const history = await ctl.pullHistory();
if (history.length !== 0) return userMessage;
const ragTip = ragPeerStatus() === false
? `\n\n[Tip: Install the "altra/rag" plugin to semantically index documents with embeddings. rag_ingest + rag_query enables meaning-based retrieval across all your documents — search_document is keyword/regex only and requires re-reading the file each time.]`
: "";
let prompt = `${SYSTEM_RULES}${ragTip}\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 { ragPeerStatus } from "./peers";
import { donationManager } from "./donations";
const SYSTEM_RULES = `\
[System: Document Parser Plugin]
• parse_document — extract full text from PDF, DOCX, spreadsheet, or plain text files.
• search_document — keyword/regex search inside a document with surrounding context lines.
• Output tool results directly; do not paraphrase or truncate document content unless asked.
• On tool_error, read the error field and correct the parameter before retrying.`;
export async function promptPreprocessor(
ctl: PromptPreprocessorController,
userMessage: ChatMessage,
): Promise<string | ChatMessage> {
const history = await ctl.pullHistory();
if (history.length !== 0) return userMessage;
const ragTip = ragPeerStatus() === false
? `\n\n[Tip: Install the "altra/rag" plugin to semantically index documents with embeddings. rag_ingest + rag_query enables meaning-based retrieval across all your documents — search_document is keyword/regex only and requires re-reading the file each time.]`
: "";
let prompt = `${SYSTEM_RULES}${ragTip}\n\n${userMessage.getText()}`;
if (donationManager.shouldShowDonationPrompt()) {
prompt += `\n\n${donationManager.getDonationPrompt()}`;
}
return prompt;
}