From 14492e6a3f98cf4102b11af4a34efc8501147d6b Mon Sep 17 00:00:00 2001 From: Lubrsy706 Date: Thu, 14 May 2026 01:16:00 +0800 Subject: [PATCH] fix: replace deprecated prompt injection model --- workers/lib/ai.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/workers/lib/ai.ts b/workers/lib/ai.ts index 78ac4ddd..96a638d5 100644 --- a/workers/lib/ai.ts +++ b/workers/lib/ai.ts @@ -21,16 +21,18 @@ Return ONLY "NO" if it is a normal email (even if angry, confused, or containing Respond with exactly one word: YES or NO.`; +const PROMPT_INJECTION_MODEL = "@cf/zai-org/glm-4.7-flash"; + export async function isPromptInjection(ai: Ai, bodyHtml: string | null | undefined): Promise { if (!bodyHtml) return false; - + const plainText = stripHtmlToText(bodyHtml).trim(); if (plainText.length < 10) return false; try { const response = (await ai.run( // @ts-expect-error — model string not in generated union - "@cf/meta/llama-3.1-8b-instruct-fast", + PROMPT_INJECTION_MODEL, { messages: [ { role: "system", content: INJECTION_PROMPT }, @@ -42,12 +44,12 @@ export async function isPromptInjection(ai: Ai, bodyHtml: string | null | undefi )) as { response?: string }; const result = (response?.response || "NO").trim().toUpperCase(); - + if (result.includes("YES")) { console.warn("Prompt injection detected in incoming email, blocking auto-draft"); return true; } - + return false; } catch (e) { console.error("Prompt injection scanner failed, skipping auto-draft:", (e as Error).message);