mirror of
https://github.com/SilenceLurker/ST-Amily2-Chat-Optimisation.git
synced 2026-06-07 07:05:49 +00:00
Update lorebook-bridge.js
This commit is contained in:
@@ -3,7 +3,7 @@ import { extension_settings, getContext } from "/scripts/extensions.js";
|
|||||||
import { extensionName } from "../../utils/settings.js";
|
import { extensionName } from "../../utils/settings.js";
|
||||||
import { this_chid, characters } from "/script.js";
|
import { this_chid, characters } from "/script.js";
|
||||||
|
|
||||||
function getMemoryBookName() {
|
export function getMemoryBookName() {
|
||||||
let charName = "Global";
|
let charName = "Global";
|
||||||
const context = getContext();
|
const context = getContext();
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ export async function syncToLorebook(tableName, data, indexText, role, headers,
|
|||||||
if (existingEntry) {
|
if (existingEntry) {
|
||||||
existingEntry.content = content;
|
existingEntry.content = content;
|
||||||
existingEntry.key = keys;
|
existingEntry.key = keys;
|
||||||
existingEntry.order = depth;
|
// existingEntry.order = depth; // 【V153.0】不再覆盖用户的深度/排序设置
|
||||||
|
|
||||||
if (type === 'constant') {
|
if (type === 'constant') {
|
||||||
existingEntry.constant = true;
|
existingEntry.constant = true;
|
||||||
@@ -76,9 +76,12 @@ export async function syncToLorebook(tableName, data, indexText, role, headers,
|
|||||||
data.forEach((row, index) => {
|
data.forEach((row, index) => {
|
||||||
if (!row || row.length === 0) return;
|
if (!row || row.length === 0) return;
|
||||||
|
|
||||||
const primaryVal = row[0];
|
const rawVal = row[0];
|
||||||
|
// 【V152.0】修复Falsy检查漏洞 (支持数字0作为主键)
|
||||||
|
if (rawVal === undefined || rawVal === null) return;
|
||||||
|
|
||||||
if (!primaryVal) return;
|
const primaryVal = String(rawVal).trim();
|
||||||
|
if (primaryVal === '') return;
|
||||||
|
|
||||||
const isPendingDeletion = rowStatuses && rowStatuses[index] === 'pending-deletion';
|
const isPendingDeletion = rowStatuses && rowStatuses[index] === 'pending-deletion';
|
||||||
const isEnabled = !isPendingDeletion;
|
const isEnabled = !isPendingDeletion;
|
||||||
@@ -125,13 +128,26 @@ 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) {
|
||||||
if(row && row[0]) activeKeys.add(row[0]);
|
// 【V152.0】修复Falsy检查漏洞 (支持数字0作为主键)
|
||||||
|
if(row && row.length > 0) {
|
||||||
|
const rVal = row[0];
|
||||||
|
if (rVal !== undefined && rVal !== null) {
|
||||||
|
const sVal = String(rVal).trim();
|
||||||
|
if (sVal !== '') {
|
||||||
|
activeKeys.add(sVal);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`[Amily2-Bridge-GC] ${tableName} 的活跃主键 (Active Keys):`, Array.from(activeKeys));
|
||||||
|
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
if (entry.comment && entry.comment.startsWith(tablePrefix)) {
|
if (entry.comment && entry.comment.startsWith(tablePrefix)) {
|
||||||
const entryKey = entry.comment.substring(tablePrefix.length).trim();
|
const entryKey = entry.comment.substring(tablePrefix.length).trim();
|
||||||
|
|
||||||
if (!activeKeys.has(entryKey)) {
|
if (!activeKeys.has(entryKey)) {
|
||||||
|
console.log(`[Amily2-Bridge-GC] 发现残留条目 (将删除): ${entry.comment} (Key: ${entryKey})`);
|
||||||
entriesToDelete.push(entry.uid);
|
entriesToDelete.push(entry.uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user