Forked from elenath/timestamp
src / promptPreprocessor.ts
import { type PromptPreprocessorController, type ChatMessage } from "@lmstudio/sdk";
function formatTimestamp(d: Date): string {
const pad = (n: number) => n.toString().padStart(2, "0");
const dd = pad(d.getDate());
const mm = pad(d.getMonth() + 1);
const yyyy = d.getFullYear();
const hh = pad(d.getHours());
const min = pad(d.getMinutes());
return `[${yyyy}-${mm}-${dd} ${hh}:${min}]`;
}
export async function preprocess(
ctl: PromptPreprocessorController,
userMessage: ChatMessage,
) {
const timestamp = formatTimestamp(new Date());
ctl.createStatus({
status: "done",
text: `Timestamp ${timestamp}`,
});
const text = userMessage.getText();
return `${timestamp}\n\n${text}`;
}