|
@@ -50,6 +50,8 @@ const PROMPT_INJECTION_PATTERNS = [
|
|
|
/<\s*(system|assistant|developer|tool)\b/i,
|
|
/<\s*(system|assistant|developer|tool)\b/i,
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
|
|
+const SESSION_RESET_PREFIX = "A new session was started via /new or /reset.";
|
|
|
|
|
+
|
|
|
function looksLikePromptInjection(text: string): boolean {
|
|
function looksLikePromptInjection(text: string): boolean {
|
|
|
const normalized = text.replace(/\s+/g, " ").trim();
|
|
const normalized = text.replace(/\s+/g, " ").trim();
|
|
|
return PROMPT_INJECTION_PATTERNS.some((pattern) => pattern.test(normalized));
|
|
return PROMPT_INJECTION_PATTERNS.some((pattern) => pattern.test(normalized));
|
|
@@ -513,12 +515,20 @@ const knowhubPlugin = {
|
|
|
if (cfg.reminderMode !== "off") {
|
|
if (cfg.reminderMode !== "off") {
|
|
|
api.on("before_prompt_build", async (event, ctx) => {
|
|
api.on("before_prompt_build", async (event, ctx) => {
|
|
|
try {
|
|
try {
|
|
|
|
|
+ if (ctx.trigger && ctx.trigger !== "user") {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const stripped = stripLeadingInboundMetadata(event.prompt);
|
|
const stripped = stripLeadingInboundMetadata(event.prompt);
|
|
|
const userPrompt = normalizeStrippedInboundText(stripped).trim();
|
|
const userPrompt = normalizeStrippedInboundText(stripped).trim();
|
|
|
if (!userPrompt || userPrompt.length < 5 || userPrompt.startsWith("/")) {
|
|
if (!userPrompt || userPrompt.length < 5 || userPrompt.startsWith("/")) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (userPrompt.startsWith(SESSION_RESET_PREFIX)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const topK = 5;
|
|
const topK = 5;
|
|
|
const minScore = 3;
|
|
const minScore = 3;
|
|
|
|
|
|