mirror of
https://github.com/Wx-2025/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 23:15:50 +00:00
2 lines
31 KiB
JavaScript
2 lines
31 KiB
JavaScript
function _0x5922(_0x110b50,_0x226a83){const _0x2dd41f=_0x2dd4();return _0x5922=function(_0x59223d,_0x2ff3ff){_0x59223d=_0x59223d-0x159;let _0x15f01a=_0x2dd41f[_0x59223d];return _0x15f01a;},_0x5922(_0x110b50,_0x226a83);}(function(_0x3e8297,_0x2748e4){const _0x59f5cf=_0x5922,_0x44b3c7=_0x3e8297();while(!![]){try{const _0x51bcae=parseInt(_0x59f5cf(0x160))/0x1*(-parseInt(_0x59f5cf(0x1e0))/0x2)+parseInt(_0x59f5cf(0x209))/0x3+parseInt(_0x59f5cf(0x1fb))/0x4*(parseInt(_0x59f5cf(0x1a9))/0x5)+parseInt(_0x59f5cf(0x15f))/0x6*(parseInt(_0x59f5cf(0x1fc))/0x7)+parseInt(_0x59f5cf(0x1de))/0x8+-parseInt(_0x59f5cf(0x1a5))/0x9+parseInt(_0x59f5cf(0x15d))/0xa*(-parseInt(_0x59f5cf(0x226))/0xb);if(_0x51bcae===_0x2748e4)break;else _0x44b3c7['push'](_0x44b3c7['shift']());}catch(_0x2b2bbd){_0x44b3c7['push'](_0x44b3c7['shift']());}}}(_0x2dd4,0xf07f3));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';function _0x2dd4(){const _0x1865f0=['min','鸣金收兵','微言录\x20(自动)','[大史官]\x20加载混合顺序失败:','prop','2463744JEdQrM','圣谕悉知','[翰林院]\x20条目入库失败:','以下是依照顺序已发生剧情','authorType','操作已取消','[大史官]\x20','each','amily2-expedition-state-change','floor','[翰林院]\x20向量化处理失败:','warning','jailbreakPrompt','historiographyIngestToRag','</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','join','amily2_vectorize_summary_content','name2','翰林院','characterId','replace','翰林院已成功接收并索引了新的记忆碎片!新增\x20','\x20批次任务失败而中止。','宏史卷重铸操作已取消。','\x0a\x0a---\x0a\x0a','filter','使用\x20TavernHelper\x20写入失败,请检查控制台日志。','遵旨!正在为您重铸《','远征完毕','77rrMFTe','遵旨!正在将《','国史馆','.historiography-message-item','match','秒后接敌)','请严格根据以下\x22对话记录\x22中的内容进行总结,不要添加任何额外信息。\x0a\x0a<对话记录>\x0a','2768730DVkTjJ','info','6ACxnEb','1JwnQqM','loreKeywords','hidden','【第\x20','content','text','\x20楼的“宏史卷”内容送往翰林院...','getElementById','disable','Amily2-Lore-','slice','国库无新事','error','\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','type','\x20至\x20','正在重新生成,请稍候...','当前角色未绑定主世界书。','val','#hist-include-char','确认原文并总结','dispatchEvent','圣谕有误','user','parse','AI你好,以上内容为rag向量化后注入的相关剧情,以下内容是已发生的剧情回顾。\x0a\x0a(前','extensions','远征军已在营中,无需下达停战敕令。','国史已是最新,远征军无需出动。','以下内容是【1楼-','length','map','character_main','[大史官-调试]\x20读取到的原始设置:','\x20层历史,分\x20','\x20批次战役准备中...\x20(',',将执行标准保存。','圣谕不明','char','closest','找不到指定的史册条目。','未知的史册写入指令。','楼聊天记录总结已由翰林院向量化注入。)\x0a\x0a【以下内容为','编年史已成功更新!','function','[大史官]\x20重铸任务失败:','count','world','large_summary','宏史卷重铸失败','system','historiographyTags','comment','textarea','凯旋!远征大捷!所有未载之史均已化为帝国永恒的记忆!','</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>','微言录总结:\x20','停战敕令已下达!远征军将在完成当前批次的任务后休整。','is_user','disabled','</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','historiographySmallAutoEnable','change','dedicated','message','loreInsertionPosition','楼的宏史卷】===\x0a\x0a','get','宏史卷重铸完毕','1583064ZHgNYP','data','close','送往翰林院的文书处理失败:\x20','1375Uqwyxe','远征军已在途中,无需重复下令。','</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','success','翰林院已成功接收旧“宏史卷”记忆!新增\x20','\x20楼。','lorebookTarget','》中的条目【','远征途中遭遇重大挫折,任务中止!您可以随时【继续远征】。','本批次总结已取消。','\x20批次征服!','[大史官]\x20阅览《','原文预览与编辑','\x20-\x20国史馆','重新生成失败,已恢复原始内容。','conditional','史册缺少【流水金印】,无法执行重铸。','条目入库失败:\x20','ceil','historiographySmallTriggerThreshold','宏史卷总结:\x201-','请将以下多个零散的\x22详细总结记录\x22提炼并融合成一段连贯的章节历史。原文如下:\x0a\x0a','请至少选择一条消息进行总结!','checked','\x20楼】\x20','“写入史册”和“存入翰林院”均未启用,总结任务已完成但未保存。','宏史卷向量化失败:\x20','author','[大史官-微言录]\x20AI回复的全部内容:','small_summary','historiographySmallSummaryPrompt','远征因第\x20','找不到指定的史册条目,重铸任务中止。','keyed','historiographySmallJailbreakPrompt','chat','微言录\x20(手动)','\x20条。','自动巡录:未找到符合条件的消息。','[大史官-调试]\x20构建并传递的选项:','》时出错:','find','trim','split','prompt','楼总结已完成】否则后续总结无法进行。','</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',':checked','amily2_prompt_presets_v2_mixed_order','[大史官-宏史卷向量化]\x20失败:','写入国史馆失败:','\x0a</对话记录>','getItem','763160FRLOGZ','正在将前\x20','715466UATpzG','historiographyExclusionRules','正在为您熔铸对话历史...','coreContent','远征军已开拔!目标:','author-type','\x20条忆识:\x0a\x0a','loreActivationMode','楼详细总结记录】\x0a','模型未能返回有效的精炼内容。','楼以后的总结内容】','史册条目中没有新的内容可供重铸。','lorebook','entries','name1','[大史官-远征失败]','楼】已发生的剧情回顾。\x0a\x0a---\x0a\x0a','historiographyLargeJailbreakPrompt','\x0a\x0a本条勿动【前','push','log','index','操作已取消。','远征开始','\x0a\x0a---\x0a\x0a【','\x0a\x0a===【截止至第','模型召唤失败','9652KbtpmL','13136179dyZIZf','historiographyLargeRefinePrompt','成功将以下内容送入翰林院,新增\x20','送往翰林院时发生未知错误。','historiographyAutoSummaryInteractive','写入国史馆时发生错误:\x20','summary','#historiography-preview-container'];_0x2dd4=function(){return _0x1865f0;};return _0x2dd4();}import{getPresetPrompts,getMixedOrder}from'../PresetSettings/index.js';import{callAI,generateRandomSeed}from'./api.js';let isExpeditionRunning=![],manualStopRequested=![];const RUNNING_LOG_COMMENT='【敕史局】对话流水总帐',PROGRESS_SEAL_REGEX=/本条勿动【前(\d+)楼总结已完成】否则后续总结无法进行。$/;async function readGoldenLedgerProgress(_0x1978c3){const _0x5f6d54=_0x5922;if(!_0x1978c3)return 0x0;try{const _0x359046=await loadWorldInfo(_0x1978c3);if(!_0x359046||!_0x359046['entries'])return 0x0;const _0x3e6e7b=Object['values'](_0x359046[_0x5f6d54(0x1ed)])[_0x5f6d54(0x1d2)](_0x3fdbfc=>_0x3fdbfc[_0x5f6d54(0x194)]===RUNNING_LOG_COMMENT&&!_0x3fdbfc[_0x5f6d54(0x168)]);if(!_0x3e6e7b)return 0x0;const _0x2b0f18=_0x3e6e7b[_0x5f6d54(0x164)][_0x5f6d54(0x15a)](PROGRESS_SEAL_REGEX);return _0x2b0f18?parseInt(_0x2b0f18[0x1],0xa):0x0;}catch(_0x3b0133){return console[_0x5f6d54(0x16c)](_0x5f6d54(0x1b4)+_0x1978c3+'》天机时出错:',_0x3b0133),0x0;}}export async function checkAndTriggerAutoSummary(){const _0x4b50d6=_0x5922;if(isExpeditionRunning)return;const _0x215c69=extension_settings[extensionName];if(!_0x215c69[_0x4b50d6(0x19d)])return;const _0x26dc2e=getContext();let _0x2a2e4c=null;switch(_0x215c69[_0x4b50d6(0x1af)]){case _0x4b50d6(0x180):_0x2a2e4c=characters[_0x26dc2e[_0x4b50d6(0x21c)]]?.['data']?.[_0x4b50d6(0x17a)]?.[_0x4b50d6(0x18f)];break;case _0x4b50d6(0x19f):const _0x13d20c=await getChatIdentifier();_0x2a2e4c='Amily2-Lore-'+_0x13d20c;break;default:return;}if(!_0x2a2e4c)return;const _0x1a4790=await readGoldenLedgerProgress(_0x2a2e4c),_0xa10e59=_0x26dc2e['chat'][_0x4b50d6(0x17e)],_0x3e7139=_0xa10e59-_0x1a4790;if(_0x3e7139>=_0x215c69['historiographySmallTriggerThreshold']+0x2){const _0x3a50b8=_0x215c69[_0x4b50d6(0x1bc)],_0x34ad2a=_0x1a4790+0x1,_0x1d955d=Math[_0x4b50d6(0x204)](_0x1a4790+_0x3a50b8,_0xa10e59);console[_0x4b50d6(0x1f4)]('[大史官]\x20自动微言录已触发,处理\x20'+_0x34ad2a+_0x4b50d6(0x16f)+_0x1d955d+_0x4b50d6(0x1ae));const _0x5e3f7c=_0x215c69[_0x4b50d6(0x200)]??![];await executeManualSummary(_0x34ad2a,_0x1d955d,!_0x5e3f7c);}}export async function getAvailableWorldbooks(){return[...world_names];}export async function getLoresForWorldbook(_0x59bf86){const _0x1b66cf=_0x5922;if(!_0x59bf86)return[];try{const _0x5ec695=await loadWorldInfo(_0x59bf86);if(!_0x5ec695||!_0x5ec695[_0x1b66cf(0x1ed)])return[];return Object['entries'](_0x5ec695[_0x1b66cf(0x1ed)])[_0x1b66cf(0x222)](([,_0x4bfb4f])=>!_0x4bfb4f[_0x1b66cf(0x168)])['map'](([_0x38d1aa,_0x1cc419])=>({'key':_0x38d1aa,'comment':_0x1cc419[_0x1b66cf(0x194)]||'无标题条目'}));}catch(_0x447516){return console[_0x1b66cf(0x16c)]('[大史官]\x20检阅《'+_0x59bf86+_0x1b66cf(0x1d1),_0x447516),[];}}export async function executeManualSummary(_0x38a21a,_0x4add54,_0x47880f=![]){return new Promise(async _0x1b8ab1=>{const _0xc8941e=_0x5922,_0x4d97b2=_0x47880f?_0xc8941e(0x206):_0xc8941e(0x1cd),_0x3398e4=getContext();if(_0x47880f){const _0x5a106b=getRawMessagesForSummary(_0x38a21a,_0x4add54);if(!_0x5a106b||_0x5a106b['length']===0x0)return toastr[_0xc8941e(0x214)](_0xc8941e(0x1cf),_0x4d97b2),_0x1b8ab1(![]);const _0x33e0ab=_0x5a106b[_0xc8941e(0x17f)](_0x41fac0=>'【第\x20'+_0x41fac0[_0xc8941e(0x212)]+'\x20楼】\x20'+_0x41fac0[_0xc8941e(0x1c4)]+':\x20'+_0x41fac0[_0xc8941e(0x164)])[_0xc8941e(0x218)]('\x0a'),_0x42dbec=await getSummary(_0x33e0ab,_0x4d97b2);_0x42dbec?showSummaryModal(_0x42dbec,{'onConfirm':async _0x550f24=>{const _0x439270=await writeSummary(_0x550f24,_0x38a21a,_0x4add54,_0x4d97b2);_0x1b8ab1(_0x439270);},'onRegenerate':async _0x1ce3aa=>{const _0x28199b=_0xc8941e;_0x1ce3aa[_0x28199b(0x1d2)](_0x28199b(0x195))[_0x28199b(0x208)](_0x28199b(0x19b),!![])[_0x28199b(0x172)](_0x28199b(0x170));const _0x51d394=await getSummary(_0x33e0ab,_0x4d97b2);_0x51d394?_0x1ce3aa[_0x28199b(0x1d2)](_0x28199b(0x195))[_0x28199b(0x208)](_0x28199b(0x19b),![])['val'](_0x51d394):(_0x1ce3aa[_0x28199b(0x1d2)]('textarea')[_0x28199b(0x208)](_0x28199b(0x19b),![])[_0x28199b(0x172)](_0x42dbec),toastr[_0x28199b(0x16c)](_0x28199b(0x1b7),_0x28199b(0x1fa)));},'onCancel':()=>{const _0x3d418b=_0xc8941e;toastr['info'](_0x3d418b(0x1b2),_0x4d97b2),_0x1b8ab1(![]);}}):_0x1b8ab1(![]);return;}const _0x53062e=getRawMessagesForSummary(_0x38a21a,_0x4add54);if(!_0x53062e||_0x53062e[_0xc8941e(0x17e)]===0x0)return toastr['warning']('选定的楼层范围内无有效对话或内容被规则排除。',_0xc8941e(0x176)),_0x1b8ab1(![]);const _0xcf63f9=_0x5e862c=>{const _0x2626f0=_0xc8941e,_0x50e707=_0x5e862c[_0x2626f0(0x17f)](_0x1852da=>_0x2626f0(0x16d)+_0x1852da[_0x2626f0(0x20d)]+'\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<summary>【第\x20'+_0x1852da[_0x2626f0(0x212)]+_0x2626f0(0x1c1)+_0x1852da[_0x2626f0(0x1c4)]+_0x2626f0(0x1ab)+_0x1852da['floor']+'\x22>'+_0x1852da[_0x2626f0(0x164)]+_0x2626f0(0x19c))[_0x2626f0(0x218)]('');return'\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'+(_0x3398e4[_0x2626f0(0x1ee)]||'用户')+_0x2626f0(0x1d7)+(_0x3398e4[_0x2626f0(0x21a)]||'角色')+_0x2626f0(0x197)+_0x50e707+_0x2626f0(0x217);},_0x4a97ab=_0xcf63f9(_0x53062e);showHtmlModal(_0xc8941e(0x1b5),_0x4a97ab,{'okText':_0xc8941e(0x174),'cancelText':'取消','onOpen':_0x4588eb=>{const _0x412ad7=_0xc8941e,_0x189d76=_0x4588eb['find']('#hist-include-user'),_0x3ef36e=_0x4588eb['find'](_0x412ad7(0x173)),_0x5d09fb=_0x4588eb[_0x412ad7(0x1d2)](_0x412ad7(0x203)),_0x3d09c3=()=>{const _0x5202e3=_0x412ad7,_0x4c862c=_0x189d76['is'](_0x5202e3(0x1d8)),_0xf29add=_0x3ef36e['is'](':checked');_0x5d09fb['find']('.historiography-message-item')[_0x5202e3(0x210)](function(){const _0x1e8432=_0x5202e3,_0x497a57=$(this),_0x33e12d=_0x497a57['data'](_0x1e8432(0x1e5));_0x33e12d===_0x1e8432(0x177)&&!_0x4c862c||_0x33e12d===_0x1e8432(0x186)&&!_0xf29add?_0x497a57['prop']('hidden',!![]):_0x497a57[_0x1e8432(0x208)](_0x1e8432(0x162),![]);});};_0x189d76['on'](_0x412ad7(0x19e),_0x3d09c3),_0x3ef36e['on']('change',_0x3d09c3);},'onOk':async _0x2c215e=>{const _0x25e6e4=_0xc8941e,_0x4104f6=_0x2c215e[_0x25e6e4(0x1d2)]('.historiography-message-item:not([hidden])\x20textarea')[_0x25e6e4(0x17f)](function(){const _0x2761b1=_0x25e6e4,_0x59e61e=$(this)['data'](_0x2761b1(0x212)),_0x4d825e=$(this)[_0x2761b1(0x187)](_0x2761b1(0x159))[_0x2761b1(0x1d2)](_0x2761b1(0x202))[_0x2761b1(0x165)]()[_0x2761b1(0x21d)](_0x2761b1(0x163)+_0x59e61e+_0x2761b1(0x1c1),'');return _0x2761b1(0x163)+_0x59e61e+'\x20楼】\x20'+_0x4d825e+':\x20'+$(this)[_0x2761b1(0x172)]();})[_0x25e6e4(0x1a3)]()['join']('\x0a');if(!_0x4104f6['trim']()){toastr['error'](_0x25e6e4(0x1bf),'圣谕有误');return;}const _0x5084cd=_0x2c215e[0x0];_0x5084cd&&typeof _0x5084cd[_0x25e6e4(0x1a7)]===_0x25e6e4(0x18c)&&_0x5084cd['close']();_0x2c215e['remove']();const _0x915abb=await getSummary(_0x4104f6,_0x4d97b2);_0x915abb?showSummaryModal(_0x915abb,{'onConfirm':async _0x1f6d0b=>{const _0x2822b5=await writeSummary(_0x1f6d0b,_0x38a21a,_0x4add54,_0x4d97b2);_0x1b8ab1(_0x2822b5);},'onRegenerate':async _0x219115=>{const _0x5e27b6=_0x25e6e4;_0x219115[_0x5e27b6(0x1d2)](_0x5e27b6(0x195))[_0x5e27b6(0x208)](_0x5e27b6(0x19b),!![])[_0x5e27b6(0x172)](_0x5e27b6(0x170));const _0x35c6e8=await getSummary(_0x4104f6,_0x4d97b2);_0x35c6e8?_0x219115['find']('textarea')[_0x5e27b6(0x208)](_0x5e27b6(0x19b),![])[_0x5e27b6(0x172)](_0x35c6e8):(_0x219115['find'](_0x5e27b6(0x195))[_0x5e27b6(0x208)](_0x5e27b6(0x19b),![])[_0x5e27b6(0x172)](_0x915abb),toastr[_0x5e27b6(0x16c)](_0x5e27b6(0x1b7),_0x5e27b6(0x1fa)));},'onCancel':()=>{const _0x345cd7=_0x25e6e4;toastr['info']('本批次总结已取消。',_0x345cd7(0x20e)),_0x1b8ab1(![]);}}):_0x1b8ab1(![]);},'onCancel':()=>{const _0x9c4abd=_0xc8941e;toastr[_0x9c4abd(0x15e)](_0x9c4abd(0x1f6),_0x4d97b2),_0x1b8ab1(![]);}});});}function getRawMessagesForSummary(_0x556156,_0xb8016b){const _0x272605=_0x5922,_0x15f054=getContext(),_0x1439f2=_0x15f054[_0x272605(0x1cc)],_0x1aa33d=extension_settings[extensionName],_0x2a8b21=_0x1439f2[_0x272605(0x16a)](_0x556156-0x1,_0xb8016b);if(_0x2a8b21[_0x272605(0x17e)]===0x0)return null;const _0x39c233=_0x15f054[_0x272605(0x1ee)]||'用户',_0x578efe=_0x15f054['name2']||'角色',_0xfc6082=_0x1aa33d['historiographyTagExtractionEnabled']??![],_0x1e017d=_0xfc6082?(_0x1aa33d[_0x272605(0x193)]||'')[_0x272605(0x1d4)](',')[_0x272605(0x17f)](_0x184db5=>_0x184db5[_0x272605(0x1d3)]())[_0x272605(0x222)](Boolean):[],_0x21f043=_0x1aa33d[_0x272605(0x1e1)]||[],_0xf79331=_0x2a8b21[_0x272605(0x17f)]((_0x368ae3,_0x39d659)=>{const _0x3a375d=_0x272605;let _0x5cceeb=_0x368ae3['mes'];if(_0xfc6082&&_0x1e017d[_0x3a375d(0x17e)]>0x0){const _0x1d04f4=extractBlocksByTags(_0x5cceeb,_0x1e017d);_0x1d04f4[_0x3a375d(0x17e)]>0x0&&(_0x5cceeb=_0x1d04f4[_0x3a375d(0x218)]('\x0a\x0a'));}_0x5cceeb=applyExclusionRules(_0x5cceeb,_0x21f043);if(!_0x5cceeb[_0x3a375d(0x1d3)]())return null;return{'floor':_0x556156+_0x39d659,'author':_0x368ae3[_0x3a375d(0x19a)]?_0x39c233:_0x578efe,'authorType':_0x368ae3[_0x3a375d(0x19a)]?_0x3a375d(0x177):'char','content':_0x5cceeb['trim']()};})[_0x272605(0x222)](Boolean);return _0xf79331;}async function getSummary(_0x32cacb,_0x281f80){const _0x30ba13=_0x5922;toastr[_0x30ba13(0x15e)](_0x30ba13(0x1e2),_0x281f80);const _0x384e7b=extension_settings[extensionName],_0x5a8aa0=getPresetPrompts(_0x30ba13(0x1c6));let _0x5dfc24;try{const _0x24cec7=localStorage[_0x30ba13(0x1dd)](_0x30ba13(0x1d9));_0x24cec7&&(_0x5dfc24=JSON[_0x30ba13(0x178)](_0x24cec7));}catch(_0x502a96){console['error'](_0x30ba13(0x207),_0x502a96);}const _0x48485e=getMixedOrder(_0x30ba13(0x1c6))||[],_0x30b213=[{'role':_0x30ba13(0x192),'content':generateRandomSeed()}];for(const _0x30f5ed of _0x48485e){if(_0x30f5ed[_0x30ba13(0x16e)]===_0x30ba13(0x1d5))_0x5a8aa0&&_0x5a8aa0[_0x30f5ed[_0x30ba13(0x1f5)]]&&_0x30b213[_0x30ba13(0x1f3)](_0x5a8aa0[_0x30f5ed['index']]);else{if(_0x30f5ed[_0x30ba13(0x16e)]===_0x30ba13(0x1b8))switch(_0x30f5ed['id']){case'jailbreakPrompt':_0x384e7b[_0x30ba13(0x1cb)]&&_0x30b213[_0x30ba13(0x1f3)]({'role':_0x30ba13(0x192),'content':_0x384e7b[_0x30ba13(0x1cb)]});break;case'summaryPrompt':_0x384e7b[_0x30ba13(0x1c7)]&&_0x30b213[_0x30ba13(0x1f3)]({'role':_0x30ba13(0x192),'content':_0x384e7b[_0x30ba13(0x1c7)]});break;case'coreContent':_0x30b213['push']({'role':_0x30ba13(0x177),'content':_0x30ba13(0x15c)+_0x32cacb+_0x30ba13(0x1dc)});break;}}}const _0x17386e=await callAI(_0x30b213);return console[_0x30ba13(0x1f4)](_0x30ba13(0x1c5),_0x17386e),_0x17386e;}async function writeSummary(_0x4be722,_0x18a862,_0x39827f,_0x1d6df6){const _0x4b3fd7=_0x5922,_0x197833=extension_settings[extensionName],_0x37e764=getContext(),_0x1f8458=_0x197833['historiographyWriteToLorebook']??!![],_0x3e6de1=_0x197833[_0x4b3fd7(0x216)]??![];if(!_0x1f8458&&!_0x3e6de1)return toastr['warning'](_0x4b3fd7(0x1c2),_0x1d6df6),!![];if(_0x3e6de1)try{toastr[_0x4b3fd7(0x15e)]('正在将此份“微言录”送往翰林院...','翰林院');const _0x322a20=await ingestTextToHanlinyuan(_0x4be722,_0x4b3fd7(0x1ec),_0x4b3fd7(0x198)+_0x18a862+'-'+_0x39827f+'楼');if(_0x322a20[_0x4b3fd7(0x1ac)])toastr['success']('翰林院已成功接收记忆碎片!',_0x4b3fd7(0x21b));else throw new Error(_0x322a20[_0x4b3fd7(0x16c)]);}catch(_0x145c6a){console['error'](_0x4b3fd7(0x213),_0x145c6a),toastr[_0x4b3fd7(0x16c)](_0x4b3fd7(0x1a8)+_0x145c6a[_0x4b3fd7(0x1a0)],_0x4b3fd7(0x21b));}if(_0x1f8458)try{let _0x5e1dba;switch(_0x197833[_0x4b3fd7(0x1af)]){case _0x4b3fd7(0x180):_0x5e1dba=characters[_0x37e764[_0x4b3fd7(0x21c)]]?.['data']?.[_0x4b3fd7(0x17a)]?.['world'];if(!_0x5e1dba)throw new Error(_0x4b3fd7(0x171));break;case _0x4b3fd7(0x19f):const _0x45aa1b=await getChatIdentifier();_0x5e1dba=_0x4b3fd7(0x169)+_0x45aa1b;break;default:throw new Error(_0x4b3fd7(0x189));}const _0x514c15=_0x46b2fe=>{const _0x18b911=_0x4b3fd7,_0x337fb0=_0x18b911(0x1f2)+_0x39827f+_0x18b911(0x1d6),_0x141ffc=_0x18b911(0x1f8)+_0x18a862+'楼至'+_0x39827f+_0x18b911(0x1e8)+_0x4be722;if(_0x46b2fe){const _0x27f531=_0x46b2fe[_0x18b911(0x21d)](PROGRESS_SEAL_REGEX,'')[_0x18b911(0x1d3)]();return _0x27f531+_0x141ffc+_0x337fb0;}else{const _0x46cf7b=_0x18b911(0x20c)+_0x141ffc;return _0x46cf7b+_0x337fb0;}};console['log'](_0x4b3fd7(0x181),{'loreActivationMode':_0x197833[_0x4b3fd7(0x1e7)],'loreInsertionPosition':_0x197833[_0x4b3fd7(0x1a1)],'loreDepth':_0x197833['loreDepth'],'loreKeywords':_0x197833[_0x4b3fd7(0x161)]});const _0x498c59={'keys':_0x197833[_0x4b3fd7(0x161)][_0x4b3fd7(0x1d4)](',')['map'](_0x47165a=>_0x47165a[_0x4b3fd7(0x1d3)]())[_0x4b3fd7(0x222)](Boolean),'isConstant':_0x197833[_0x4b3fd7(0x1e7)]!==_0x4b3fd7(0x1ca),'insertion_position':_0x197833[_0x4b3fd7(0x1a1)],'depth':_0x197833['loreDepth']};console['log'](_0x4b3fd7(0x1d0),_0x498c59);const _0x2134be=await writeToLorebookWithTavernHelper(_0x5e1dba,RUNNING_LOG_COMMENT,_0x514c15,_0x498c59);if(_0x2134be)return toastr[_0x4b3fd7(0x1ac)](_0x4b3fd7(0x18b),_0x1d6df6+_0x4b3fd7(0x1b6)),!![];else throw new Error(_0x4b3fd7(0x223));}catch(_0x2ec3a2){return console[_0x4b3fd7(0x16c)](_0x4b3fd7(0x20f)+_0x1d6df6+_0x4b3fd7(0x1db),_0x2ec3a2),toastr[_0x4b3fd7(0x16c)](_0x4b3fd7(0x201)+_0x2ec3a2[_0x4b3fd7(0x1a0)],_0x4b3fd7(0x228)),![];}return!![];}const CHAPTER_SEAL_REGEX=/【前(\d+)楼篇章编撰已完成】/;export async function executeRefinement(_0x3eac48,_0x4c441c){const _0x5be414=_0x5922;toastr['info'](_0x5be414(0x224)+_0x3eac48+'》中的【微言录合集】...','宏史卷重铸');try{const _0x2f5340=await loadWorldInfo(_0x3eac48),_0x376300=_0x2f5340?.[_0x5be414(0x1ed)][_0x4c441c];if(!_0x376300){toastr[_0x5be414(0x16c)](_0x5be414(0x1c9),_0x5be414(0x176));return;}const _0x52a500=_0x376300[_0x5be414(0x164)],_0x21b4cb=extension_settings[extensionName],_0x40ffe1=_0x52a500['match'](PROGRESS_SEAL_REGEX);if(!_0x40ffe1){toastr[_0x5be414(0x16c)](_0x5be414(0x1b9),'结构异常');return;}const _0x4bd6a6=_0x40ffe1[0x0],_0x5cc694=parseInt(_0x40ffe1[0x1],0xa),_0x2772e2=_0x52a500[_0x5be414(0x15a)](CHAPTER_SEAL_REGEX);let _0xfe4560='',_0x7d7b61='',_0x1595ee=0x0;if(_0x2772e2){const _0x3be7a0=_0x2772e2[0x0];_0x1595ee=parseInt(_0x2772e2[0x1],0xa);const _0x2dbbc7=_0x52a500[_0x5be414(0x1d4)](_0x3be7a0);_0xfe4560=_0x2dbbc7[0x0][_0x5be414(0x1d3)](),_0x7d7b61=_0x2dbbc7[0x1][_0x5be414(0x21d)](PROGRESS_SEAL_REGEX,'')['trim']();}else _0x7d7b61=_0x52a500[_0x5be414(0x21d)](PROGRESS_SEAL_REGEX,'')[_0x5be414(0x1d3)]();if(!_0x7d7b61[_0x5be414(0x1d3)]()){toastr[_0x5be414(0x214)](_0x5be414(0x1eb),_0x5be414(0x16b));return;}const _0x3bead4=getPresetPrompts('large_summary');let _0x43546d;try{const _0x3bd531=localStorage[_0x5be414(0x1dd)](_0x5be414(0x1d9));_0x3bd531&&(_0x43546d=JSON['parse'](_0x3bd531));}catch(_0x4dd9ae){console[_0x5be414(0x16c)]('[大史官]\x20加载混合顺序失败:',_0x4dd9ae);}const _0xa425b8=getMixedOrder(_0x5be414(0x190))||[],_0x3a13ae=[{'role':_0x5be414(0x192),'content':generateRandomSeed()}];for(const _0x468522 of _0xa425b8){if(_0x468522['type']===_0x5be414(0x1d5))_0x3bead4&&_0x3bead4[_0x468522[_0x5be414(0x1f5)]]&&_0x3a13ae[_0x5be414(0x1f3)](_0x3bead4[_0x468522[_0x5be414(0x1f5)]]);else{if(_0x468522[_0x5be414(0x16e)]==='conditional')switch(_0x468522['id']){case _0x5be414(0x215):_0x21b4cb[_0x5be414(0x1f1)]&&_0x3a13ae['push']({'role':'system','content':_0x21b4cb[_0x5be414(0x1f1)]});break;case'summaryPrompt':_0x21b4cb['historiographyLargeRefinePrompt']&&_0x3a13ae[_0x5be414(0x1f3)]({'role':_0x5be414(0x192),'content':_0x21b4cb[_0x5be414(0x1fd)]});break;case _0x5be414(0x1e3):_0x3a13ae[_0x5be414(0x1f3)]({'role':_0x5be414(0x177),'content':_0x5be414(0x1be)+_0x7d7b61});break;}}}const _0x29fe82=async()=>{const _0x2b46f2=_0x5be414;return toastr[_0x2b46f2(0x15e)]('正在召唤模型进行内容精炼...','宏史卷重铸'),await callAI(_0x3a13ae);},_0x49e314=await _0x29fe82();if(!_0x49e314){toastr[_0x5be414(0x16c)](_0x5be414(0x1e9),_0x5be414(0x191));return;}const _0x404824=async _0x5a72d7=>{showSummaryModal(_0x5a72d7,{'onConfirm':async _0x44e919=>{const _0xab095=_0x5922;let _0x53a474;const _0x164419='\x0a\x0a【前'+_0x5cc694+'楼篇章编撰已完成】',_0x22a7c0=document[_0xab095(0x167)](_0xab095(0x219))?.[_0xab095(0x1c0)]??![];if(_0x22a7c0&&_0x2772e2)try{toastr[_0xab095(0x15e)](_0xab095(0x1df)+_0x1595ee+_0xab095(0x166),'翰林院');const _0x309f56=await ingestTextToHanlinyuan(_0xfe4560,_0xab095(0x1ec),_0xab095(0x1bd)+_0x1595ee+'楼');if(!_0x309f56[_0xab095(0x1ac)])throw new Error(_0x309f56[_0xab095(0x16c)]||'未知错误');toastr[_0xab095(0x1ac)](_0xab095(0x1ad)+_0x309f56[_0xab095(0x18e)]+_0xab095(0x1ce),_0xab095(0x21b));const _0x5d8a85=_0xab095(0x179)+_0x1595ee+_0xab095(0x18a)+_0x1595ee+_0xab095(0x1ea);_0x53a474=_0x5d8a85+_0xab095(0x221)+_0x44e919+_0x164419+'\x0a\x0a'+_0x4bd6a6;}catch(_0x40463b){console[_0xab095(0x16c)](_0xab095(0x1da),_0x40463b),toastr[_0xab095(0x16c)](_0xab095(0x1c3)+_0x40463b['message']+_0xab095(0x184),'翰林院');const _0x29890a=_0xab095(0x1f9)+_0x1595ee+'楼的宏史卷】===\x0a\x0a';_0x53a474=''+_0xfe4560+_0x29890a+_0x44e919+_0x164419+'\x0a\x0a'+_0x4bd6a6;}else{if(_0x2772e2){const _0x3f8a9a=_0xab095(0x1f9)+_0x1595ee+_0xab095(0x1a2);_0x53a474=''+_0xfe4560+_0x3f8a9a+_0x44e919+_0x164419+'\x0a\x0a'+_0x4bd6a6;}else{const _0x31e3c4=_0xab095(0x17d)+_0x5cc694+_0xab095(0x1f0);_0x53a474=''+_0x31e3c4+_0x44e919+_0x164419+'\x0a\x0a'+_0x4bd6a6;}}_0x376300['content']=_0x53a474,await saveWorldInfo(_0x3eac48,_0x2f5340,!![]),toastr[_0xab095(0x1ac)]('史册已成功重铸,并保存于《'+_0x3eac48+'》!',_0xab095(0x1a4));},'onRegenerate':async _0x4acd6f=>{const _0x42e506=_0x5922;_0x4acd6f[_0x42e506(0x1d2)](_0x42e506(0x195))[_0x42e506(0x208)](_0x42e506(0x19b),!![])[_0x42e506(0x172)](_0x42e506(0x170));const _0xeaa558=await _0x29fe82();_0xeaa558?_0x4acd6f[_0x42e506(0x1d2)](_0x42e506(0x195))[_0x42e506(0x208)]('disabled',![])[_0x42e506(0x172)](_0xeaa558):(_0x4acd6f[_0x42e506(0x1d2)]('textarea')[_0x42e506(0x208)](_0x42e506(0x19b),![])[_0x42e506(0x172)](_0x5a72d7),toastr[_0x42e506(0x16c)](_0x42e506(0x1b7),_0x42e506(0x1fa)));},'onCancel':()=>{const _0x369da9=_0x5922;toastr[_0x369da9(0x15e)](_0x369da9(0x220),_0x369da9(0x20e));}});};await _0x404824(_0x49e314);}catch(_0x305409){console['error'](_0x5be414(0x18d),_0x305409),toastr[_0x5be414(0x16c)]('重铸史册时发生严重错误:\x20'+_0x305409[_0x5be414(0x1a0)],'国史馆');}}export async function executeExpedition(){const _0x30f79c=_0x5922;if(isExpeditionRunning){toastr[_0x30f79c(0x15e)](_0x30f79c(0x1aa),_0x30f79c(0x20a));return;}isExpeditionRunning=!![],manualStopRequested=![],document[_0x30f79c(0x175)](new CustomEvent('amily2-expedition-state-change',{'detail':{'isRunning':!![]}}));try{const _0x37dde3=extension_settings[extensionName],_0x334810=getContext();let _0x3181da=null;switch(_0x37dde3[_0x30f79c(0x1af)]){case _0x30f79c(0x180):_0x3181da=characters[_0x334810['characterId']]?.[_0x30f79c(0x1a6)]?.[_0x30f79c(0x17a)]?.[_0x30f79c(0x18f)];if(!_0x3181da){toastr[_0x30f79c(0x16c)]('当前角色未绑定主世界书,远征军无法开拔!',_0x30f79c(0x185)),isExpeditionRunning=![],document[_0x30f79c(0x175)](new CustomEvent('amily2-expedition-state-change',{'detail':{'isRunning':![],'manualStop':![]}}));return;}break;case _0x30f79c(0x19f):const _0x49a2d8=await getChatIdentifier();_0x3181da=_0x30f79c(0x169)+_0x49a2d8;break;default:toastr['error']('未知的史册写入目标,远征军无法开拔!','圣谕不明'),isExpeditionRunning=![],document[_0x30f79c(0x175)](new CustomEvent(_0x30f79c(0x211),{'detail':{'isRunning':![],'manualStop':![]}}));return;}const _0x48673b=await readGoldenLedgerProgress(_0x3181da),_0x46e9eb=_0x334810[_0x30f79c(0x1cc)][_0x30f79c(0x17e)],_0x4a902a=_0x46e9eb-_0x48673b;if(_0x4a902a<=0x0){toastr[_0x30f79c(0x15e)](_0x30f79c(0x17c),'凯旋'),isExpeditionRunning=![],document[_0x30f79c(0x175)](new CustomEvent('amily2-expedition-state-change',{'detail':{'isRunning':![],'manualStop':![]}}));return;}const _0x1d4b1c=_0x37dde3['historiographySmallTriggerThreshold'],_0x429439=Math[_0x30f79c(0x1bb)](_0x4a902a/_0x1d4b1c);toastr[_0x30f79c(0x15e)](_0x30f79c(0x1e4)+_0x4a902a+_0x30f79c(0x182)+_0x429439+_0x30f79c(0x1b3),_0x30f79c(0x1f7));let _0x283d1d=_0x48673b;for(let _0x192599=0x0;_0x192599<_0x429439;_0x192599++){if(manualStopRequested){toastr['warning']('远征已遵从您的敕令暂停!随时可以【继续远征】。','鸣金收兵');break;}const _0x350739=_0x283d1d+0x1,_0x4a9184=Math[_0x30f79c(0x204)](_0x283d1d+_0x1d4b1c,_0x46e9eb),_0x8addae='远征战役\x20('+(_0x192599+0x1)+'/'+_0x429439+')',_0x27f4b1=0x7d0;_0x192599>0x0&&(toastr['info']('第\x20'+(_0x192599+0x1)+_0x30f79c(0x183)+_0x27f4b1/0x3e8+_0x30f79c(0x15b),_0x8addae),await new Promise(_0x44a19f=>setTimeout(_0x44a19f,_0x27f4b1)));if(manualStopRequested){toastr['warning']('远征已在准备阶段遵令暂停!',_0x30f79c(0x205));break;}const _0x5aa337=await executeManualSummary(_0x350739,_0x4a9184,![]);if(_0x5aa337)_0x283d1d=_0x4a9184;else{toastr[_0x30f79c(0x214)](_0x30f79c(0x1c8)+(_0x192599+0x1)+_0x30f79c(0x21f),'远征中止'),manualStopRequested=!![];break;}}!manualStopRequested&&toastr[_0x30f79c(0x1ac)](_0x30f79c(0x196),_0x30f79c(0x225));}catch(_0x584741){console[_0x30f79c(0x16c)](_0x30f79c(0x1ef),_0x584741),toastr[_0x30f79c(0x16c)](_0x30f79c(0x1b1),'远征失败');}finally{isExpeditionRunning=![],document[_0x30f79c(0x175)](new CustomEvent(_0x30f79c(0x211),{'detail':{'isRunning':![],'manualStop':manualStopRequested}}));}}export function stopExpedition(){const _0x1243f8=_0x5922;isExpeditionRunning?(manualStopRequested=!![],toastr['info'](_0x1243f8(0x199),'圣谕传达')):toastr[_0x1243f8(0x214)](_0x1243f8(0x17b),_0x1243f8(0x20a));}export async function executeCompilation(_0x4b9708,_0x216c3c){const _0x415655=_0x5922;toastr[_0x415655(0x15e)](_0x415655(0x227)+_0x4b9708+_0x415655(0x1b0)+_0x216c3c+'】送入翰林院...','翰林院入库');try{const _0x185eba=await loadWorldInfo(_0x4b9708),_0x2ffd83=_0x185eba?.[_0x415655(0x1ed)][_0x216c3c];if(!_0x2ffd83)throw new Error(_0x415655(0x188));const _0xeb1aab=_0x2ffd83[_0x415655(0x164)];if(!_0xeb1aab[_0x415655(0x1d3)]())throw new Error('所选条目内容为空,无法入库。');const _0x36a70b=await ingestTextToHanlinyuan(_0xeb1aab,_0x415655(0x1ec),_0x2ffd83[_0x415655(0x194)]||_0x216c3c);if(_0x36a70b[_0x415655(0x1ac)])return toastr[_0x415655(0x1ac)](_0x415655(0x21e)+_0x36a70b[_0x415655(0x18e)]+_0x415655(0x1ce),_0x415655(0x21b)),{'success':!![],'content':_0x415655(0x1fe)+_0x36a70b[_0x415655(0x18e)]+_0x415655(0x1e6)+_0xeb1aab};else throw new Error(_0x36a70b[_0x415655(0x16c)]||_0x415655(0x1ff));}catch(_0x32cf03){return console[_0x415655(0x16c)](_0x415655(0x20b),_0x32cf03),toastr[_0x415655(0x16c)](_0x415655(0x1ba)+_0x32cf03[_0x415655(0x1a0)],_0x415655(0x21b)),{'success':![],'error':_0x32cf03[_0x415655(0x1a0)]};}}
|