2025-12-13 13:37:37 +09:00
|
|
|
import {
|
2025-12-14 11:38:33 +09:00
|
|
|
KEYWORD_DETECTORS,
|
2025-12-13 13:37:37 +09:00
|
|
|
CODE_BLOCK_PATTERN,
|
|
|
|
|
INLINE_CODE_PATTERN,
|
|
|
|
|
} from "./constants"
|
|
|
|
|
|
|
|
|
|
export function removeCodeBlocks(text: string): string {
|
|
|
|
|
return text.replace(CODE_BLOCK_PATTERN, "").replace(INLINE_CODE_PATTERN, "")
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-14 11:38:33 +09:00
|
|
|
export function detectKeywords(text: string): string[] {
|
2025-12-13 13:37:37 +09:00
|
|
|
const textWithoutCode = removeCodeBlocks(text)
|
2025-12-14 11:38:33 +09:00
|
|
|
return KEYWORD_DETECTORS.filter(({ pattern }) =>
|
|
|
|
|
pattern.test(textWithoutCode)
|
|
|
|
|
).map(({ message }) => message)
|
2025-12-13 13:37:37 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function extractPromptText(
|
|
|
|
|
parts: Array<{ type: string; text?: string }>
|
|
|
|
|
): string {
|
|
|
|
|
return parts
|
|
|
|
|
.filter((p) => p.type === "text")
|
|
|
|
|
.map((p) => p.text || "")
|
2025-12-14 11:38:33 +09:00
|
|
|
.join(" ")
|
2025-12-13 13:37:37 +09:00
|
|
|
}
|