skill manager 添加脚本管理功能,支持写入和删除可复用脚本

This commit is contained in:
2026-05-15 17:07:52 +08:00
parent 4ec6cbed16
commit 2f83add134
7 changed files with 127 additions and 8 deletions
+19 -2
View File
@@ -14,12 +14,15 @@ const FORBIDDEN_PERSISTENCE_PATTERNS = [
/eyJ[a-zA-Z0-9_-]{8,}\.[a-zA-Z0-9._-]{8,}\.[a-zA-Z0-9._-]{8,}/,
];
export const containsForbiddenPersistentContent = (content: string) =>
FORBIDDEN_PERSISTENCE_PATTERNS.some((pattern) => pattern.test(content));
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))) {
if (containsForbiddenPersistentContent(normalized)) {
return "";
}
if (normalized.length > maxLength) {
@@ -39,7 +42,7 @@ export const sanitizePersistentDocument = (content: string, maxLength: number) =
if (!normalized) {
return "";
}
if (FORBIDDEN_PERSISTENCE_PATTERNS.some((pattern) => pattern.test(normalized))) {
if (containsForbiddenPersistentContent(normalized)) {
return "";
}
if (normalized.length > maxLength) {
@@ -47,3 +50,17 @@ export const sanitizePersistentDocument = (content: string, maxLength: number) =
}
return normalized;
};
export const sanitizePersistentScript = (content: string, maxLength: number) => {
const normalized = content.replace(/\r\n/g, "\n").replace(/\t/g, " ").trim();
if (!normalized) {
return "";
}
if (containsForbiddenPersistentContent(normalized)) {
return "";
}
if (normalized.length > maxLength) {
return "";
}
return `${normalized}\n`;
};