Update secondary-filler.js

This commit is contained in:
2025-10-01 23:35:11 +08:00
committed by GitHub
parent e730a77c1a
commit 232ea18a91

View File

@@ -2,8 +2,9 @@ import { getContext, extension_settings } from "/scripts/extensions.js";
import { loadWorldInfo } from "/scripts/world-info.js"; import { loadWorldInfo } from "/scripts/world-info.js";
import { saveChat } from "/script.js"; import { saveChat } from "/script.js";
import { renderTables } from '../../ui/table-bindings.js'; import { renderTables } from '../../ui/table-bindings.js';
import { updateOrInsertTableInChat } from '../../ui/message-table-renderer.js';
import { extensionName } from "../../utils/settings.js"; import { extensionName } from "../../utils/settings.js";
import { updateTableFromText, getBatchFillerRuleTemplate, getBatchFillerFlowTemplate, convertTablesToCsvString, saveStateToMessage, getMemoryState } from './manager.js'; import { updateTableFromText, getBatchFillerRuleTemplate, getBatchFillerFlowTemplate, convertTablesToCsvString, saveStateToMessage, getMemoryState, clearHighlights } from './manager.js';
import { getPresetPrompts, getMixedOrder } from '../../PresetSettings/index.js'; import { getPresetPrompts, getMixedOrder } from '../../PresetSettings/index.js';
import { callAI, generateRandomSeed } from '../api.js'; import { callAI, generateRandomSeed } from '../api.js';
import { callNccsAI } from '../api/NccsApi.js'; import { callNccsAI } from '../api/NccsApi.js';
@@ -48,6 +49,8 @@ async function getWorldBookContext() {
} }
export async function fillWithSecondaryApi(latestMessage) { export async function fillWithSecondaryApi(latestMessage) {
clearHighlights();
const context = getContext(); const context = getContext();
if (context.chat.length <= 1) { if (context.chat.length <= 1) {
console.log("[Amily2-副API] 聊天刚开始,跳过本次自动填表。"); console.log("[Amily2-副API] 聊天刚开始,跳过本次自动填表。");
@@ -76,11 +79,30 @@ export async function fillWithSecondaryApi(latestMessage) {
} }
try { try {
const textToProcess = latestMessage.mes; let textToProcess = latestMessage.mes;
if (!textToProcess || !textToProcess.trim()) { if (!textToProcess || !textToProcess.trim()) {
console.log("[Amily2-副API] 消息内容为空,跳过填表任务。"); console.log("[Amily2-副API] 消息内容为空,跳过填表任务。");
console.timeEnd("副API填表任务总耗时"); return;
console.groupEnd(); }
let tagsToExtract, exclusionRules;
if (settings.table_independent_rules_enabled) {
tagsToExtract = (settings.table_tags_to_extract || '').split(',').map(t => t.trim()).filter(Boolean);
exclusionRules = settings.table_exclusion_rules || [];
} else {
const useHistoriographyRules = settings.historiographyTagExtractionEnabled ?? false;
tagsToExtract = useHistoriographyRules ? (settings.historiographyTags || '').split(',').map(t => t.trim()).filter(Boolean) : [];
exclusionRules = settings.historiographyExclusionRules || [];
}
if (tagsToExtract.length > 0) {
const blocks = extractBlocksByTags(textToProcess, tagsToExtract);
textToProcess = blocks.join('\n\n');
}
textToProcess = applyExclusionRules(textToProcess, exclusionRules);
if (!textToProcess.trim()) {
console.log("[Amily2-副API] 规则处理后消息内容为空,跳过填表任务。");
return; return;
} }
@@ -241,7 +263,8 @@ export async function fillWithSecondaryApi(latestMessage) {
const lastMessage = currentContext.chat[currentContext.chat.length - 1]; const lastMessage = currentContext.chat[currentContext.chat.length - 1];
if (saveStateToMessage(getMemoryState(), lastMessage)) { if (saveStateToMessage(getMemoryState(), lastMessage)) {
saveChat(); saveChat();
renderTables(); renderTables();
updateOrInsertTableInChat();
return; return;
} }
} }
@@ -270,21 +293,28 @@ async function getHistoryContext(contextLevel) {
const userName = context.name1 || '用户'; const userName = context.name1 || '用户';
const characterName = context.name2 || '角色'; const characterName = context.name2 || '角色';
const useTagExtraction = settings.historiographyTagExtractionEnabled ?? false; let tagsToExtract, exclusionRules;
const tagsToExtract = useTagExtraction ? (settings.historiographyTags || '').split(',').map(t => t.trim()).filter(Boolean) : [];
const exclusionRules = settings.historiographyExclusionRules || []; if (settings.table_independent_rules_enabled) {
tagsToExtract = (settings.table_tags_to_extract || '').split(',').map(t => t.trim()).filter(Boolean);
exclusionRules = settings.table_exclusion_rules || [];
} else {
const useHistoriographyRules = settings.historiographyTagExtractionEnabled ?? false;
tagsToExtract = useHistoriographyRules ? (settings.historiographyTags || '').split(',').map(t => t.trim()).filter(Boolean) : [];
exclusionRules = settings.historiographyExclusionRules || [];
}
const messages = historySlice.map((msg, index) => { const messages = historySlice.map((msg, index) => {
let content = msg.mes; let content = msg.mes;
if (useTagExtraction && tagsToExtract.length > 0) { if (tagsToExtract.length > 0) {
const blocks = extractBlocksByTags(content, tagsToExtract); const blocks = extractBlocksByTags(content, tagsToExtract);
if (blocks.length > 0) { content = blocks.length > 0 ? blocks.join('\n\n') : '';
content = blocks.join('\n\n');
}
} }
content = applyExclusionRules(content, exclusionRules); if (content) {
content = applyExclusionRules(content, exclusionRules);
}
if (!content.trim()) return null; if (!content.trim()) return null;