From 45505116029950c90c3ce1d07ea7b995ddcc3fb7 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Wed, 1 Oct 2025 23:25:28 +0800 Subject: [PATCH] Update lore.js --- core/lore.js | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/core/lore.js b/core/lore.js index b139a04..14d791f 100644 --- a/core/lore.js +++ b/core/lore.js @@ -226,6 +226,74 @@ export async function writeSummaryToLorebook(pendingData) { } } +export async function getOptimizationWorldbookContent() { + const panel = $("#amily2_chat_optimiser"); + if (panel.length === 0) { + console.warn('[Amily2-正文优化] 未找到主设置面板,无法读取世界书设置。'); + return ''; + } + + const settings = { + enabled: panel.find('#amily2_wb_enabled').is(':checked'), + source: panel.find('input[name="amily2_wb_source"]:checked').val() || 'character', + selectedBooks: [], + selectedEntries: {}, + }; + + if (!settings.enabled) { + return ''; + } + + panel.find('#amily2_wb_checkbox_list input[type="checkbox"]:checked').each(function() { + settings.selectedBooks.push($(this).val()); + }); + + panel.find('#amily2_wb_entry_list input[type="checkbox"]:checked').each(function() { + const book = $(this).data('book'); + const uid = parseInt($(this).data('uid')); + if (!settings.selectedEntries[book]) { + settings.selectedEntries[book] = []; + } + settings.selectedEntries[book].push(uid); + }); + + try { + let bookNames = []; + if (settings.source === 'manual') { + bookNames = settings.selectedBooks; + } else { + const charLorebooks = await safeCharLorebooks({ type: 'all' }); + if (charLorebooks.primary) bookNames.push(charLorebooks.primary); + if (charLorebooks.additional?.length) bookNames.push(...charLorebooks.additional); + } + + if (bookNames.length === 0) return ''; + + let allEntries = []; + for (const bookName of bookNames) { + if (bookName) { + const entries = await safeLorebookEntries(bookName); + if (entries?.length) { + entries.forEach(entry => allEntries.push({ ...entry, bookName })); + } + } + } + + const userEnabledEntries = allEntries.filter(entry => { + if (!entry.enabled) return false; + const bookConfig = settings.selectedEntries[entry.bookName]; + return bookConfig ? bookConfig.includes(entry.uid) : false; + }); + + const finalContent = userEnabledEntries.map(entry => entry.content).filter(Boolean); + return finalContent.join('\n\n---\n\n'); + + } catch (error) { + console.error(`[Amily2-正文优化] 处理世界书逻辑时出错:`, error); + return ''; + } +} + export async function getPlotOptimizedWorldbookContent(context, apiSettings) { const panel = $('#amily2_plot_optimization_panel');