mirror of
https://github.com/SilenceLurker/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 15:55:50 +00:00
Update lorebook-bridge.js
This commit is contained in:
@@ -30,23 +30,36 @@ export async function syncToLorebook(tableName, data, indexText, role, headers,
|
|||||||
const entriesToUpdate = [];
|
const entriesToUpdate = [];
|
||||||
const entriesToCreate = [];
|
const entriesToCreate = [];
|
||||||
|
|
||||||
const processEntry = (comment, keys, content, type = 'selective', enabled = true) => {
|
const processEntry = (comment, keys, content, type = 'selective', enabled = true, excludeRecursion = false, specificOrder = null, specificDepth = null) => {
|
||||||
const existingEntry = entries.find(e => e.comment === comment);
|
const existingEntry = entries.find(e => e.comment === comment);
|
||||||
if (existingEntry) {
|
if (existingEntry) {
|
||||||
existingEntry.content = content;
|
existingEntry.content = content;
|
||||||
existingEntry.key = keys;
|
existingEntry.key = keys;
|
||||||
// existingEntry.order = depth; // 【V153.0】不再覆盖用户的深度/排序设置
|
|
||||||
|
existingEntry.exclude_recursion = excludeRecursion;
|
||||||
|
existingEntry.prevent_recursion = excludeRecursion;
|
||||||
|
existingEntry.excludeRecursion = excludeRecursion;
|
||||||
|
existingEntry.preventRecursion = excludeRecursion;
|
||||||
|
|
||||||
|
if (specificOrder !== null) {
|
||||||
|
existingEntry.order = specificOrder;
|
||||||
|
existingEntry.position = 4; // 【V154.2】索引条目强制位置为 4 (@D)
|
||||||
|
}
|
||||||
|
// 【V154.4】如果是索引条目,强制修正Depth为0
|
||||||
|
if (specificDepth !== null) {
|
||||||
|
existingEntry.depth = specificDepth;
|
||||||
|
}
|
||||||
|
|
||||||
if (type === 'constant') {
|
if (type === 'constant') {
|
||||||
existingEntry.constant = true;
|
existingEntry.constant = true;
|
||||||
} else {
|
} else {
|
||||||
existingEntry.constant = false;
|
existingEntry.constant = false;
|
||||||
}
|
}
|
||||||
if (existingEntry.enabled !== undefined) {
|
// 【V154.8】回归WorldEditor逻辑:仅使用 enabled 属性,移除 disable 属性以交给 helper 处理
|
||||||
existingEntry.enabled = enabled;
|
existingEntry.enabled = enabled;
|
||||||
} else {
|
delete existingEntry.disable;
|
||||||
existingEntry.disable = !enabled;
|
delete existingEntry.disabled;
|
||||||
}
|
|
||||||
entriesToUpdate.push(existingEntry);
|
entriesToUpdate.push(existingEntry);
|
||||||
} else {
|
} else {
|
||||||
entriesToCreate.push({
|
entriesToCreate.push({
|
||||||
@@ -54,15 +67,21 @@ export async function syncToLorebook(tableName, data, indexText, role, headers,
|
|||||||
keys: keys,
|
keys: keys,
|
||||||
content: content,
|
content: content,
|
||||||
type: type,
|
type: type,
|
||||||
position: 1,
|
position: 4, // 【V154.2】默认为 4 (@D/D+)
|
||||||
order: depth,
|
order: specificOrder !== null ? specificOrder : depth, // 这里使用的是传入的 8001+ (Order)
|
||||||
enabled: enabled
|
depth: specificDepth !== null ? specificDepth : depth, // 【V154.5】普通条目深度也使用传入的 8001+ (实现深层扫描)
|
||||||
|
enabled: enabled, // 【V154.8】恢复 enabled 属性
|
||||||
|
// disable: !enabled, // 移除 disable
|
||||||
|
exclude_recursion: excludeRecursion,
|
||||||
|
prevent_recursion: excludeRecursion,
|
||||||
|
excludeRecursion: excludeRecursion,
|
||||||
|
preventRecursion: excludeRecursion
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (role === 'database') {
|
if (role === 'database') {
|
||||||
const indexKey = [`Amily_Index_${tableName}`];
|
const indexKey = [`Amily_Index_${tableName}`,'索引'];
|
||||||
const indexComment = `[Amily2] Index for ${tableName}`;
|
const indexComment = `[Amily2] Index for ${tableName}`;
|
||||||
let indexContent = `【${tableName} 索引】\n${indexText.trim()}`;
|
let indexContent = `【${tableName} 索引】\n${indexText.trim()}`;
|
||||||
|
|
||||||
@@ -70,14 +89,13 @@ export async function syncToLorebook(tableName, data, indexText, role, headers,
|
|||||||
indexContent += `\n<system_note>\n【Amily2-前瞻性预测指令】\n为了实现“提前一轮触发绿灯世界书”的高级记忆回流,请在生成本轮回复时,根据当前剧情走向,**大胆预测并自然提及**下一轮可能出现的索引编码。可自行增加一个标签并使用<!--到-->html注释掉该编码。这将激活系统的预加载机制,确保剧情发展的连贯性。\n</system_note>`;
|
indexContent += `\n<system_note>\n【Amily2-前瞻性预测指令】\n为了实现“提前一轮触发绿灯世界书”的高级记忆回流,请在生成本轮回复时,根据当前剧情走向,**大胆预测并自然提及**下一轮可能出现的索引编码。可自行增加一个标签并使用<!--到-->html注释掉该编码。这将激活系统的预加载机制,确保剧情发展的连贯性。\n</system_note>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
processEntry(indexComment, indexKey, indexContent, 'constant');
|
processEntry(indexComment, indexKey, indexContent, 'constant', true, true, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.forEach((row, index) => {
|
data.forEach((row, index) => {
|
||||||
if (!row || row.length === 0) return;
|
if (!row || row.length === 0) return;
|
||||||
|
|
||||||
const rawVal = row[0];
|
const rawVal = row[0];
|
||||||
// 【V152.0】修复Falsy检查漏洞 (支持数字0作为主键)
|
|
||||||
if (rawVal === undefined || rawVal === null) return;
|
if (rawVal === undefined || rawVal === null) return;
|
||||||
|
|
||||||
const primaryVal = String(rawVal).trim();
|
const primaryVal = String(rawVal).trim();
|
||||||
@@ -128,7 +146,6 @@ export async function syncToLorebook(tableName, data, indexText, role, headers,
|
|||||||
|
|
||||||
const activeKeys = new Set();
|
const activeKeys = new Set();
|
||||||
for(const row of data) {
|
for(const row of data) {
|
||||||
// 【V152.0】修复Falsy检查漏洞 (支持数字0作为主键)
|
|
||||||
if(row && row.length > 0) {
|
if(row && row.length > 0) {
|
||||||
const rVal = row[0];
|
const rVal = row[0];
|
||||||
if (rVal !== undefined && rVal !== null) {
|
if (rVal !== undefined && rVal !== null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user