MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / compileRules

Function compileRules

packages/node-runtime/src/ai/preprocessor/pipeline.ts:238–260  ·  view source on GitHub ↗
(
  rules: DesensitizeRule[],
  logger: PreprocessLogger
)

Source from the content-addressed store, hash-verified

236const regexCache = new Map<string, RegExp | null>()
237
238function compileRules(
239 rules: DesensitizeRule[],
240 logger: PreprocessLogger
241): Array<{ regex: RegExp; replacement: string }> {
242 const result: Array<{ regex: RegExp; replacement: string }> = []
243 for (const rule of rules) {
244 let regex = regexCache.get(rule.pattern)
245 if (regex === undefined) {
246 try {
247 regex = new RegExp(rule.pattern, 'g')
248 regexCache.set(rule.pattern, regex)
249 } catch {
250 logger.warn('Preprocess', `Invalid regex in desensitize rule "${rule.id}": ${rule.pattern}`)
251 regexCache.set(rule.pattern, null)
252 continue
253 }
254 }
255 if (regex) {
256 result.push({ regex, replacement: rule.replacement })
257 }
258 }
259 return result
260}

Callers 1

applyDesensitizeFunction · 0.85

Calls 3

setMethod · 0.80
getMethod · 0.65
warnMethod · 0.65

Tested by

no test coverage detected