Files
ST-Amily2-Chat-Optimisation…/core/historiographer.js
2025-08-25 14:56:08 +08:00

2 lines
31 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const _0x5979b5=_0x3157;(function(_0x1f54ce,_0x4cc3db){const _0x19e11b=_0x3157,_0xddf3c2=_0x1f54ce();while(!![]){try{const _0x1930ba=parseInt(_0x19e11b(0x1bd))/0x1+parseInt(_0x19e11b(0x1dd))/0x2+-parseInt(_0x19e11b(0x13a))/0x3+parseInt(_0x19e11b(0x1f9))/0x4+parseInt(_0x19e11b(0x1ca))/0x5*(parseInt(_0x19e11b(0x1a9))/0x6)+parseInt(_0x19e11b(0x179))/0x7+-parseInt(_0x19e11b(0x16c))/0x8;if(_0x1930ba===_0x4cc3db)break;else _0xddf3c2['push'](_0xddf3c2['shift']());}catch(_0x53cf7f){_0xddf3c2['push'](_0xddf3c2['shift']());}}}(_0x4596,0x584db));import{getContext,extension_settings}from'/scripts/extensions.js';import{characters}from'/script.js';import{extractBlocksByTags,applyExclusionRules}from'./utils/rag-tag-extractor.js';import{world_names,loadWorldInfo,createNewWorldInfo,createWorldInfoEntry,saveWorldInfo}from'/scripts/world-info.js';import{extensionName}from'../utils/settings.js';import{getChatIdentifier,writeToLorebookWithTavernHelper}from'./lore.js';import{ingestTextToHanlinyuan}from'./rag-processor.js';import{showSummaryModal,showHtmlModal}from'../ui/page-window.js';import{getPresetPrompts,getMixedOrder}from'../PresetSettings/index.js';import{callAI,generateRandomSeed}from'./api.js';let isExpeditionRunning=![],manualStopRequested=![];const RUNNING_LOG_COMMENT=_0x5979b5(0x1dc),PROGRESS_SEAL_REGEX=/本条勿动【前(\d+)楼总结已完成】否则后续总结无法进行。$/;async function readGoldenLedgerProgress(_0x3f510c){const _0x444a0f=_0x5979b5;if(!_0x3f510c)return 0x0;try{const _0x27b1e9=await loadWorldInfo(_0x3f510c);if(!_0x27b1e9||!_0x27b1e9[_0x444a0f(0x12c)])return 0x0;const _0x4cbd5e=Object['values'](_0x27b1e9[_0x444a0f(0x12c)])[_0x444a0f(0x19e)](_0x2cc384=>_0x2cc384[_0x444a0f(0x1c1)]===RUNNING_LOG_COMMENT&&!_0x2cc384[_0x444a0f(0x1ef)]);if(!_0x4cbd5e)return 0x0;const _0x52fe04=_0x4cbd5e[_0x444a0f(0x172)][_0x444a0f(0x166)](PROGRESS_SEAL_REGEX);return _0x52fe04?parseInt(_0x52fe04[0x1],0xa):0x0;}catch(_0x3979db){return console[_0x444a0f(0x17c)](_0x444a0f(0x1b2)+_0x3f510c+'》天机时出错:',_0x3979db),0x0;}}export async function checkAndTriggerAutoSummary(){const _0x2a636f=_0x5979b5;if(isExpeditionRunning)return;const _0x8cf107=extension_settings[extensionName];if(!_0x8cf107['historiographySmallAutoEnable'])return;const _0x360639=getContext();let _0x498bb7=null;switch(_0x8cf107[_0x2a636f(0x149)]){case _0x2a636f(0x1b5):_0x498bb7=characters[_0x360639[_0x2a636f(0x1df)]]?.[_0x2a636f(0x1d9)]?.[_0x2a636f(0x1b7)]?.[_0x2a636f(0x131)];break;case _0x2a636f(0x192):const _0x4069c4=await getChatIdentifier();_0x498bb7=_0x2a636f(0x1cb)+_0x4069c4;break;default:return;}if(!_0x498bb7)return;const _0x513c20=await readGoldenLedgerProgress(_0x498bb7),_0x303520=_0x360639[_0x2a636f(0x140)]['length'],_0x372a8f=_0x303520-_0x513c20;if(_0x372a8f>=_0x8cf107['historiographySmallTriggerThreshold']+0x2){const _0xfb7805=_0x8cf107[_0x2a636f(0x1da)],_0x5cad2b=_0x513c20+0x1,_0x18fea9=Math[_0x2a636f(0x199)](_0x513c20+_0xfb7805,_0x303520);console[_0x2a636f(0x1a3)](_0x2a636f(0x1c2)+_0x5cad2b+_0x2a636f(0x182)+_0x18fea9+'\x20楼。');const _0xacf121=_0x8cf107[_0x2a636f(0x16f)]??![];await executeManualSummary(_0x5cad2b,_0x18fea9,!_0xacf121);}}export async function getAvailableWorldbooks(){return[...world_names];}export async function getLoresForWorldbook(_0x1e7003){const _0x2fee2d=_0x5979b5;if(!_0x1e7003)return[];try{const _0x12b75c=await loadWorldInfo(_0x1e7003);if(!_0x12b75c||!_0x12b75c[_0x2fee2d(0x12c)])return[];return Object['entries'](_0x12b75c[_0x2fee2d(0x12c)])[_0x2fee2d(0x193)](([,_0x31b073])=>!_0x31b073[_0x2fee2d(0x1ef)])[_0x2fee2d(0x137)](([_0x131293,_0x3dabce])=>({'key':_0x131293,'comment':_0x3dabce[_0x2fee2d(0x1c1)]||_0x2fee2d(0x1f0)}));}catch(_0x4ccb24){return console['error'](_0x2fee2d(0x152)+_0x1e7003+'》时出错:',_0x4ccb24),[];}}export async function executeManualSummary(_0x155cea,_0x4df02e,_0x5aa30b=![]){return new Promise(async _0x2c12d3=>{const _0x99ad47=_0x3157,_0x479a2e=_0x5aa30b?_0x99ad47(0x170):_0x99ad47(0x1d1),_0x5b21fb=getContext();if(_0x5aa30b){const _0x11d621=getRawMessagesForSummary(_0x155cea,_0x4df02e);if(!_0x11d621||_0x11d621[_0x99ad47(0x18b)]===0x0)return toastr[_0x99ad47(0x12b)](_0x99ad47(0x1b1),_0x479a2e),_0x2c12d3(![]);const _0x506d0c=_0x11d621['map'](_0x35c781=>_0x99ad47(0x1c8)+_0x35c781[_0x99ad47(0x1a1)]+_0x99ad47(0x1ed)+_0x35c781[_0x99ad47(0x1a6)]+':\x20'+_0x35c781[_0x99ad47(0x172)])[_0x99ad47(0x133)]('\x0a'),_0x28802c=await getSummary(_0x506d0c,_0x479a2e);_0x28802c?showSummaryModal(_0x28802c,{'onConfirm':async _0x5f11fb=>{const _0x1af6cb=await writeSummary(_0x5f11fb,_0x155cea,_0x4df02e,_0x479a2e);_0x2c12d3(_0x1af6cb);},'onRegenerate':async _0x39c2e4=>{const _0x35bd9d=_0x99ad47;_0x39c2e4['find'](_0x35bd9d(0x1c3))['prop'](_0x35bd9d(0x1c4),!![])[_0x35bd9d(0x148)](_0x35bd9d(0x132));const _0x495cca=await getSummary(_0x506d0c,_0x479a2e);_0x495cca?_0x39c2e4[_0x35bd9d(0x19e)](_0x35bd9d(0x1c3))[_0x35bd9d(0x1c5)](_0x35bd9d(0x1c4),![])[_0x35bd9d(0x148)](_0x495cca):(_0x39c2e4[_0x35bd9d(0x19e)]('textarea')[_0x35bd9d(0x1c5)](_0x35bd9d(0x1c4),![])[_0x35bd9d(0x148)](_0x28802c),toastr[_0x35bd9d(0x17c)]('重新生成失败,已恢复原始内容。',_0x35bd9d(0x1b9)));},'onCancel':()=>{toastr['info']('本批次总结已取消。',_0x479a2e),_0x2c12d3(![]);}}):_0x2c12d3(![]);return;}const _0x495fb3=getRawMessagesForSummary(_0x155cea,_0x4df02e);if(!_0x495fb3||_0x495fb3[_0x99ad47(0x18b)]===0x0)return toastr[_0x99ad47(0x12b)](_0x99ad47(0x158),'圣谕有误'),_0x2c12d3(![]);const _0x245278=_0x32a73f=>{const _0x4afb74=_0x99ad47,_0x5a6af0=_0x32a73f[_0x4afb74(0x137)](_0x38bcf9=>_0x4afb74(0x156)+_0x38bcf9[_0x4afb74(0x1bc)]+'\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<summary>【第\x20'+_0x38bcf9['floor']+_0x4afb74(0x1ed)+_0x38bcf9[_0x4afb74(0x1a6)]+_0x4afb74(0x183)+_0x38bcf9[_0x4afb74(0x1a1)]+'\x22>'+_0x38bcf9[_0x4afb74(0x172)]+_0x4afb74(0x150))[_0x4afb74(0x133)]('');return _0x4afb74(0x180)+(_0x5b21fb['name1']||'用户')+_0x4afb74(0x14e)+(_0x5b21fb[_0x4afb74(0x153)]||'角色')+_0x4afb74(0x175)+_0x5a6af0+_0x4afb74(0x12e);},_0x5c0df3=_0x245278(_0x495fb3);showHtmlModal(_0x99ad47(0x1f3),_0x5c0df3,{'okText':_0x99ad47(0x14c),'cancelText':'取消','onOpen':_0x28c22f=>{const _0x1e7fd1=_0x99ad47,_0x2179dc=_0x28c22f[_0x1e7fd1(0x19e)](_0x1e7fd1(0x174)),_0x3c5c4c=_0x28c22f['find'](_0x1e7fd1(0x1de)),_0x1d9b77=_0x28c22f['find'](_0x1e7fd1(0x1ad)),_0x51b0ef=()=>{const _0x443049=_0x1e7fd1,_0x1b3d9f=_0x2179dc['is'](_0x443049(0x1ab)),_0x33b1da=_0x3c5c4c['is'](_0x443049(0x1ab));_0x1d9b77[_0x443049(0x19e)]('.historiography-message-item')['each'](function(){const _0x4e73ec=_0x443049,_0xff8823=$(this),_0x2ef940=_0xff8823[_0x4e73ec(0x1d9)](_0x4e73ec(0x1d5));_0x2ef940==='user'&&!_0x1b3d9f||_0x2ef940===_0x4e73ec(0x1aa)&&!_0x33b1da?_0xff8823[_0x4e73ec(0x1c5)](_0x4e73ec(0x1d0),!![]):_0xff8823['prop'](_0x4e73ec(0x1d0),![]);});};_0x2179dc['on'](_0x1e7fd1(0x128),_0x51b0ef),_0x3c5c4c['on'](_0x1e7fd1(0x128),_0x51b0ef);},'onOk':async _0x36d736=>{const _0x3b85c7=_0x99ad47,_0x22a968=_0x36d736['find']('.historiography-message-item:not([hidden])\x20textarea')[_0x3b85c7(0x137)](function(){const _0x45b669=_0x3b85c7,_0x3e3503=$(this)[_0x45b669(0x1d9)](_0x45b669(0x1a1)),_0xeeebb0=$(this)[_0x45b669(0x18a)](_0x45b669(0x1a0))[_0x45b669(0x19e)]('summary')[_0x45b669(0x1e6)]()['replace'](_0x45b669(0x1c8)+_0x3e3503+_0x45b669(0x1ed),'');return _0x45b669(0x1c8)+_0x3e3503+'\x20楼】\x20'+_0xeeebb0+':\x20'+$(this)[_0x45b669(0x148)]();})[_0x3b85c7(0x13d)]()[_0x3b85c7(0x133)]('\x0a');if(!_0x22a968[_0x3b85c7(0x15f)]()){toastr[_0x3b85c7(0x17c)](_0x3b85c7(0x191),_0x3b85c7(0x155));return;}const _0x5d2ddd=_0x36d736[0x0];_0x5d2ddd&&typeof _0x5d2ddd[_0x3b85c7(0x1e1)]===_0x3b85c7(0x1cd)&&_0x5d2ddd['close']();_0x36d736['remove']();const _0x5a3096=await getSummary(_0x22a968,_0x479a2e);_0x5a3096?showSummaryModal(_0x5a3096,{'onConfirm':async _0xac0647=>{const _0x2319e6=await writeSummary(_0xac0647,_0x155cea,_0x4df02e,_0x479a2e);_0x2c12d3(_0x2319e6);},'onRegenerate':async _0x26a2f9=>{const _0x1bb76f=_0x3b85c7;_0x26a2f9['find'](_0x1bb76f(0x1c3))[_0x1bb76f(0x1c5)]('disabled',!![])[_0x1bb76f(0x148)](_0x1bb76f(0x132));const _0x20d553=await getSummary(_0x22a968,_0x479a2e);_0x20d553?_0x26a2f9[_0x1bb76f(0x19e)](_0x1bb76f(0x1c3))[_0x1bb76f(0x1c5)](_0x1bb76f(0x1c4),![])[_0x1bb76f(0x148)](_0x20d553):(_0x26a2f9['find'](_0x1bb76f(0x1c3))['prop'](_0x1bb76f(0x1c4),![])[_0x1bb76f(0x148)](_0x5a3096),toastr['error'](_0x1bb76f(0x16b),_0x1bb76f(0x1b9)));},'onCancel':()=>{const _0x393483=_0x3b85c7;toastr[_0x393483(0x1b0)](_0x393483(0x176),_0x393483(0x15a)),_0x2c12d3(![]);}}):_0x2c12d3(![]);},'onCancel':()=>{const _0x25b556=_0x99ad47;toastr['info'](_0x25b556(0x1b4),_0x479a2e),_0x2c12d3(![]);}});});}function _0x4596(){const _0x1e77c3=['请将以下多个零散的\x22详细总结记录\x22提炼并融合成一段连贯的章节历史。原文如下\x0a\x0a','</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<style>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20#historiography-preview-controls\x20{\x20margin-bottom:\x2010px;\x20display:\x20flex;\x20gap:\x2015px;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20#historiography-preview-container\x20{\x20height:\x2065vh;\x20overflow-y:\x20auto;\x20border:\x201px\x20solid\x20#444;\x20padding:\x205px;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20.historiography-message-item\x20{\x20margin-bottom:\x205px;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20.historiography-message-item[hidden]\x20{\x20display:\x20none;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20.historiography-message-item\x20summary\x20{\x20cursor:\x20pointer;\x20padding:\x205px;\x20background-color:\x20#333;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20.historiography-editor-container\x20{\x20padding:\x2010px;\x20border:\x201px\x20solid\x20#444;\x20border-top:\x20none;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20.historiography-editor-container\x20textarea\x20{\x20height:\x20150px;\x20resize:\x20vertical;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</style>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20','模型未能返回有效的精炼内容。','loreInsertionPosition','world','正在重新生成,请稍候...','join','鸣金收兵','所选条目内容为空,无法入库。','[翰林院]\x20向量化处理失败:','map','large_summary','\x0a\x0a---\x0a\x0a【','137517BVPXQd','宏史卷重铸完毕','远征已在准备阶段遵令暂停!','get','[大史官]\x20','编年史已成功更新!','chat','\x0a</对话记录>','国史已是最新,远征军无需出动。','翰林院已成功接收旧“宏史卷”记忆!新增\x20','史册缺少【流水金印】,无法执行重铸。','楼的宏史卷】===\x0a\x0a','amily2_prompt_presets_v2_mixed_order','\x20条忆识\x0a\x0a','val','lorebookTarget','conditional','停战敕令已下达!远征军将在完成当前批次的任务后休整。','确认原文并总结','】送入翰林院...','</label>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<label><input\x20type=\x22checkbox\x22\x20id=\x22hist-include-char\x22\x20checked>\x20','\x20层历史分\x20','</textarea>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</details>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20','楼】已发生的剧情回顾。\x0a\x0a---\x0a\x0a','[大史官]\x20检阅《','name2','请严格根据以下\x22对话记录\x22中的内容进行总结不要添加任何额外信息。\x0a\x0a<对话记录>\x0a','圣谕有误','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<details\x20class=\x22historiography-message-item\x22\x20data-author-type=\x22','ceil','选定的楼层范围内无有效对话或内容被规则排除。','replace','操作已取消','[大史官-宏史卷向量化]\x20失败:','“写入史册”和“存入翰林院”均未启用,总结任务已完成但未保存。','lorebook','楼聊天记录总结已由翰林院向量化注入。)\x0a\x0a【以下内容为','trim','mes','远征开始','\x20批次战役准备中...\x20(','宏史卷重铸','史册已成功重铸,并保存于《','成功将以下内容送入翰林院,新增\x20','match','historiographySmallSummaryPrompt','以下是依照顺序已发生剧情','dispatchEvent','圣谕悉知','重新生成失败,已恢复原始内容。','14989776RJHlVq','success','远征军已在营中,无需下达停战敕令。','historiographyAutoSummaryInteractive','微言录\x20(自动)','远征军已在途中,无需重复下令。','content','未知错误','#hist-include-user','</label>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20id=\x22historiography-preview-container\x22>','本批次总结已取消。','loreDepth','\x0a\x0a【前','2315376spVCkw','is_user','条目入库失败:\x20','error','楼以后的总结内容】','远征因第\x20','正在召唤模型进行内容精炼...','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20id=\x22historiography-preview-controls\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<label><input\x20type=\x22checkbox\x22\x20id=\x22hist-include-user\x22\x20checked>\x20','type','\x20至\x20','</summary>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22historiography-editor-container\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<textarea\x20class=\x22text_pole\x22\x20data-floor=\x22','historiographyWriteToLorebook','loreKeywords','圣谕传达','找不到指定的史册条目。','翰林院','[大史官-调试]\x20构建并传递的选项:','closest','length','当前角色未绑定主世界书,远征军无法开拔!','圣谕不明','\x20条。','凯旋!远征大捷!所有未载之史均已化为帝国永恒的记忆!','amily2-expedition-state-change','请至少选择一条消息进行总结!','dedicated','filter',',将执行标准保存。','\x20批次征服','重铸史册时发生严重错误:\x20','historiographyTags','写入国史馆时发生错误:\x20','min','\x20-\x20国史馆','\x20楼的“宏史卷”内容送往翰林院...','amily2_vectorize_summary_content','historiographySmallJailbreakPrompt','find','[翰林院]\x20条目入库失败:','.historiography-message-item','floor','找不到指定的史册条目,重铸任务中止。','log','宏史卷总结:\x201-','count','author','user','split','246DjwtSt','char',':checked','[大史官-微言录]\x20AI回复的全部内容:','#historiography-preview-container','正在将此份“微言录”送往翰林院...','远征完毕','info','自动巡录:未找到符合条件的消息。','[大史官]\x20阅览《','翰林院入库','操作已取消。','character_main','正在将前\x20','extensions','远征途中遭遇重大挫折,任务中止!您可以随时【继续远征】。','模型召唤失败','国库无新事','送往翰林院的文书处理失败:\x20','authorType','711245IGbxRk','prompt','keyed','push','comment','[大史官]\x20自动微言录已触发处理\x20','textarea','disabled','prop','未知的史册写入指令。','以下内容是【1楼-','【第\x20','historiographyLargeRefinePrompt','44635QFnwyd','Amily2-Lore-','small_summary','function','遵旨!正在为您重铸《','遵旨!正在将《','hidden','微言录\x20(手动)','historiographyLargeJailbreakPrompt','正在为您熔铸对话历史...','远征失败','author-type','system','slice','楼总结已完成】否则后续总结无法进行。','data','historiographySmallTriggerThreshold','[大史官-远征失败]','【敕史局】对话流水总帐','745760EbFjay','#hist-include-char','characterId','loreActivationMode','close','[大史官]\x20加载混合顺序失败:','翰林院已成功接收并索引了新的记忆碎片!新增\x20','宏史卷重铸操作已取消。','getElementById','text','\x0a\x0a===【截止至第','AI你好以上内容为rag向量化后注入的相关剧情以下内容是已发生的剧情回顾。\x0a\x0a前','送往翰林院时发生未知错误。','checked','historiographyTagExtractionEnabled','parse','\x20楼】\x20','》中的条目【','disable','无标题条目','coreContent','historiographyIngestToRag','原文预览与编辑','写入国史馆失败:','\x0a\x0a---\x0a\x0a','远征战役\x20(','》中的【微言录合集】...','国史馆','2001408BlWnML','微言录总结:\x20','change','getItem','message','warning','entries'];_0x4596=function(){return _0x1e77c3;};return _0x4596();}function getRawMessagesForSummary(_0x25e34d,_0x21ec1e){const _0x1bd1d1=_0x5979b5,_0x419294=getContext(),_0x3fbaf5=_0x419294[_0x1bd1d1(0x140)],_0x209f93=extension_settings[extensionName],_0x4ffc7a=_0x3fbaf5[_0x1bd1d1(0x1d7)](_0x25e34d-0x1,_0x21ec1e);if(_0x4ffc7a[_0x1bd1d1(0x18b)]===0x0)return null;const _0x47d2a0=_0x419294['name1']||'用户',_0x312f90=_0x419294[_0x1bd1d1(0x153)]||'角色',_0x416d4c=_0x209f93[_0x1bd1d1(0x1eb)]??![],_0x5cc6df=_0x416d4c?(_0x209f93[_0x1bd1d1(0x197)]||'')['split'](',')['map'](_0xd73d26=>_0xd73d26[_0x1bd1d1(0x15f)]())['filter'](Boolean):[],_0x2cdf8f=_0x209f93['historiographyExclusionRules']||[],_0x2e0fd2=_0x4ffc7a[_0x1bd1d1(0x137)]((_0x4b35ae,_0x4111d6)=>{const _0x342435=_0x1bd1d1;let _0x42a6be=_0x4b35ae[_0x342435(0x160)];if(_0x416d4c&&_0x5cc6df[_0x342435(0x18b)]>0x0){const _0x168ba2=extractBlocksByTags(_0x42a6be,_0x5cc6df);_0x168ba2[_0x342435(0x18b)]>0x0&&(_0x42a6be=_0x168ba2[_0x342435(0x133)]('\x0a\x0a'));}_0x42a6be=applyExclusionRules(_0x42a6be,_0x2cdf8f);if(!_0x42a6be[_0x342435(0x15f)]())return null;return{'floor':_0x25e34d+_0x4111d6,'author':_0x4b35ae[_0x342435(0x17a)]?_0x47d2a0:_0x312f90,'authorType':_0x4b35ae['is_user']?_0x342435(0x1a7):_0x342435(0x1aa),'content':_0x42a6be[_0x342435(0x15f)]()};})[_0x1bd1d1(0x193)](Boolean);return _0x2e0fd2;}async function getSummary(_0x2c45a2,_0x4ace4d){const _0x251bf=_0x5979b5;toastr[_0x251bf(0x1b0)](_0x251bf(0x1d3),_0x4ace4d);const _0x1ccafe=extension_settings[extensionName],_0x41b717=getPresetPrompts(_0x251bf(0x1cc));let _0x177c1f;try{const _0x23b98c=localStorage[_0x251bf(0x129)](_0x251bf(0x146));_0x23b98c&&(_0x177c1f=JSON[_0x251bf(0x1ec)](_0x23b98c));}catch(_0xa4700e){console[_0x251bf(0x17c)](_0x251bf(0x1e2),_0xa4700e);}const _0x2125f8=getMixedOrder(_0x251bf(0x1cc))||[],_0x37b1b2=[{'role':_0x251bf(0x1d6),'content':generateRandomSeed()}];let _0x20ea6c=0x0;for(const _0x35d397 of _0x2125f8){if(_0x35d397[_0x251bf(0x181)]===_0x251bf(0x1be))_0x41b717&&_0x41b717[_0x20ea6c]&&(_0x37b1b2[_0x251bf(0x1c0)](_0x41b717[_0x20ea6c]),_0x20ea6c++);else{if(_0x35d397[_0x251bf(0x181)]==='conditional')switch(_0x35d397['id']){case'jailbreakPrompt':_0x1ccafe[_0x251bf(0x19d)]&&_0x37b1b2['push']({'role':_0x251bf(0x1d6),'content':_0x1ccafe[_0x251bf(0x19d)]});break;case'summaryPrompt':_0x1ccafe[_0x251bf(0x167)]&&_0x37b1b2[_0x251bf(0x1c0)]({'role':_0x251bf(0x1d6),'content':_0x1ccafe[_0x251bf(0x167)]});break;case'coreContent':_0x37b1b2[_0x251bf(0x1c0)]({'role':_0x251bf(0x1a7),'content':_0x251bf(0x154)+_0x2c45a2+_0x251bf(0x141)});break;}}}const _0x5ed452=await callAI(_0x37b1b2);return console[_0x251bf(0x1a3)](_0x251bf(0x1ac),_0x5ed452),_0x5ed452;}async function writeSummary(_0xa572e5,_0x56a0ed,_0x5dc945,_0x5e60f2){const _0x2bde96=_0x5979b5,_0x26cd36=extension_settings[extensionName],_0x8616a2=getContext(),_0x576d16=_0x26cd36[_0x2bde96(0x184)]??!![],_0x4f94de=_0x26cd36[_0x2bde96(0x1f2)]??![];if(!_0x576d16&&!_0x4f94de)return toastr[_0x2bde96(0x12b)](_0x2bde96(0x15c),_0x5e60f2),!![];if(_0x4f94de)try{toastr[_0x2bde96(0x1b0)](_0x2bde96(0x1ae),_0x2bde96(0x188));const _0x1e90cd=await ingestTextToHanlinyuan(_0xa572e5,'lorebook',_0x2bde96(0x127)+_0x56a0ed+'-'+_0x5dc945+'楼');if(_0x1e90cd[_0x2bde96(0x16d)])toastr['success']('翰林院已成功接收记忆碎片!',_0x2bde96(0x188));else throw new Error(_0x1e90cd[_0x2bde96(0x17c)]);}catch(_0x362c72){console[_0x2bde96(0x17c)](_0x2bde96(0x136),_0x362c72),toastr[_0x2bde96(0x17c)](_0x2bde96(0x1bb)+_0x362c72['message'],_0x2bde96(0x188));}if(_0x576d16)try{let _0x48d38f;switch(_0x26cd36[_0x2bde96(0x149)]){case _0x2bde96(0x1b5):_0x48d38f=characters[_0x8616a2[_0x2bde96(0x1df)]]?.[_0x2bde96(0x1d9)]?.[_0x2bde96(0x1b7)]?.[_0x2bde96(0x131)];if(!_0x48d38f)throw new Error('当前角色未绑定主世界书。');break;case _0x2bde96(0x192):const _0x4e2e2c=await getChatIdentifier();_0x48d38f=_0x2bde96(0x1cb)+_0x4e2e2c;break;default:throw new Error(_0x2bde96(0x1c6));}const _0x5bdd12=_0x5eedfb=>{const _0x515730=_0x2bde96,_0x3fd517='\x0a\x0a本条勿动【前'+_0x5dc945+_0x515730(0x1d8),_0x54a9c9=_0x515730(0x139)+_0x56a0ed+'楼至'+_0x5dc945+'楼详细总结记录】\x0a'+_0xa572e5;if(_0x5eedfb){const _0x441f4f=_0x5eedfb[_0x515730(0x159)](PROGRESS_SEAL_REGEX,'')[_0x515730(0x15f)]();return _0x441f4f+_0x54a9c9+_0x3fd517;}else{const _0x1dca8a=_0x515730(0x168)+_0x54a9c9;return _0x1dca8a+_0x3fd517;}};console[_0x2bde96(0x1a3)]('[大史官-调试]\x20读取到的原始设置:',{'loreActivationMode':_0x26cd36[_0x2bde96(0x1e0)],'loreInsertionPosition':_0x26cd36[_0x2bde96(0x130)],'loreDepth':_0x26cd36[_0x2bde96(0x177)],'loreKeywords':_0x26cd36[_0x2bde96(0x185)]});const _0x146b8e={'keys':_0x26cd36[_0x2bde96(0x185)][_0x2bde96(0x1a8)](',')[_0x2bde96(0x137)](_0x1f437e=>_0x1f437e[_0x2bde96(0x15f)]())[_0x2bde96(0x193)](Boolean),'isConstant':_0x26cd36['loreActivationMode']!==_0x2bde96(0x1bf),'insertion_position':_0x26cd36[_0x2bde96(0x130)],'depth':_0x26cd36['loreDepth']};console[_0x2bde96(0x1a3)](_0x2bde96(0x189),_0x146b8e);const _0x1a3d35=await writeToLorebookWithTavernHelper(_0x48d38f,RUNNING_LOG_COMMENT,_0x5bdd12,_0x146b8e);if(_0x1a3d35)return toastr['success'](_0x2bde96(0x13f),_0x5e60f2+_0x2bde96(0x19a)),!![];else throw new Error('使用\x20TavernHelper\x20写入失败请检查控制台日志。');}catch(_0x108c2b){return console[_0x2bde96(0x17c)](_0x2bde96(0x13e)+_0x5e60f2+_0x2bde96(0x1f4),_0x108c2b),toastr[_0x2bde96(0x17c)](_0x2bde96(0x198)+_0x108c2b[_0x2bde96(0x12a)],_0x2bde96(0x1f8)),![];}return!![];}const CHAPTER_SEAL_REGEX=/【前(\d+)楼篇章编撰已完成】/;export async function executeRefinement(_0x55c437,_0x447683){const _0x10f79a=_0x5979b5;toastr[_0x10f79a(0x1b0)](_0x10f79a(0x1ce)+_0x55c437+_0x10f79a(0x1f7),_0x10f79a(0x163));try{const _0x509f00=await loadWorldInfo(_0x55c437),_0x32c80f=_0x509f00?.[_0x10f79a(0x12c)][_0x447683];if(!_0x32c80f){toastr[_0x10f79a(0x17c)](_0x10f79a(0x1a2),_0x10f79a(0x155));return;}const _0x77acf9=_0x32c80f[_0x10f79a(0x172)],_0x5c24b6=extension_settings[extensionName],_0x2c57de=_0x77acf9['match'](PROGRESS_SEAL_REGEX);if(!_0x2c57de){toastr[_0x10f79a(0x17c)](_0x10f79a(0x144),'结构异常');return;}const _0x3f24d4=_0x2c57de[0x0],_0x105758=parseInt(_0x2c57de[0x1],0xa),_0x41df46=_0x77acf9[_0x10f79a(0x166)](CHAPTER_SEAL_REGEX);let _0x53b66b='',_0x6dcc94='',_0x391359=0x0;if(_0x41df46){const _0x5c6125=_0x41df46[0x0];_0x391359=parseInt(_0x41df46[0x1],0xa);const _0x275117=_0x77acf9[_0x10f79a(0x1a8)](_0x5c6125);_0x53b66b=_0x275117[0x0][_0x10f79a(0x15f)](),_0x6dcc94=_0x275117[0x1][_0x10f79a(0x159)](PROGRESS_SEAL_REGEX,'')['trim']();}else _0x6dcc94=_0x77acf9[_0x10f79a(0x159)](PROGRESS_SEAL_REGEX,'')[_0x10f79a(0x15f)]();if(!_0x6dcc94[_0x10f79a(0x15f)]()){toastr[_0x10f79a(0x12b)]('史册条目中没有新的内容可供重铸。',_0x10f79a(0x1ba));return;}const _0x4ce713=getPresetPrompts(_0x10f79a(0x138));let _0x3e3b23;try{const _0x5248a3=localStorage[_0x10f79a(0x129)](_0x10f79a(0x146));_0x5248a3&&(_0x3e3b23=JSON[_0x10f79a(0x1ec)](_0x5248a3));}catch(_0x9bf0e1){console['error'](_0x10f79a(0x1e2),_0x9bf0e1);}const _0x2502f9=getMixedOrder(_0x10f79a(0x138))||[],_0xe65848=[{'role':_0x10f79a(0x1d6),'content':generateRandomSeed()}];let _0x3089a1=0x0;for(const _0xdcc943 of _0x2502f9){if(_0xdcc943[_0x10f79a(0x181)]==='prompt')_0x4ce713&&_0x4ce713[_0x3089a1]&&(_0xe65848[_0x10f79a(0x1c0)](_0x4ce713[_0x3089a1]),_0x3089a1++);else{if(_0xdcc943[_0x10f79a(0x181)]===_0x10f79a(0x14a))switch(_0xdcc943['id']){case'jailbreakPrompt':_0x5c24b6[_0x10f79a(0x1d2)]&&_0xe65848[_0x10f79a(0x1c0)]({'role':_0x10f79a(0x1d6),'content':_0x5c24b6[_0x10f79a(0x1d2)]});break;case'summaryPrompt':_0x5c24b6[_0x10f79a(0x1c9)]&&_0xe65848[_0x10f79a(0x1c0)]({'role':_0x10f79a(0x1d6),'content':_0x5c24b6[_0x10f79a(0x1c9)]});break;case _0x10f79a(0x1f1):_0xe65848['push']({'role':_0x10f79a(0x1a7),'content':_0x10f79a(0x12d)+_0x6dcc94});break;}}}const _0x3d91a3=async()=>{const _0x590b67=_0x10f79a;return toastr[_0x590b67(0x1b0)](_0x590b67(0x17f),_0x590b67(0x163)),await callAI(_0xe65848);},_0x3022b8=await _0x3d91a3();if(!_0x3022b8){toastr[_0x10f79a(0x17c)](_0x10f79a(0x12f),'宏史卷重铸失败');return;}const _0x1d1026=async _0x41eeac=>{showSummaryModal(_0x41eeac,{'onConfirm':async _0x7e55b1=>{const _0x1eae20=_0x3157;let _0x3cc76b;const _0x3d23f7=_0x1eae20(0x178)+_0x105758+'楼篇章编撰已完成】',_0x19e622=document[_0x1eae20(0x1e5)](_0x1eae20(0x19c))?.[_0x1eae20(0x1ea)]??![];if(_0x19e622&&_0x41df46)try{toastr[_0x1eae20(0x1b0)](_0x1eae20(0x1b6)+_0x391359+_0x1eae20(0x19b),_0x1eae20(0x188));const _0x532b25=await ingestTextToHanlinyuan(_0x53b66b,_0x1eae20(0x15d),_0x1eae20(0x1a4)+_0x391359+'楼');if(!_0x532b25[_0x1eae20(0x16d)])throw new Error(_0x532b25[_0x1eae20(0x17c)]||_0x1eae20(0x173));toastr[_0x1eae20(0x16d)](_0x1eae20(0x143)+_0x532b25['count']+_0x1eae20(0x18e),_0x1eae20(0x188));const _0x109b37=_0x1eae20(0x1e8)+_0x391359+_0x1eae20(0x15e)+_0x391359+_0x1eae20(0x17d);_0x3cc76b=_0x109b37+_0x1eae20(0x1f5)+_0x7e55b1+_0x3d23f7+'\x0a\x0a'+_0x3f24d4;}catch(_0x236606){console[_0x1eae20(0x17c)](_0x1eae20(0x15b),_0x236606),toastr[_0x1eae20(0x17c)]('宏史卷向量化失败:\x20'+_0x236606['message']+_0x1eae20(0x194),_0x1eae20(0x188));const _0x3d1f45=_0x1eae20(0x1e7)+_0x391359+_0x1eae20(0x145);_0x3cc76b=''+_0x53b66b+_0x3d1f45+_0x7e55b1+_0x3d23f7+'\x0a\x0a'+_0x3f24d4;}else{if(_0x41df46){const _0x20b263='\x0a\x0a===【截止至第'+_0x391359+_0x1eae20(0x145);_0x3cc76b=''+_0x53b66b+_0x20b263+_0x7e55b1+_0x3d23f7+'\x0a\x0a'+_0x3f24d4;}else{const _0x4f3809=_0x1eae20(0x1c7)+_0x105758+_0x1eae20(0x151);_0x3cc76b=''+_0x4f3809+_0x7e55b1+_0x3d23f7+'\x0a\x0a'+_0x3f24d4;}}_0x32c80f[_0x1eae20(0x172)]=_0x3cc76b,await saveWorldInfo(_0x55c437,_0x509f00,!![]),toastr[_0x1eae20(0x16d)](_0x1eae20(0x164)+_0x55c437+'》!',_0x1eae20(0x13b));},'onRegenerate':async _0xe4d616=>{const _0x37ac5d=_0x3157;_0xe4d616['find'](_0x37ac5d(0x1c3))[_0x37ac5d(0x1c5)](_0x37ac5d(0x1c4),!![])[_0x37ac5d(0x148)](_0x37ac5d(0x132));const _0x186028=await _0x3d91a3();_0x186028?_0xe4d616['find'](_0x37ac5d(0x1c3))[_0x37ac5d(0x1c5)](_0x37ac5d(0x1c4),![])[_0x37ac5d(0x148)](_0x186028):(_0xe4d616[_0x37ac5d(0x19e)](_0x37ac5d(0x1c3))[_0x37ac5d(0x1c5)](_0x37ac5d(0x1c4),![])['val'](_0x41eeac),toastr[_0x37ac5d(0x17c)](_0x37ac5d(0x16b),_0x37ac5d(0x1b9)));},'onCancel':()=>{const _0x56c257=_0x3157;toastr[_0x56c257(0x1b0)](_0x56c257(0x1e4),_0x56c257(0x15a));}});};await _0x1d1026(_0x3022b8);}catch(_0x5ba1a7){console[_0x10f79a(0x17c)]('[大史官]\x20重铸任务失败:',_0x5ba1a7),toastr['error'](_0x10f79a(0x196)+_0x5ba1a7[_0x10f79a(0x12a)],_0x10f79a(0x1f8));}}function _0x3157(_0x92bde7,_0x2da7d6){const _0x459658=_0x4596();return _0x3157=function(_0x3157b7,_0xfafa2b){_0x3157b7=_0x3157b7-0x127;let _0x34b069=_0x459658[_0x3157b7];return _0x34b069;},_0x3157(_0x92bde7,_0x2da7d6);}export async function executeExpedition(){const _0x1fe9b1=_0x5979b5;if(isExpeditionRunning){toastr[_0x1fe9b1(0x1b0)](_0x1fe9b1(0x171),'圣谕悉知');return;}isExpeditionRunning=!![],manualStopRequested=![],document['dispatchEvent'](new CustomEvent(_0x1fe9b1(0x190),{'detail':{'isRunning':!![]}}));try{const _0x1b3cb8=extension_settings[extensionName],_0x233c36=getContext();let _0x321d88=null;switch(_0x1b3cb8[_0x1fe9b1(0x149)]){case _0x1fe9b1(0x1b5):_0x321d88=characters[_0x233c36[_0x1fe9b1(0x1df)]]?.['data']?.[_0x1fe9b1(0x1b7)]?.[_0x1fe9b1(0x131)];if(!_0x321d88){toastr[_0x1fe9b1(0x17c)](_0x1fe9b1(0x18c),_0x1fe9b1(0x18d)),isExpeditionRunning=![],document['dispatchEvent'](new CustomEvent(_0x1fe9b1(0x190),{'detail':{'isRunning':![],'manualStop':![]}}));return;}break;case _0x1fe9b1(0x192):const _0x33ff8d=await getChatIdentifier();_0x321d88=_0x1fe9b1(0x1cb)+_0x33ff8d;break;default:toastr['error']('未知的史册写入目标,远征军无法开拔!',_0x1fe9b1(0x18d)),isExpeditionRunning=![],document[_0x1fe9b1(0x169)](new CustomEvent('amily2-expedition-state-change',{'detail':{'isRunning':![],'manualStop':![]}}));return;}const _0x2e979b=await readGoldenLedgerProgress(_0x321d88),_0x48ab54=_0x233c36['chat']['length'],_0x3f9e83=_0x48ab54-_0x2e979b;if(_0x3f9e83<=0x0){toastr[_0x1fe9b1(0x1b0)](_0x1fe9b1(0x142),'凯旋'),isExpeditionRunning=![],document[_0x1fe9b1(0x169)](new CustomEvent('amily2-expedition-state-change',{'detail':{'isRunning':![],'manualStop':![]}}));return;}const _0x40b0f2=_0x1b3cb8['historiographySmallTriggerThreshold'],_0xad9fec=Math[_0x1fe9b1(0x157)](_0x3f9e83/_0x40b0f2);toastr[_0x1fe9b1(0x1b0)]('远征军已开拔!目标:'+_0x3f9e83+_0x1fe9b1(0x14f)+_0xad9fec+_0x1fe9b1(0x195),_0x1fe9b1(0x161));let _0x32ce09=_0x2e979b;for(let _0x4b9b0e=0x0;_0x4b9b0e<_0xad9fec;_0x4b9b0e++){if(manualStopRequested){toastr[_0x1fe9b1(0x12b)]('远征已遵从您的敕令暂停!随时可以【继续远征】。',_0x1fe9b1(0x134));break;}const _0x33205a=_0x32ce09+0x1,_0x389def=Math[_0x1fe9b1(0x199)](_0x32ce09+_0x40b0f2,_0x48ab54),_0x5c8da2=_0x1fe9b1(0x1f6)+(_0x4b9b0e+0x1)+'/'+_0xad9fec+')',_0x3bc32b=0x7d0;_0x4b9b0e>0x0&&(toastr[_0x1fe9b1(0x1b0)]('第\x20'+(_0x4b9b0e+0x1)+_0x1fe9b1(0x162)+_0x3bc32b/0x3e8+'秒后接敌)',_0x5c8da2),await new Promise(_0x2d0473=>setTimeout(_0x2d0473,_0x3bc32b)));if(manualStopRequested){toastr[_0x1fe9b1(0x12b)](_0x1fe9b1(0x13c),_0x1fe9b1(0x134));break;}const _0x4716b5=await executeManualSummary(_0x33205a,_0x389def,![]);if(_0x4716b5)_0x32ce09=_0x389def;else{toastr['warning'](_0x1fe9b1(0x17e)+(_0x4b9b0e+0x1)+'\x20批次任务失败而中止。','远征中止'),manualStopRequested=!![];break;}}!manualStopRequested&&toastr[_0x1fe9b1(0x16d)](_0x1fe9b1(0x18f),_0x1fe9b1(0x1af));}catch(_0x39d33b){console[_0x1fe9b1(0x17c)](_0x1fe9b1(0x1db),_0x39d33b),toastr['error'](_0x1fe9b1(0x1b8),_0x1fe9b1(0x1d4));}finally{isExpeditionRunning=![],document[_0x1fe9b1(0x169)](new CustomEvent(_0x1fe9b1(0x190),{'detail':{'isRunning':![],'manualStop':manualStopRequested}}));}}export function stopExpedition(){const _0x151b13=_0x5979b5;isExpeditionRunning?(manualStopRequested=!![],toastr['info'](_0x151b13(0x14b),_0x151b13(0x186))):toastr['warning'](_0x151b13(0x16e),_0x151b13(0x16a));}export async function executeCompilation(_0x23ed4b,_0xdc02d){const _0x2e8c1c=_0x5979b5;toastr[_0x2e8c1c(0x1b0)](_0x2e8c1c(0x1cf)+_0x23ed4b+_0x2e8c1c(0x1ee)+_0xdc02d+_0x2e8c1c(0x14d),_0x2e8c1c(0x1b3));try{const _0xeaddd9=await loadWorldInfo(_0x23ed4b),_0x19359c=_0xeaddd9?.['entries'][_0xdc02d];if(!_0x19359c)throw new Error(_0x2e8c1c(0x187));const _0x326e70=_0x19359c[_0x2e8c1c(0x172)];if(!_0x326e70[_0x2e8c1c(0x15f)]())throw new Error(_0x2e8c1c(0x135));const _0x4c2ddd=await ingestTextToHanlinyuan(_0x326e70,_0x2e8c1c(0x15d),_0x19359c[_0x2e8c1c(0x1c1)]||_0xdc02d);if(_0x4c2ddd['success'])return toastr[_0x2e8c1c(0x16d)](_0x2e8c1c(0x1e3)+_0x4c2ddd[_0x2e8c1c(0x1a5)]+_0x2e8c1c(0x18e),_0x2e8c1c(0x188)),{'success':!![],'content':_0x2e8c1c(0x165)+_0x4c2ddd['count']+_0x2e8c1c(0x147)+_0x326e70};else throw new Error(_0x4c2ddd[_0x2e8c1c(0x17c)]||_0x2e8c1c(0x1e9));}catch(_0x5e67b3){return console[_0x2e8c1c(0x17c)](_0x2e8c1c(0x19f),_0x5e67b3),toastr[_0x2e8c1c(0x17c)](_0x2e8c1c(0x17b)+_0x5e67b3[_0x2e8c1c(0x12a)],'翰林院'),{'success':![],'error':_0x5e67b3[_0x2e8c1c(0x12a)]};}}