新增 memory 和 skill 存储,实现 Agent 持续学习,并增加工具支持;增加 LLM progress detail 输出
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
const FORBIDDEN_PERSISTENCE_PATTERNS = [
|
||||
/ignore\s+(all|previous|prior|above)\s+instructions/i,
|
||||
/system\s+prompt/i,
|
||||
/do\s+not\s+tell\s+the\s+user/i,
|
||||
/curl\s+.*(token|secret|password|api)/i,
|
||||
/bearer\s+[a-z0-9._-]{16,}/i,
|
||||
/(api[_-]?key|access[_-]?token|refresh[_-]?token|secret|password)\s*[:=]/i,
|
||||
/eyJ[a-zA-Z0-9_-]{8,}\.[a-zA-Z0-9._-]{8,}\.[a-zA-Z0-9._-]{8,}/,
|
||||
];
|
||||
|
||||
export const sanitizePersistentLine = (content: string, maxLength: number) => {
|
||||
const normalized = content.replace(/\s+/g, " ").trim();
|
||||
if (!normalized) {
|
||||
return "";
|
||||
}
|
||||
if (FORBIDDEN_PERSISTENCE_PATTERNS.some((pattern) => pattern.test(normalized))) {
|
||||
return "";
|
||||
}
|
||||
if (normalized.length > maxLength) {
|
||||
return `${normalized.slice(0, maxLength - 3).trimEnd()}...`;
|
||||
}
|
||||
return normalized;
|
||||
};
|
||||
|
||||
export const sanitizePersistentDocument = (content: string, maxLength: number) => {
|
||||
const normalized = content
|
||||
.replace(/\r\n/g, "\n")
|
||||
.split("\n")
|
||||
.map((line) => line.trimEnd())
|
||||
.join("\n")
|
||||
.replace(/\n{3,}/g, "\n\n")
|
||||
.trim();
|
||||
if (!normalized) {
|
||||
return "";
|
||||
}
|
||||
if (FORBIDDEN_PERSISTENCE_PATTERNS.some((pattern) => pattern.test(normalized))) {
|
||||
return "";
|
||||
}
|
||||
if (normalized.length > maxLength) {
|
||||
return `${normalized.slice(0, maxLength - 3).trimEnd()}...`;
|
||||
}
|
||||
return normalized;
|
||||
};
|
||||
Reference in New Issue
Block a user