- Detect ultrawork, search, analyze keywords (EN/KO/JP/CN/VN) - Add session-based injection tracking (once per session) - Remove unnecessary state management 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
26 lines
659 B
TypeScript
26 lines
659 B
TypeScript
import {
|
|
KEYWORD_DETECTORS,
|
|
CODE_BLOCK_PATTERN,
|
|
INLINE_CODE_PATTERN,
|
|
} from "./constants"
|
|
|
|
export function removeCodeBlocks(text: string): string {
|
|
return text.replace(CODE_BLOCK_PATTERN, "").replace(INLINE_CODE_PATTERN, "")
|
|
}
|
|
|
|
export function detectKeywords(text: string): string[] {
|
|
const textWithoutCode = removeCodeBlocks(text)
|
|
return KEYWORD_DETECTORS.filter(({ pattern }) =>
|
|
pattern.test(textWithoutCode)
|
|
).map(({ message }) => message)
|
|
}
|
|
|
|
export function extractPromptText(
|
|
parts: Array<{ type: string; text?: string }>
|
|
): string {
|
|
return parts
|
|
.filter((p) => p.type === "text")
|
|
.map((p) => p.text || "")
|
|
.join(" ")
|
|
}
|