diff --git a/core/historiographer.js b/core/historiographer.js index 96f4563..ae7d319 100644 --- a/core/historiographer.js +++ b/core/historiographer.js @@ -1 +1 @@ -const _0x17f21b=_0x5497;function _0x44ce(){const _0x388ce3=['远征中止','historiographySmallTriggerThreshold','loreKeywords','historiographyLargeJailbreakPrompt','圣谕有误','historiographyExclusionRules','远征军已在营中,无需下达停战敕令。','579414VQWYkT','\x0a\x0a---\x0a\x0a','ceil','》天机时出错:','push','change','正在将此份“微言录”送往翰林院...','historiographySmallSummaryPrompt','\x20楼】\x20','map','disable','[大史官]\x20自动微言录已触发,处理\x20','\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20【第\x20','jailbreakPrompt','type','char','\x20条。','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20','dedicated','count','遵旨!正在为您重铸《','微言录\x20(手动)','user','】处理失败:\x20','当前角色未绑定主世界书,远征军无法开拔!','3013002nMHHaf','[大史官]\x20','写入国史馆时发生错误:\x20','.historiography-message-item','史册缺少【流水金印】,无法执行重铸。','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20','请严格根据以下\x22对话记录\x22中的内容进行总结,不要添加任何额外信息。\x0a\x0a<对话记录>\x0a','split','log','远征完毕','\x20楼。','warning','values','info','宏史卷重铸失败','请将以下多个零散的\x22详细总结记录\x22提炼并融合成一段连贯的章节历史。原文如下:\x0a\x0a','historiographySmallJailbreakPrompt','historiographyWriteToLorebook','】内容为空。','\x0a\x0a【前','prop',',将执行标准保存。','val','条目【','批量入库失败:\x20','735780OSlRpX','重铸史册时发生严重错误:\x20','圣谕不明','historiographyAutoSummaryInteractive','find','2870235wTlJOS','disabled','world','\x20批次战役准备中...\x20(','characterId','[大史官-调试]\x20读取到的原始设置:','\x20-\x20国史馆','match','请至少选择一条消息进行总结!','join','lorebook','楼详细总结记录】\x0a','远征已遵从您的敕令暂停!随时可以【继续远征】。','当前角色未绑定主世界书。','》时出错:','prompt','楼总结已完成】否则后续总结无法进行。','[大史官]\x20加载混合顺序失败:','模型召唤失败','hidden','微言录\x20(自动)','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20','选定的楼层范围内无有效对话或内容被规则排除。','远征军已在途中,无需重复下令。','确认原文并总结','name2','模型未能返回有效的精炼内容。','操作已取消','name1','远征开始','slice','replace','\x20批次任务失败而中止。','lorebookTarget','\x20个条目进行批量编纂...','4626783qiNPAJ','data','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20','small_summary','textarea','正在召唤模型进行内容精炼...','summaryPrompt','楼的宏史卷】===\x0a\x0a','重新生成失败,已恢复原始内容。',':checked','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\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'+_0x5cbb7e[_0x1fe511(0xd7)]+_0x1fe511(0x78))[_0x1fe511(0x14b)]('');return _0x1fe511(0xf9)+(_0x328e3d[_0x1fe511(0x7f)]||'用户')+_0x1fe511(0xff)+(_0x328e3d['name2']||'角色')+_0x1fe511(0x129)+_0x3c3029+_0x1fe511(0x11c);},_0x4cb65d=_0x1e6a52(_0x563ff1);showHtmlModal(_0x2cd50e(0xe1),_0x4cb65d,{'okText':_0x2cd50e(0x7b),'cancelText':'取消','onOpen':_0xa53028=>{const _0x51700a=_0x2cd50e,_0x545ab8=_0xa53028['find'](_0x51700a(0xd8)),_0x3d77c9=_0xa53028[_0x51700a(0x141)](_0x51700a(0x97)),_0x10877b=_0xa53028[_0x51700a(0x141)](_0x51700a(0xb0)),_0x5971ed=()=>{const _0x257c30=_0x51700a,_0x463517=_0x545ab8['is'](_0x257c30(0xf8)),_0x3c6e24=_0x3d77c9['is'](_0x257c30(0xf8));_0x10877b[_0x257c30(0x141)](_0x257c30(0x127))[_0x257c30(0x9a)](function(){const _0x140ae4=_0x257c30,_0x328163=$(this),_0x5a1685=_0x328163['data']('author-type');_0x5a1685==='user'&&!_0x463517||_0x5a1685==='char'&&!_0x3c6e24?_0x328163[_0x140ae4(0x138)](_0x140ae4(0x76),!![]):_0x328163['prop']('hidden',![]);});};_0x545ab8['on'](_0x51700a(0x110),_0x5971ed),_0x3d77c9['on'](_0x51700a(0x110),_0x5971ed);},'onOk':async _0x13144b=>{const _0x4b1869=_0x2cd50e,_0x1f23b6=_0x13144b['find']('.historiography-message-item:not([hidden])\x20textarea')[_0x4b1869(0x114)](function(){const _0x1cdf39=_0x4b1869,_0x1135cc=$(this)[_0x1cdf39(0x87)]('floor'),_0x194f25=$(this)['closest']('.historiography-message-item')[_0x1cdf39(0x141)]('summary')['text']()[_0x1cdf39(0x82)](_0x1cdf39(0xc6)+_0x1135cc+_0x1cdf39(0x113),'');return _0x1cdf39(0xc6)+_0x1135cc+_0x1cdf39(0x113)+_0x194f25+':\x20'+$(this)[_0x1cdf39(0x13a)]();})[_0x4b1869(0xb2)]()[_0x4b1869(0x14b)]('\x0a');if(!_0x1f23b6[_0x4b1869(0xdb)]()){toastr[_0x4b1869(0xe4)](_0x4b1869(0x14a),_0x4b1869(0x108));return;}const _0x3bc3fa=_0x13144b[0x0];_0x3bc3fa&&typeof _0x3bc3fa['close']===_0x4b1869(0x8b)&&_0x3bc3fa[_0x4b1869(0xfc)]();_0x13144b[_0x4b1869(0x95)]();const _0x43b487=await getSummary(_0x1f23b6,_0x3c6a6c);_0x43b487?showSummaryModal(_0x43b487,{'onConfirm':async _0x1a91f0=>{const _0x25ad84=await writeSummary(_0x1a91f0,_0x2e9b37,_0x251bcb,_0x3c6a6c);_0x22d588(_0x25ad84);},'onRegenerate':async _0xe35aef=>{const _0x45a025=_0x4b1869;_0xe35aef['find'](_0x45a025(0xf3))[_0x45a025(0x138)](_0x45a025(0x143),!![])[_0x45a025(0x13a)](_0x45a025(0x94));const _0x26fb2c=await getSummary(_0x1f23b6,_0x3c6a6c);_0x26fb2c?_0xe35aef['find'](_0x45a025(0xf3))[_0x45a025(0x138)](_0x45a025(0x143),![])[_0x45a025(0x13a)](_0x26fb2c):(_0xe35aef[_0x45a025(0x141)]('textarea')[_0x45a025(0x138)](_0x45a025(0x143),![])['val'](_0x43b487),toastr[_0x45a025(0xe4)](_0x45a025(0xf7),'模型召唤失败'));},'onCancel':()=>{const _0x2088a6=_0x4b1869;toastr[_0x2088a6(0x131)]('本批次总结已取消。',_0x2088a6(0x7e)),_0x22d588(![]);}}):_0x22d588(![]);},'onCancel':()=>{const _0x396783=_0x2cd50e;toastr[_0x396783(0x131)](_0x396783(0xa3),_0x3c6a6c),_0x22d588(![]);}});});}function getRawMessagesForSummary(_0x356346,_0x419acf){const _0x43ea6b=_0x17f21b,_0x3e8999=getContext(),_0x33b793=_0x3e8999[_0x43ea6b(0x9f)],_0x5a44f5=extension_settings[extensionName],_0xbb5a66=_0x33b793[_0x43ea6b(0x81)](_0x356346-0x1,_0x419acf);if(_0xbb5a66[_0x43ea6b(0xec)]===0x0)return null;const _0x139497=_0x3e8999[_0x43ea6b(0x7f)]||'用户',_0x3a9dc5=_0x3e8999[_0x43ea6b(0x7c)]||'角色',_0x5a7114=_0x5a44f5['historiographyTagExtractionEnabled']??![],_0x34dc6c=_0x5a7114?(_0x5a44f5[_0x43ea6b(0xac)]||'')['split'](',')['map'](_0x4367f6=>_0x4367f6[_0x43ea6b(0xdb)]())['filter'](Boolean):[],_0x427044=_0x5a44f5[_0x43ea6b(0x109)]||[],_0x35210f=_0xbb5a66[_0x43ea6b(0x114)]((_0x15fc19,_0x3f3c15)=>{const _0x20873a=_0x43ea6b;let _0x2fb2e6=_0x15fc19[_0x20873a(0xd3)];if(_0x5a7114&&_0x34dc6c['length']>0x0){const _0x54adeb=extractBlocksByTags(_0x2fb2e6,_0x34dc6c);_0x54adeb['length']>0x0&&(_0x2fb2e6=_0x54adeb[_0x20873a(0x14b)]('\x0a\x0a'));}_0x2fb2e6=applyExclusionRules(_0x2fb2e6,_0x427044);if(!_0x2fb2e6[_0x20873a(0xdb)]())return null;return{'floor':_0x356346+_0x3f3c15,'author':_0x15fc19[_0x20873a(0xfb)]?_0x139497:_0x3a9dc5,'authorType':_0x15fc19[_0x20873a(0xfb)]?_0x20873a(0x121):_0x20873a(0x11a),'content':_0x2fb2e6['trim']()};})['filter'](Boolean);return _0x35210f;}async function getSummary(_0xb2a0d6,_0x4a497e){const _0x4764fa=_0x17f21b;toastr[_0x4764fa(0x131)](_0x4764fa(0xc0),_0x4a497e);const _0x166983=extension_settings[extensionName],_0x4ff214=getPresetPrompts(_0x4764fa(0xf2));let _0x557c5a;try{const _0x1386e9=localStorage[_0x4764fa(0xdf)](_0x4764fa(0xd0));_0x1386e9&&(_0x557c5a=JSON[_0x4764fa(0xef)](_0x1386e9));}catch(_0x333830){console['error'](_0x4764fa(0x74),_0x333830);}const _0x31fdfe=getMixedOrder(_0x4764fa(0xf2))||[],_0x4aa6da=[{'role':'system','content':generateRandomSeed()}];let _0x344ca2=0x0;for(const _0x12c97c of _0x31fdfe){if(_0x12c97c['type']===_0x4764fa(0x72))_0x4ff214&&_0x4ff214[_0x344ca2]&&(_0x4aa6da[_0x4764fa(0x10f)](_0x4ff214[_0x344ca2]),_0x344ca2++);else{if(_0x12c97c[_0x4764fa(0x119)]===_0x4764fa(0xbd))switch(_0x12c97c['id']){case _0x4764fa(0x118):_0x166983[_0x4764fa(0x134)]&&_0x4aa6da[_0x4764fa(0x10f)]({'role':'system','content':_0x166983[_0x4764fa(0x134)]});break;case _0x4764fa(0xf5):_0x166983[_0x4764fa(0x112)]&&_0x4aa6da[_0x4764fa(0x10f)]({'role':_0x4764fa(0xbf),'content':_0x166983[_0x4764fa(0x112)]});break;case _0x4764fa(0xcc):_0x4aa6da['push']({'role':_0x4764fa(0x121),'content':_0x4764fa(0x12a)+_0xb2a0d6+_0x4764fa(0xf1)});break;}}}const _0x3bfe54=await callAI(_0x4aa6da);return console[_0x4764fa(0x12c)](_0x4764fa(0x102),_0x3bfe54),_0x3bfe54;}async function writeSummary(_0x3c19af,_0x32b9d0,_0x553963,_0x6382b5){const _0xdaf6c6=_0x17f21b,_0x2fbe14=extension_settings[extensionName],_0x150ace=getContext(),_0x518b89=_0x2fbe14[_0xdaf6c6(0x135)]??!![],_0x12c175=_0x2fbe14['historiographyIngestToRag']??![];if(!_0x518b89&&!_0x12c175)return toastr[_0xdaf6c6(0x12f)](_0xdaf6c6(0xca),_0x6382b5),!![];if(_0x12c175)try{let _0x17a293;switch(_0x2fbe14['lorebookTarget']){case'character_main':_0x17a293=characters[_0x150ace['characterId']]?.['data']?.['extensions']?.[_0xdaf6c6(0x144)];if(!_0x17a293)throw new Error(_0xdaf6c6(0xa4));break;case'dedicated':const _0x3a9c2a=await getChatIdentifier();_0x17a293=_0xdaf6c6(0xa6)+_0x3a9c2a;break;default:throw new Error('未知的史册写入指令,无法为翰林院确定目标。');}toastr[_0xdaf6c6(0x131)](_0xdaf6c6(0x111),_0xdaf6c6(0xd2));const _0xa4820={'bookName':_0x17a293,'entryName':'微言录总结:\x20'+_0x32b9d0+'-'+_0x553963+'楼'},_0x499b58=await ingestTextToHanlinyuan(_0x3c19af,_0xdaf6c6(0x14c),_0xa4820);if(_0x499b58[_0xdaf6c6(0xb8)])toastr[_0xdaf6c6(0xb8)](_0xdaf6c6(0xc3),_0xdaf6c6(0xd2));else throw new Error(_0x499b58['error']);}catch(_0x5d9760){console[_0xdaf6c6(0xe4)]('[翰林院]\x20向量化处理失败:',_0x5d9760),toastr[_0xdaf6c6(0xe4)](_0xdaf6c6(0xa5)+_0x5d9760['message'],_0xdaf6c6(0xd2));}if(_0x518b89)try{let _0x58854d;switch(_0x2fbe14[_0xdaf6c6(0x84)]){case _0xdaf6c6(0xaf):_0x58854d=characters[_0x150ace[_0xdaf6c6(0x146)]]?.['data']?.[_0xdaf6c6(0xbe)]?.['world'];if(!_0x58854d)throw new Error(_0xdaf6c6(0x70));break;case _0xdaf6c6(0x11d):const _0x526167=await getChatIdentifier();_0x58854d=_0xdaf6c6(0xa6)+_0x526167;break;default:throw new Error(_0xdaf6c6(0xe7));}const _0x42de19=_0x385c6a=>{const _0x20495b=_0xdaf6c6,_0x4f0ee7=_0x20495b(0x96)+_0x553963+_0x20495b(0x73),_0xa2e5c=_0x20495b(0xde)+_0x32b9d0+'楼至'+_0x553963+_0x20495b(0x14d)+_0x3c19af;if(_0x385c6a){const _0x591e17=_0x385c6a[_0x20495b(0x82)](PROGRESS_SEAL_REGEX,'')[_0x20495b(0xdb)]();return _0x591e17+_0xa2e5c+_0x4f0ee7;}else{const _0x10b0b8='以下是依照顺序已发生剧情'+_0xa2e5c;return _0x10b0b8+_0x4f0ee7;}};console['log'](_0xdaf6c6(0x147),{'loreActivationMode':_0x2fbe14[_0xdaf6c6(0xd6)],'loreInsertionPosition':_0x2fbe14[_0xdaf6c6(0xdc)],'loreDepth':_0x2fbe14['loreDepth'],'loreKeywords':_0x2fbe14['loreKeywords']});const _0x46a7d4={'keys':_0x2fbe14[_0xdaf6c6(0x106)][_0xdaf6c6(0x12b)](',')[_0xdaf6c6(0x114)](_0x503c3b=>_0x503c3b['trim']())[_0xdaf6c6(0xa2)](Boolean),'isConstant':_0x2fbe14[_0xdaf6c6(0xd6)]!==_0xdaf6c6(0xc5),'insertion_position':_0x2fbe14['loreInsertionPosition'],'depth':_0x2fbe14[_0xdaf6c6(0xab)]};console[_0xdaf6c6(0x12c)]('[大史官-调试]\x20构建并传递的选项:',_0x46a7d4);const _0x21c93d=await writeToLorebookWithTavernHelper(_0x58854d,RUNNING_LOG_COMMENT,_0x42de19,_0x46a7d4);if(_0x21c93d)return toastr['success'](_0xdaf6c6(0xa0),_0x6382b5+_0xdaf6c6(0x148)),!![];else throw new Error(_0xdaf6c6(0xa7));}catch(_0x1b70a3){return console['error'](_0xdaf6c6(0x125)+_0x6382b5+_0xdaf6c6(0x9e),_0x1b70a3),toastr['error'](_0xdaf6c6(0x126)+_0x1b70a3[_0xdaf6c6(0xb9)],_0xdaf6c6(0xe6)),![];}return!![];}const CHAPTER_SEAL_REGEX=/【前(\d+)楼篇章编撰已完成】/;export async function executeRefinement(_0x388d14,_0x22d27d){const _0x3395f4=_0x17f21b;toastr[_0x3395f4(0x131)](_0x3395f4(0x11f)+_0x388d14+_0x3395f4(0x91),_0x3395f4(0xc1));try{const _0x3f0ce3=await loadWorldInfo(_0x388d14),_0x270f66=_0x3f0ce3?.[_0x3395f4(0x103)][_0x22d27d];if(!_0x270f66){toastr['error'](_0x3395f4(0x8f),_0x3395f4(0x108));return;}const _0x5617ae=_0x270f66[_0x3395f4(0xd7)],_0x820d45=extension_settings[extensionName],_0x14a4ed=_0x5617ae[_0x3395f4(0x149)](PROGRESS_SEAL_REGEX);if(!_0x14a4ed){toastr[_0x3395f4(0xe4)](_0x3395f4(0x128),_0x3395f4(0xfa));return;}const _0xe62522=_0x14a4ed[0x0],_0x3c2380=parseInt(_0x14a4ed[0x1],0xa),_0xc0e403=_0x5617ae[_0x3395f4(0x149)](CHAPTER_SEAL_REGEX);let _0x188f3b='',_0x42a260='',_0x351ec5=0x0;if(_0xc0e403){const _0x2ee460=_0xc0e403[0x0];_0x351ec5=parseInt(_0xc0e403[0x1],0xa);const _0x376be9=_0x5617ae['split'](_0x2ee460);_0x188f3b=_0x376be9[0x0][_0x3395f4(0xdb)](),_0x42a260=_0x376be9[0x1][_0x3395f4(0x82)](PROGRESS_SEAL_REGEX,'')[_0x3395f4(0xdb)]();}else _0x42a260=_0x5617ae[_0x3395f4(0x82)](PROGRESS_SEAL_REGEX,'')[_0x3395f4(0xdb)]();if(!_0x42a260[_0x3395f4(0xdb)]()){toastr[_0x3395f4(0x12f)](_0x3395f4(0xcf),_0x3395f4(0x92));return;}const _0x1af5f8=getPresetPrompts(_0x3395f4(0xc2));let _0x2c3ab0;try{const _0xcd2c26=localStorage[_0x3395f4(0xdf)](_0x3395f4(0xd0));_0xcd2c26&&(_0x2c3ab0=JSON[_0x3395f4(0xef)](_0xcd2c26));}catch(_0x1135b8){console[_0x3395f4(0xe4)](_0x3395f4(0x74),_0x1135b8);}const _0x4e0fc0=getMixedOrder('large_summary')||[],_0x4e8082=[{'role':_0x3395f4(0xbf),'content':generateRandomSeed()}];let _0x18c831=0x0;for(const _0x49bd8d of _0x4e0fc0){if(_0x49bd8d['type']===_0x3395f4(0x72))_0x1af5f8&&_0x1af5f8[_0x18c831]&&(_0x4e8082[_0x3395f4(0x10f)](_0x1af5f8[_0x18c831]),_0x18c831++);else{if(_0x49bd8d[_0x3395f4(0x119)]===_0x3395f4(0xbd))switch(_0x49bd8d['id']){case _0x3395f4(0x118):_0x820d45[_0x3395f4(0x107)]&&_0x4e8082['push']({'role':_0x3395f4(0xbf),'content':_0x820d45[_0x3395f4(0x107)]});break;case _0x3395f4(0xf5):_0x820d45[_0x3395f4(0xa9)]&&_0x4e8082[_0x3395f4(0x10f)]({'role':_0x3395f4(0xbf),'content':_0x820d45[_0x3395f4(0xa9)]});break;case _0x3395f4(0xcc):_0x4e8082[_0x3395f4(0x10f)]({'role':'user','content':_0x3395f4(0x133)+_0x42a260});break;}}}const _0x51b2f8=async()=>{const _0x5d04a7=_0x3395f4;return toastr['info'](_0x5d04a7(0xf4),_0x5d04a7(0xc1)),await callAI(_0x4e8082);},_0x5b472d=await _0x51b2f8();if(!_0x5b472d){toastr[_0x3395f4(0xe4)](_0x3395f4(0x7d),_0x3395f4(0x132));return;}const _0x237ee1=async _0x4dcc0f=>{showSummaryModal(_0x4dcc0f,{'onConfirm':async _0x3c71dd=>{const _0x25b5c8=_0x5497;let _0x5ac52a;const _0x5e4ed8=_0x25b5c8(0x137)+_0x3c2380+_0x25b5c8(0xad),_0x5962f7=document['getElementById']('amily2_vectorize_summary_content')?.[_0x25b5c8(0xeb)]??![];if(_0x5962f7&&_0xc0e403)try{toastr[_0x25b5c8(0x131)]('正在将前\x20'+_0x351ec5+'\x20楼的“宏史卷”内容送往翰林院...','翰林院');const _0x58e2f7={'bookName':_0x388d14,'entryName':_0x25b5c8(0xb6)+_0x351ec5+'楼'},_0x54ac96=await ingestTextToHanlinyuan(_0x188f3b,_0x25b5c8(0x14c),_0x58e2f7);if(!_0x54ac96['success'])throw new Error(_0x54ac96[_0x25b5c8(0xe4)]||'未知错误');toastr['success']('翰林院已成功接收旧“宏史卷”记忆!新增\x20'+_0x54ac96[_0x25b5c8(0x11e)]+_0x25b5c8(0x11b),_0x25b5c8(0xd2));const _0x4b2202='AI你好,以上内容为rag向量化后注入的相关剧情,以下内容是已发生的剧情回顾。\x0a\x0a(前'+_0x351ec5+_0x25b5c8(0xf0)+_0x351ec5+_0x25b5c8(0xd9);_0x5ac52a=_0x4b2202+_0x25b5c8(0x10c)+_0x3c71dd+_0x5e4ed8+'\x0a\x0a'+_0xe62522;}catch(_0x18c2c6){console[_0x25b5c8(0xe4)](_0x25b5c8(0xc4),_0x18c2c6),toastr[_0x25b5c8(0xe4)](_0x25b5c8(0xb4)+_0x18c2c6['message']+_0x25b5c8(0x139),_0x25b5c8(0xd2));const _0x51df30=_0x25b5c8(0xea)+_0x351ec5+_0x25b5c8(0xf6);_0x5ac52a=''+_0x188f3b+_0x51df30+_0x3c71dd+_0x5e4ed8+'\x0a\x0a'+_0xe62522;}else{if(_0xc0e403){const _0x4d337d=_0x25b5c8(0xea)+_0x351ec5+'楼的宏史卷】===\x0a\x0a';_0x5ac52a=''+_0x188f3b+_0x4d337d+_0x3c71dd+_0x5e4ed8+'\x0a\x0a'+_0xe62522;}else{const _0x11b0be=_0x25b5c8(0x89)+_0x3c2380+_0x25b5c8(0xe0);_0x5ac52a=''+_0x11b0be+_0x3c71dd+_0x5e4ed8+'\x0a\x0a'+_0xe62522;}}_0x270f66['content']=_0x5ac52a,await saveWorldInfo(_0x388d14,_0x3f0ce3,!![]),toastr[_0x25b5c8(0xb8)](_0x25b5c8(0xc9)+_0x388d14+'》!','宏史卷重铸完毕');},'onRegenerate':async _0x247ee5=>{const _0x2a972e=_0x5497;_0x247ee5[_0x2a972e(0x141)](_0x2a972e(0xf3))['prop'](_0x2a972e(0x143),!![])['val'](_0x2a972e(0x94));const _0x2c3b59=await _0x51b2f8();_0x2c3b59?_0x247ee5[_0x2a972e(0x141)](_0x2a972e(0xf3))[_0x2a972e(0x138)](_0x2a972e(0x143),![])['val'](_0x2c3b59):(_0x247ee5[_0x2a972e(0x141)](_0x2a972e(0xf3))[_0x2a972e(0x138)](_0x2a972e(0x143),![])['val'](_0x4dcc0f),toastr[_0x2a972e(0xe4)]('重新生成失败,已恢复原始内容。',_0x2a972e(0x75)));},'onCancel':()=>{const _0x4f28cf=_0x5497;toastr[_0x4f28cf(0x131)](_0x4f28cf(0xb5),_0x4f28cf(0x7e));}});};await _0x237ee1(_0x5b472d);}catch(_0x4297cf){console[_0x3395f4(0xe4)]('[大史官]\x20重铸任务失败:',_0x4297cf),toastr[_0x3395f4(0xe4)](_0x3395f4(0x13e)+_0x4297cf[_0x3395f4(0xb9)],_0x3395f4(0xe6));}}export async function executeExpedition(){const _0x22c2c6=_0x17f21b;if(isExpeditionRunning){toastr['info'](_0x22c2c6(0x7a),_0x22c2c6(0xe5));return;}isExpeditionRunning=!![],manualStopRequested=![],document[_0x22c2c6(0xb1)](new CustomEvent(_0x22c2c6(0xa8),{'detail':{'isRunning':!![]}}));try{const _0x5eca56=extension_settings[extensionName],_0x5d4255=getContext();let _0x4652d5=null;switch(_0x5eca56[_0x22c2c6(0x84)]){case _0x22c2c6(0xaf):_0x4652d5=characters[_0x5d4255[_0x22c2c6(0x146)]]?.[_0x22c2c6(0x87)]?.[_0x22c2c6(0xbe)]?.[_0x22c2c6(0x144)];if(!_0x4652d5){toastr['error'](_0x22c2c6(0x123),_0x22c2c6(0x13f)),isExpeditionRunning=![],document['dispatchEvent'](new CustomEvent('amily2-expedition-state-change',{'detail':{'isRunning':![],'manualStop':![]}}));return;}break;case _0x22c2c6(0x11d):const _0xd31577=await getChatIdentifier();_0x4652d5=_0x22c2c6(0xa6)+_0xd31577;break;default:toastr[_0x22c2c6(0xe4)](_0x22c2c6(0xe9),_0x22c2c6(0x13f)),isExpeditionRunning=![],document[_0x22c2c6(0xb1)](new CustomEvent(_0x22c2c6(0xa8),{'detail':{'isRunning':![],'manualStop':![]}}));return;}const _0xa8cf4a=await readGoldenLedgerProgress(_0x4652d5),_0x53f673=_0x5d4255['chat'][_0x22c2c6(0xec)],_0x4938e3=_0x53f673-_0xa8cf4a;if(_0x4938e3<=0x0){toastr[_0x22c2c6(0x131)](_0x22c2c6(0xaa),'凯旋'),isExpeditionRunning=![],document[_0x22c2c6(0xb1)](new CustomEvent('amily2-expedition-state-change',{'detail':{'isRunning':![],'manualStop':![]}}));return;}const _0x2741f2=_0x5eca56[_0x22c2c6(0x105)],_0x216893=Math[_0x22c2c6(0x10d)](_0x4938e3/_0x2741f2);toastr[_0x22c2c6(0x131)](_0x22c2c6(0x8c)+_0x4938e3+'\x20层历史,分\x20'+_0x216893+_0x22c2c6(0x9c),_0x22c2c6(0x80));let _0x49dac1=_0xa8cf4a;for(let _0x12935d=0x0;_0x12935d<_0x216893;_0x12935d++){if(manualStopRequested){toastr[_0x22c2c6(0x12f)](_0x22c2c6(0x14e),'鸣金收兵');break;}const _0x4ebe22=_0x49dac1+0x1,_0x530da1=Math['min'](_0x49dac1+_0x2741f2,_0x53f673),_0x439e3e=_0x22c2c6(0x99)+(_0x12935d+0x1)+'/'+_0x216893+')',_0x18cdfb=0x7d0;_0x12935d>0x0&&(toastr['info']('第\x20'+(_0x12935d+0x1)+_0x22c2c6(0x145)+_0x18cdfb/0x3e8+_0x22c2c6(0xbb),_0x439e3e),await new Promise(_0x52fd92=>setTimeout(_0x52fd92,_0x18cdfb)));if(manualStopRequested){toastr[_0x22c2c6(0x12f)](_0x22c2c6(0x101),_0x22c2c6(0xa1));break;}const _0x3530d3=await executeManualSummary(_0x4ebe22,_0x530da1,![]);if(_0x3530d3)_0x49dac1=_0x530da1;else{toastr[_0x22c2c6(0x12f)]('远征因第\x20'+(_0x12935d+0x1)+_0x22c2c6(0x83),_0x22c2c6(0x104)),manualStopRequested=!![];break;}}!manualStopRequested&&toastr[_0x22c2c6(0xb8)]('凯旋!远征大捷!所有未载之史均已化为帝国永恒的记忆!',_0x22c2c6(0x12d));}catch(_0x12e994){console['error'](_0x22c2c6(0xe8),_0x12e994),toastr[_0x22c2c6(0xe4)]('远征途中遭遇重大挫折,任务中止!您可以随时【继续远征】。','远征失败');}finally{isExpeditionRunning=![],document[_0x22c2c6(0xb1)](new CustomEvent(_0x22c2c6(0xa8),{'detail':{'isRunning':![],'manualStop':manualStopRequested}}));}}export function stopExpedition(){const _0x19d478=_0x17f21b;isExpeditionRunning?(manualStopRequested=!![],toastr[_0x19d478(0x131)](_0x19d478(0xae),_0x19d478(0xce))):toastr['warning'](_0x19d478(0x10a),_0x19d478(0xe5));}export async function executeCompilation(_0x260242,_0x2f1a7e){const _0x35a1e6=_0x17f21b;if(!Array[_0x35a1e6(0xfe)](_0x2f1a7e)||_0x2f1a7e['length']===0x0)return toastr[_0x35a1e6(0x12f)]('未选择任何条目进行编纂。',_0x35a1e6(0x13f)),{'success':![],'error':_0x35a1e6(0x93)};toastr[_0x35a1e6(0x131)](_0x35a1e6(0xe2)+_0x260242+_0x35a1e6(0x100)+_0x2f1a7e[_0x35a1e6(0xec)]+_0x35a1e6(0x85),_0x35a1e6(0xd5));let _0x38e949=0x0,_0x1e48fa=0x0,_0x293c41=[];try{const _0x82628f=await loadWorldInfo(_0x260242);if(!_0x82628f||!_0x82628f[_0x35a1e6(0x103)])throw new Error('无法加载书库《'+_0x260242+_0x35a1e6(0xb7));for(const _0x468b3f of _0x2f1a7e){const _0x5b1537=_0x82628f[_0x35a1e6(0x103)][_0x468b3f];if(!_0x5b1537){_0x293c41[_0x35a1e6(0x10f)](_0x35a1e6(0x13b)+_0x468b3f+_0x35a1e6(0xc8));continue;}const _0x157edf=_0x5b1537['content'];if(!_0x157edf[_0x35a1e6(0xdb)]()){_0x293c41[_0x35a1e6(0x10f)](_0x35a1e6(0x13b)+(_0x5b1537[_0x35a1e6(0xcd)]||_0x468b3f)+_0x35a1e6(0x136));continue;}const _0x3c02a6={'bookName':_0x260242,'entryName':_0x5b1537['comment']||_0x468b3f};try{const _0x42bee5=await ingestTextToHanlinyuan(_0x157edf,'lorebook',_0x3c02a6);_0x42bee5[_0x35a1e6(0xb8)]?(_0x38e949++,_0x1e48fa+=_0x42bee5['count']):_0x293c41[_0x35a1e6(0x10f)]('条目【'+(_0x5b1537[_0x35a1e6(0xcd)]||_0x468b3f)+_0x35a1e6(0x122)+_0x42bee5[_0x35a1e6(0xe4)]);}catch(_0x1528ba){_0x293c41[_0x35a1e6(0x10f)](_0x35a1e6(0x13b)+(_0x5b1537[_0x35a1e6(0xcd)]||_0x468b3f)+'】处理时发生严重错误:\x20'+_0x1528ba[_0x35a1e6(0xb9)]);}}let _0x2b59f0=_0x35a1e6(0xe3)+_0x38e949+_0x35a1e6(0x90)+_0x2f1a7e['length']+'\x20个条目,共新增\x20'+_0x1e48fa+'\x20条忆识。';return _0x293c41['length']>0x0?(_0x2b59f0+=_0x35a1e6(0xb3)+_0x293c41[_0x35a1e6(0x14b)]('\x0a-\x20'),toastr[_0x35a1e6(0x12f)](_0x35a1e6(0x98),_0x35a1e6(0xd2)),console[_0x35a1e6(0xba)](_0x35a1e6(0xcb),_0x293c41)):toastr['success'](_0x35a1e6(0xfd)+_0x1e48fa+'\x20条忆识。',_0x35a1e6(0xd2)),{'success':_0x293c41[_0x35a1e6(0xec)]===0x0,'content':_0x2b59f0,'totalSuccess':_0x38e949,'totalVectors':_0x1e48fa,'errors':_0x293c41};}catch(_0x2220cf){return console[_0x35a1e6(0xe4)]('[翰林院]\x20批量条目入库失败:',_0x2220cf),toastr['error'](_0x35a1e6(0x13c)+_0x2220cf[_0x35a1e6(0xb9)],_0x35a1e6(0xd2)),{'success':![],'error':_0x2220cf[_0x35a1e6(0xb9)]};}} +const _0x326bc9=_0x469a;(function(_0x15b6ee,_0x3380b1){const _0x585271=_0x469a,_0x293750=_0x15b6ee();while(!![]){try{const _0x660d01=parseInt(_0x585271(0x1cf))/0x1*(-parseInt(_0x585271(0x1f3))/0x2)+parseInt(_0x585271(0x239))/0x3+-parseInt(_0x585271(0x25f))/0x4+-parseInt(_0x585271(0x189))/0x5*(-parseInt(_0x585271(0x1e6))/0x6)+-parseInt(_0x585271(0x223))/0x7+-parseInt(_0x585271(0x19c))/0x8*(-parseInt(_0x585271(0x1cb))/0x9)+parseInt(_0x585271(0x18f))/0xa;if(_0x660d01===_0x3380b1)break;else _0x293750['push'](_0x293750['shift']());}catch(_0x455181){_0x293750['push'](_0x293750['shift']());}}}(_0x2d7d,0xdd06e));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';import{callNgmsAI}from'./api/Ngms_api.js';function _0x469a(_0x8797f0,_0x22709d){const _0x2d7dc4=_0x2d7d();return _0x469a=function(_0x469af6,_0x192b96){_0x469af6=_0x469af6-0x182;let _0x2743f1=_0x2d7dc4[_0x469af6];return _0x2743f1;},_0x469a(_0x8797f0,_0x22709d);}let isExpeditionRunning=![],manualStopRequested=![];const RUNNING_LOG_COMMENT=_0x326bc9(0x1d8),PROGRESS_SEAL_REGEX=/本条勿动【前(\d+)楼总结已完成】否则后续总结无法进行。$/;async function readGoldenLedgerProgress(_0x717f0c){const _0x4447b2=_0x326bc9;if(!_0x717f0c)return 0x0;try{const _0x4d3d90=await loadWorldInfo(_0x717f0c);if(!_0x4d3d90||!_0x4d3d90[_0x4447b2(0x227)])return 0x0;const _0x3416b1=Object[_0x4447b2(0x248)](_0x4d3d90['entries'])[_0x4447b2(0x205)](_0x30ef3c=>_0x30ef3c[_0x4447b2(0x1e7)]===RUNNING_LOG_COMMENT&&!_0x30ef3c[_0x4447b2(0x1f6)]);if(!_0x3416b1)return 0x0;const _0x38ccce=_0x3416b1[_0x4447b2(0x1b5)][_0x4447b2(0x258)](PROGRESS_SEAL_REGEX);return _0x38ccce?parseInt(_0x38ccce[0x1],0xa):0x0;}catch(_0x2ea41f){return console[_0x4447b2(0x242)](_0x4447b2(0x254)+_0x717f0c+_0x4447b2(0x19a),_0x2ea41f),0x0;}}export async function checkAndTriggerAutoSummary(){const _0x5bfce9=_0x326bc9;if(isExpeditionRunning)return;const _0x4761d1=extension_settings[extensionName];if(!_0x4761d1[_0x5bfce9(0x1a6)])return;const _0x149b69=getContext();let _0xa2608=null;switch(_0x4761d1['lorebookTarget']){case _0x5bfce9(0x21e):_0xa2608=characters[_0x149b69[_0x5bfce9(0x184)]]?.['data']?.['extensions']?.[_0x5bfce9(0x1dc)];break;case _0x5bfce9(0x247):const _0x303d37=await getChatIdentifier();_0xa2608='Amily2-Lore-'+_0x303d37;break;default:return;}if(!_0xa2608)return;const _0x3bdef6=await readGoldenLedgerProgress(_0xa2608),_0x16a279=_0x149b69[_0x5bfce9(0x22c)][_0x5bfce9(0x1d4)],_0x87f61=_0x16a279-_0x3bdef6;if(_0x87f61>=_0x4761d1[_0x5bfce9(0x260)]+0x2){const _0x236b60=_0x4761d1[_0x5bfce9(0x260)],_0x901289=_0x3bdef6+0x1,_0x3e2f33=Math[_0x5bfce9(0x24b)](_0x3bdef6+_0x236b60,_0x16a279);console['log'](_0x5bfce9(0x1ed)+_0x901289+_0x5bfce9(0x1c8)+_0x3e2f33+'\x20楼。');const _0x3c3eee=_0x4761d1['historiographyAutoSummaryInteractive']??![];await executeManualSummary(_0x901289,_0x3e2f33,!_0x3c3eee);}}export async function getAvailableWorldbooks(){return[...world_names];}export async function getLoresForWorldbook(_0x710953){const _0x5426e7=_0x326bc9;if(!_0x710953)return[];try{const _0x2d4643=await loadWorldInfo(_0x710953);if(!_0x2d4643||!_0x2d4643[_0x5426e7(0x227)])return[];return Object[_0x5426e7(0x227)](_0x2d4643['entries'])['filter'](([,_0x38ae4f])=>!_0x38ae4f[_0x5426e7(0x1f6)])[_0x5426e7(0x234)](([_0x24a5bc,_0xc6aabc])=>({'key':_0x24a5bc,'comment':_0xc6aabc[_0x5426e7(0x1e7)]||_0x5426e7(0x251)}));}catch(_0x3ecea1){return console['error'](_0x5426e7(0x1d3)+_0x710953+_0x5426e7(0x23e),_0x3ecea1),[];}}export async function executeManualSummary(_0x4a2c27,_0x58ec0c,_0x495e3c=![]){return new Promise(async _0x589ea4=>{const _0x4220b4=_0x469a,_0x3539ae=_0x495e3c?_0x4220b4(0x22f):'微言录\x20(手动)',_0x39bd7e=getContext();if(_0x495e3c){const _0xc1bac2=getRawMessagesForSummary(_0x4a2c27,_0x58ec0c);if(!_0xc1bac2||_0xc1bac2[_0x4220b4(0x1d4)]===0x0)return toastr[_0x4220b4(0x232)]('自动巡录:未找到符合条件的消息。',_0x3539ae),_0x589ea4(![]);const _0x4471f1=_0xc1bac2[_0x4220b4(0x234)](_0x45a330=>_0x4220b4(0x1ea)+_0x45a330['floor']+_0x4220b4(0x1f4)+_0x45a330['author']+':\x20'+_0x45a330[_0x4220b4(0x1b5)])[_0x4220b4(0x219)]('\x0a'),_0x3fa78a=await getSummary(_0x4471f1,_0x3539ae);_0x3fa78a?showSummaryModal(_0x3fa78a,{'onConfirm':async _0x60c14f=>{const _0x2e12de=await writeSummary(_0x60c14f,_0x4a2c27,_0x58ec0c,_0x3539ae);_0x589ea4(_0x2e12de);},'onRegenerate':async _0xe4363a=>{const _0x5ade83=_0x4220b4;_0xe4363a[_0x5ade83(0x205)](_0x5ade83(0x24f))[_0x5ade83(0x20d)](_0x5ade83(0x1e0),!![])[_0x5ade83(0x1d9)](_0x5ade83(0x250));const _0x2a2712=await getSummary(_0x4471f1,_0x3539ae);_0x2a2712?_0xe4363a['find'](_0x5ade83(0x24f))[_0x5ade83(0x20d)]('disabled',![])[_0x5ade83(0x1d9)](_0x2a2712):(_0xe4363a[_0x5ade83(0x205)]('textarea')['prop'](_0x5ade83(0x1e0),![])[_0x5ade83(0x1d9)](_0x3fa78a),toastr[_0x5ade83(0x242)]('重新生成失败,已恢复原始内容。','模型召唤失败'));},'onCancel':()=>{const _0x30dedd=_0x4220b4;toastr[_0x30dedd(0x262)]('本批次总结已取消。',_0x3539ae),_0x589ea4(![]);}}):_0x589ea4(![]);return;}const _0x18fb29=getRawMessagesForSummary(_0x4a2c27,_0x58ec0c);if(!_0x18fb29||_0x18fb29[_0x4220b4(0x1d4)]===0x0)return toastr[_0x4220b4(0x232)](_0x4220b4(0x1e3),'圣谕有误'),_0x589ea4(![]);const _0xbd5599=_0x255d8b=>{const _0x1ac2c4=_0x4220b4,_0x9404dd=_0x255d8b[_0x1ac2c4(0x234)](_0x677753=>_0x1ac2c4(0x1db)+_0x677753[_0x1ac2c4(0x237)]+_0x1ac2c4(0x261)+_0x677753['floor']+_0x1ac2c4(0x1f4)+_0x677753[_0x1ac2c4(0x1a4)]+_0x1ac2c4(0x217)+_0x677753[_0x1ac2c4(0x1b0)]+'\x22>'+_0x677753[_0x1ac2c4(0x1b5)]+'\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20')[_0x1ac2c4(0x219)]('');return _0x1ac2c4(0x204)+(_0x39bd7e[_0x1ac2c4(0x1c4)]||'用户')+_0x1ac2c4(0x23f)+(_0x39bd7e[_0x1ac2c4(0x1ee)]||'角色')+_0x1ac2c4(0x1e4)+_0x9404dd+_0x1ac2c4(0x1bc);},_0x2f38f9=_0xbd5599(_0x18fb29);showHtmlModal(_0x4220b4(0x22d),_0x2f38f9,{'okText':_0x4220b4(0x21a),'cancelText':'取消','onOpen':_0x12a377=>{const _0x2a9deb=_0x4220b4,_0x3758a1=_0x12a377[_0x2a9deb(0x205)](_0x2a9deb(0x245)),_0x1f4f6c=_0x12a377[_0x2a9deb(0x205)](_0x2a9deb(0x1b3)),_0x2cf016=_0x12a377['find'](_0x2a9deb(0x194)),_0x5e8b5b=()=>{const _0x24916b=_0x2a9deb,_0x507e48=_0x3758a1['is'](_0x24916b(0x1ba)),_0x5c21d2=_0x1f4f6c['is'](_0x24916b(0x1ba));_0x2cf016['find'](_0x24916b(0x1ab))[_0x24916b(0x1f7)](function(){const _0x84c018=_0x24916b,_0x2b2c50=$(this),_0x4720e8=_0x2b2c50[_0x84c018(0x229)]('author-type');_0x4720e8===_0x84c018(0x201)&&!_0x507e48||_0x4720e8===_0x84c018(0x1a8)&&!_0x5c21d2?_0x2b2c50[_0x84c018(0x20d)](_0x84c018(0x1a9),!![]):_0x2b2c50[_0x84c018(0x20d)](_0x84c018(0x1a9),![]);});};_0x3758a1['on'](_0x2a9deb(0x214),_0x5e8b5b),_0x1f4f6c['on'](_0x2a9deb(0x214),_0x5e8b5b);},'onOk':async _0x3ffc68=>{const _0x12aba2=_0x4220b4,_0x5e936e=_0x3ffc68[_0x12aba2(0x205)](_0x12aba2(0x1cd))[_0x12aba2(0x234)](function(){const _0x1a57df=_0x12aba2,_0x1e5dcb=$(this)['data']('floor'),_0x517a52=$(this)[_0x1a57df(0x1ac)]('.historiography-message-item')[_0x1a57df(0x205)](_0x1a57df(0x190))[_0x1a57df(0x1fa)]()[_0x1a57df(0x238)](_0x1a57df(0x1ea)+_0x1e5dcb+_0x1a57df(0x1f4),'');return _0x1a57df(0x1ea)+_0x1e5dcb+_0x1a57df(0x1f4)+_0x517a52+':\x20'+$(this)[_0x1a57df(0x1d9)]();})['get']()[_0x12aba2(0x219)]('\x0a');if(!_0x5e936e[_0x12aba2(0x188)]()){toastr['error'](_0x12aba2(0x1f5),'圣谕有误');return;}const _0x5ef5c7=_0x3ffc68[0x0];_0x5ef5c7&&typeof _0x5ef5c7['close']===_0x12aba2(0x20f)&&_0x5ef5c7[_0x12aba2(0x1cc)]();_0x3ffc68[_0x12aba2(0x256)]();const _0x822179=await getSummary(_0x5e936e,_0x3539ae);_0x822179?showSummaryModal(_0x822179,{'onConfirm':async _0x48987e=>{const _0x431902=await writeSummary(_0x48987e,_0x4a2c27,_0x58ec0c,_0x3539ae);_0x589ea4(_0x431902);},'onRegenerate':async _0x371453=>{const _0x6efa07=_0x12aba2;_0x371453[_0x6efa07(0x205)]('textarea')[_0x6efa07(0x20d)](_0x6efa07(0x1e0),!![])[_0x6efa07(0x1d9)](_0x6efa07(0x250));const _0x5738bb=await getSummary(_0x5e936e,_0x3539ae);_0x5738bb?_0x371453[_0x6efa07(0x205)](_0x6efa07(0x24f))['prop']('disabled',![])['val'](_0x5738bb):(_0x371453[_0x6efa07(0x205)](_0x6efa07(0x24f))[_0x6efa07(0x20d)](_0x6efa07(0x1e0),![])[_0x6efa07(0x1d9)](_0x822179),toastr[_0x6efa07(0x242)](_0x6efa07(0x187),_0x6efa07(0x221)));},'onCancel':()=>{const _0x2a0d08=_0x12aba2;toastr[_0x2a0d08(0x262)](_0x2a0d08(0x259),_0x2a0d08(0x1c5)),_0x589ea4(![]);}}):_0x589ea4(![]);},'onCancel':()=>{const _0xf0d35f=_0x4220b4;toastr[_0xf0d35f(0x262)](_0xf0d35f(0x222),_0x3539ae),_0x589ea4(![]);}});});}function getRawMessagesForSummary(_0x2e040e,_0x2268b5){const _0x48c923=_0x326bc9,_0x167ef5=getContext(),_0xb4f706=_0x167ef5[_0x48c923(0x22c)],_0x551158=extension_settings[extensionName],_0x14ac0e=_0xb4f706[_0x48c923(0x23b)](_0x2e040e-0x1,_0x2268b5);if(_0x14ac0e[_0x48c923(0x1d4)]===0x0)return null;const _0x22609c=_0x167ef5[_0x48c923(0x1c4)]||'用户',_0x41fc5b=_0x167ef5[_0x48c923(0x1ee)]||'角色',_0x4b6dfe=_0x551158['historiographyTagExtractionEnabled']??![],_0x288589=_0x4b6dfe?(_0x551158[_0x48c923(0x18d)]||'')[_0x48c923(0x1f0)](',')[_0x48c923(0x234)](_0x38d005=>_0x38d005['trim']())[_0x48c923(0x1f2)](Boolean):[],_0x38788d=_0x551158[_0x48c923(0x24e)]||[],_0x58cd04=_0x14ac0e['map']((_0x52839a,_0xbbfda3)=>{const _0x2986bb=_0x48c923;let _0x149341=_0x52839a[_0x2986bb(0x21f)];if(_0x4b6dfe&&_0x288589['length']>0x0){const _0x29a165=extractBlocksByTags(_0x149341,_0x288589);_0x29a165[_0x2986bb(0x1d4)]>0x0&&(_0x149341=_0x29a165[_0x2986bb(0x219)]('\x0a\x0a'));}_0x149341=applyExclusionRules(_0x149341,_0x38788d);if(!_0x149341[_0x2986bb(0x188)]())return null;return{'floor':_0x2e040e+_0xbbfda3,'author':_0x52839a[_0x2986bb(0x19f)]?_0x22609c:_0x41fc5b,'authorType':_0x52839a[_0x2986bb(0x19f)]?_0x2986bb(0x201):_0x2986bb(0x1a8),'content':_0x149341['trim']()};})[_0x48c923(0x1f2)](Boolean);return _0x58cd04;}async function getSummary(_0x458188,_0x4f9f4f){const _0x2283f6=_0x326bc9;toastr[_0x2283f6(0x262)]('正在为您熔铸对话历史...',_0x4f9f4f);const _0x4e68a7=extension_settings[extensionName],_0x1f4e5a=getPresetPrompts(_0x2283f6(0x18c));let _0x291b38;try{const _0x508406=localStorage[_0x2283f6(0x249)](_0x2283f6(0x198));_0x508406&&(_0x291b38=JSON[_0x2283f6(0x24d)](_0x508406));}catch(_0x2a15b7){console[_0x2283f6(0x242)](_0x2283f6(0x210),_0x2a15b7);}const _0x3065de=getMixedOrder('small_summary')||[],_0x5d021b=[{'role':_0x2283f6(0x1da),'content':generateRandomSeed()}];let _0x481130=0x0;for(const _0x43e549 of _0x3065de){if(_0x43e549[_0x2283f6(0x231)]==='prompt')_0x1f4e5a&&_0x1f4e5a[_0x481130]&&(_0x5d021b[_0x2283f6(0x1aa)](_0x1f4e5a[_0x481130]),_0x481130++);else{if(_0x43e549['type']===_0x2283f6(0x1c1))switch(_0x43e549['id']){case _0x2283f6(0x19d):_0x4e68a7[_0x2283f6(0x1ad)]&&_0x5d021b[_0x2283f6(0x1aa)]({'role':'system','content':_0x4e68a7[_0x2283f6(0x1ad)]});break;case'summaryPrompt':_0x4e68a7[_0x2283f6(0x1b6)]&&_0x5d021b[_0x2283f6(0x1aa)]({'role':_0x2283f6(0x1da),'content':_0x4e68a7[_0x2283f6(0x1b6)]});break;case _0x2283f6(0x208):_0x5d021b['push']({'role':_0x2283f6(0x201),'content':_0x2283f6(0x1b1)+_0x458188+'\x0a'});break;}}}const _0x1f4a65=_0x4e68a7[_0x2283f6(0x21c)]?await callNgmsAI(_0x5d021b):await callAI(_0x5d021b);return console[_0x2283f6(0x243)](_0x2283f6(0x1b7),_0x1f4a65),_0x1f4a65;}async function writeSummary(_0x163f2f,_0xee366a,_0x3849d5,_0x47752){const _0x22e314=_0x326bc9,_0x1d7243=extension_settings[extensionName],_0xeb1dfa=getContext(),_0xc7ecb7=_0x1d7243[_0x22e314(0x192)]??!![],_0x118443=_0x1d7243[_0x22e314(0x253)]??![];if(!_0xc7ecb7&&!_0x118443)return toastr[_0x22e314(0x232)](_0x22e314(0x20b),_0x47752),!![];if(_0x118443)try{let _0x23636f;switch(_0x1d7243[_0x22e314(0x212)]){case _0x22e314(0x21e):_0x23636f=characters[_0xeb1dfa[_0x22e314(0x184)]]?.[_0x22e314(0x229)]?.[_0x22e314(0x235)]?.[_0x22e314(0x1dc)];if(!_0x23636f)throw new Error(_0x22e314(0x230));break;case'dedicated':const _0x598078=await getChatIdentifier();_0x23636f='Amily2-Lore-'+_0x598078;break;default:throw new Error(_0x22e314(0x1eb));}toastr[_0x22e314(0x262)](_0x22e314(0x1ff),_0x22e314(0x1c2));const _0x1ed422={'bookName':_0x23636f,'entryName':_0x22e314(0x1bf)+_0xee366a+'-'+_0x3849d5+'楼'},_0x263050=await ingestTextToHanlinyuan(_0x163f2f,_0x22e314(0x1ae),_0x1ed422);if(_0x263050[_0x22e314(0x1df)])toastr[_0x22e314(0x1df)](_0x22e314(0x23a),'翰林院');else throw new Error(_0x263050[_0x22e314(0x242)]);}catch(_0x2f0d79){console[_0x22e314(0x242)](_0x22e314(0x1f8),_0x2f0d79),toastr[_0x22e314(0x242)](_0x22e314(0x182)+_0x2f0d79[_0x22e314(0x1a3)],_0x22e314(0x1c2));}if(_0xc7ecb7)try{let _0x1ee2f5;switch(_0x1d7243['lorebookTarget']){case _0x22e314(0x21e):_0x1ee2f5=characters[_0xeb1dfa[_0x22e314(0x184)]]?.[_0x22e314(0x229)]?.[_0x22e314(0x235)]?.['world'];if(!_0x1ee2f5)throw new Error(_0x22e314(0x1b8));break;case _0x22e314(0x247):const _0x1204b8=await getChatIdentifier();_0x1ee2f5=_0x22e314(0x200)+_0x1204b8;break;default:throw new Error(_0x22e314(0x228));}const _0x31b7e6=_0x30adc0=>{const _0x26b849=_0x22e314,_0x35b737='\x0a\x0a本条勿动【前'+_0x3849d5+'楼总结已完成】否则后续总结无法进行。',_0x39ca92='\x0a\x0a---\x0a\x0a【'+_0xee366a+'楼至'+_0x3849d5+_0x26b849(0x226)+_0x163f2f;if(_0x30adc0){const _0x84c7d5=_0x30adc0[_0x26b849(0x238)](PROGRESS_SEAL_REGEX,'')[_0x26b849(0x188)]();return _0x84c7d5+_0x39ca92+_0x35b737;}else{const _0xf71292='以下是依照顺序已发生剧情'+_0x39ca92;return _0xf71292+_0x35b737;}};console['log']('[大史官-调试]\x20读取到的原始设置:',{'loreActivationMode':_0x1d7243[_0x22e314(0x1fb)],'loreInsertionPosition':_0x1d7243['loreInsertionPosition'],'loreDepth':_0x1d7243[_0x22e314(0x21b)],'loreKeywords':_0x1d7243[_0x22e314(0x18e)]});const _0x14132f={'keys':_0x1d7243['loreKeywords']['split'](',')[_0x22e314(0x234)](_0x5374eb=>_0x5374eb[_0x22e314(0x188)]())[_0x22e314(0x1f2)](Boolean),'isConstant':_0x1d7243[_0x22e314(0x1fb)]!=='keyed','insertion_position':_0x1d7243[_0x22e314(0x195)],'depth':_0x1d7243['loreDepth']};console[_0x22e314(0x243)](_0x22e314(0x240),_0x14132f);const _0xd662ae=await writeToLorebookWithTavernHelper(_0x1ee2f5,RUNNING_LOG_COMMENT,_0x31b7e6,_0x14132f);if(_0xd662ae)return toastr[_0x22e314(0x1df)](_0x22e314(0x255),_0x47752+_0x22e314(0x1ef)),!![];else throw new Error('使用\x20TavernHelper\x20写入失败,请检查控制台日志。');}catch(_0x9c6f95){return console[_0x22e314(0x242)]('[大史官]\x20'+_0x47752+_0x22e314(0x220),_0x9c6f95),toastr[_0x22e314(0x242)](_0x22e314(0x22e)+_0x9c6f95['message'],_0x22e314(0x18b)),![];}return!![];}const CHAPTER_SEAL_REGEX=/【前(\d+)楼篇章编撰已完成】/;export async function executeRefinement(_0x3a4ef2,_0x39398c){const _0x4cad41=_0x326bc9;toastr[_0x4cad41(0x262)](_0x4cad41(0x1ec)+_0x3a4ef2+_0x4cad41(0x206),_0x4cad41(0x22a));try{const _0x36dd5d=await loadWorldInfo(_0x3a4ef2),_0x104b0e=_0x36dd5d?.[_0x4cad41(0x227)][_0x39398c];if(!_0x104b0e){toastr[_0x4cad41(0x242)](_0x4cad41(0x21d),_0x4cad41(0x199));return;}const _0x33324e=_0x104b0e[_0x4cad41(0x1b5)],_0x502ee6=extension_settings[extensionName],_0x3fbb6c=_0x33324e[_0x4cad41(0x258)](PROGRESS_SEAL_REGEX);if(!_0x3fbb6c){toastr[_0x4cad41(0x242)](_0x4cad41(0x18a),_0x4cad41(0x213));return;}const _0x31b11a=_0x3fbb6c[0x0],_0x281fcf=parseInt(_0x3fbb6c[0x1],0xa),_0x166ef0=_0x33324e[_0x4cad41(0x258)](CHAPTER_SEAL_REGEX);let _0x3db77f='',_0x1d67d2='',_0x3921a3=0x0;if(_0x166ef0){const _0x4cd19c=_0x166ef0[0x0];_0x3921a3=parseInt(_0x166ef0[0x1],0xa);const _0x4952ee=_0x33324e[_0x4cad41(0x1f0)](_0x4cd19c);_0x3db77f=_0x4952ee[0x0]['trim'](),_0x1d67d2=_0x4952ee[0x1]['replace'](PROGRESS_SEAL_REGEX,'')[_0x4cad41(0x188)]();}else _0x1d67d2=_0x33324e[_0x4cad41(0x238)](PROGRESS_SEAL_REGEX,'')[_0x4cad41(0x188)]();if(!_0x1d67d2[_0x4cad41(0x188)]()){toastr[_0x4cad41(0x232)]('史册条目中没有新的内容可供重铸。',_0x4cad41(0x20c));return;}const _0x1d2bc0=getPresetPrompts(_0x4cad41(0x1e2));let _0x2e7521;try{const _0x3a9206=localStorage[_0x4cad41(0x249)](_0x4cad41(0x198));_0x3a9206&&(_0x2e7521=JSON[_0x4cad41(0x24d)](_0x3a9206));}catch(_0x3db6a0){console[_0x4cad41(0x242)](_0x4cad41(0x210),_0x3db6a0);}const _0x39041a=getMixedOrder(_0x4cad41(0x1e2))||[],_0x4f7d91=[{'role':'system','content':generateRandomSeed()}];let _0x46e102=0x0;for(const _0x571a6d of _0x39041a){if(_0x571a6d[_0x4cad41(0x231)]===_0x4cad41(0x1b4))_0x1d2bc0&&_0x1d2bc0[_0x46e102]&&(_0x4f7d91[_0x4cad41(0x1aa)](_0x1d2bc0[_0x46e102]),_0x46e102++);else{if(_0x571a6d['type']==='conditional')switch(_0x571a6d['id']){case _0x4cad41(0x19d):_0x502ee6[_0x4cad41(0x1de)]&&_0x4f7d91[_0x4cad41(0x1aa)]({'role':_0x4cad41(0x1da),'content':_0x502ee6[_0x4cad41(0x1de)]});break;case'summaryPrompt':_0x502ee6[_0x4cad41(0x209)]&&_0x4f7d91[_0x4cad41(0x1aa)]({'role':_0x4cad41(0x1da),'content':_0x502ee6['historiographyLargeRefinePrompt']});break;case _0x4cad41(0x208):_0x4f7d91['push']({'role':'user','content':_0x4cad41(0x202)+_0x1d67d2});break;}}}const _0x51cff8=async()=>{const _0x4f4a17=_0x4cad41;return toastr[_0x4f4a17(0x262)](_0x4f4a17(0x1bb),_0x4f4a17(0x22a)),await callAI(_0x4f7d91);},_0x194222=await _0x51cff8();if(!_0x194222){toastr[_0x4cad41(0x242)](_0x4cad41(0x1ce),_0x4cad41(0x218));return;}const _0x55c231=async _0x11e1aa=>{showSummaryModal(_0x11e1aa,{'onConfirm':async _0x83bda=>{const _0x3a29bc=_0x469a;let _0x423c85;const _0x19283b=_0x3a29bc(0x257)+_0x281fcf+_0x3a29bc(0x191),_0x3410d4=document['getElementById'](_0x3a29bc(0x1a5))?.[_0x3a29bc(0x207)]??![];if(_0x3410d4&&_0x166ef0)try{toastr['info'](_0x3a29bc(0x23c)+_0x3921a3+_0x3a29bc(0x1dd),_0x3a29bc(0x1c2));const _0x44171a={'bookName':_0x3a4ef2,'entryName':'宏史卷总结:\x201-'+_0x3921a3+'楼'},_0x1f9963=await ingestTextToHanlinyuan(_0x3db77f,_0x3a29bc(0x1ae),_0x44171a);if(!_0x1f9963[_0x3a29bc(0x1df)])throw new Error(_0x1f9963['error']||_0x3a29bc(0x1af));toastr[_0x3a29bc(0x1df)]('翰林院已成功接收旧“宏史卷”记忆!新增\x20'+_0x1f9963[_0x3a29bc(0x224)]+_0x3a29bc(0x1e8),_0x3a29bc(0x1c2));const _0xde99c5=_0x3a29bc(0x1c7)+_0x3921a3+_0x3a29bc(0x1d5)+_0x3921a3+_0x3a29bc(0x22b);_0x423c85=_0xde99c5+_0x3a29bc(0x1a2)+_0x83bda+_0x19283b+'\x0a\x0a'+_0x31b11a;}catch(_0x30284a){console[_0x3a29bc(0x242)]('[大史官-宏史卷向量化]\x20失败:',_0x30284a),toastr[_0x3a29bc(0x242)](_0x3a29bc(0x186)+_0x30284a['message']+_0x3a29bc(0x24a),'翰林院');const _0x32f1ad=_0x3a29bc(0x183)+_0x3921a3+_0x3a29bc(0x23d);_0x423c85=''+_0x3db77f+_0x32f1ad+_0x83bda+_0x19283b+'\x0a\x0a'+_0x31b11a;}else{if(_0x166ef0){const _0x47b79b=_0x3a29bc(0x183)+_0x3921a3+_0x3a29bc(0x23d);_0x423c85=''+_0x3db77f+_0x47b79b+_0x83bda+_0x19283b+'\x0a\x0a'+_0x31b11a;}else{const _0x433ff6=_0x3a29bc(0x211)+_0x281fcf+_0x3a29bc(0x216);_0x423c85=''+_0x433ff6+_0x83bda+_0x19283b+'\x0a\x0a'+_0x31b11a;}}_0x104b0e[_0x3a29bc(0x1b5)]=_0x423c85,await saveWorldInfo(_0x3a4ef2,_0x36dd5d,!![]),toastr[_0x3a29bc(0x1df)](_0x3a29bc(0x25a)+_0x3a4ef2+'》!',_0x3a29bc(0x1c0));},'onRegenerate':async _0x34a887=>{const _0x50d2c9=_0x469a;_0x34a887[_0x50d2c9(0x205)](_0x50d2c9(0x24f))[_0x50d2c9(0x20d)](_0x50d2c9(0x1e0),!![])[_0x50d2c9(0x1d9)](_0x50d2c9(0x250));const _0x2a9c4b=await _0x51cff8();_0x2a9c4b?_0x34a887[_0x50d2c9(0x205)](_0x50d2c9(0x24f))[_0x50d2c9(0x20d)](_0x50d2c9(0x1e0),![])[_0x50d2c9(0x1d9)](_0x2a9c4b):(_0x34a887[_0x50d2c9(0x205)](_0x50d2c9(0x24f))['prop'](_0x50d2c9(0x1e0),![])['val'](_0x11e1aa),toastr[_0x50d2c9(0x242)]('重新生成失败,已恢复原始内容。','模型召唤失败'));},'onCancel':()=>{const _0x4fb2c0=_0x469a;toastr[_0x4fb2c0(0x262)](_0x4fb2c0(0x252),_0x4fb2c0(0x1c5));}});};await _0x55c231(_0x194222);}catch(_0x374c1d){console['error'](_0x4cad41(0x236),_0x374c1d),toastr[_0x4cad41(0x242)](_0x4cad41(0x20e)+_0x374c1d['message'],_0x4cad41(0x18b));}}function _0x2d7d(){const _0x1a0144=['log','远征军已开拔!目标:','#hist-include-user','\x20/\x20','dedicated','values','getItem',',将执行标准保存。','min','\x20批次任务失败而中止。','parse','historiographyExclusionRules','textarea','正在重新生成,请稍候...','无标题条目','宏史卷重铸操作已取消。','historiographyIngestToRag','[大史官]\x20阅览《','编年史已成功更新!','remove','\x0a\x0a【前','match','本批次总结已取消。','史册已成功重铸,并保存于《','dispatchEvent','[大史官-远征失败]','远征已遵从您的敕令暂停!随时可以【继续远征】。','warn','1291460eSiraQ','historiographySmallTriggerThreshold','\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20【第\x20','info','送往翰林院的文书处理失败:\x20','\x0a\x0a===【截止至第','characterId','批量编纂大功告成!新增\x20','宏史卷向量化失败:\x20','重新生成失败,已恢复原始内容。','trim','9980miZqDD','史册缺少【流水金印】,无法执行重铸。','国史馆','small_summary','historiographyTags','loreKeywords','18660880NOmJeU','summary','楼篇章编撰已完成】','historiographyWriteToLorebook','远征失败','#historiography-preview-container','loreInsertionPosition','】内容为空。','amily2-expedition-state-change','amily2_prompt_presets_v2_mixed_order','圣谕有误','》天机时出错:','国史已是最新,远征军无需出动。','536ySJAFA','jailbreakPrompt','批量编纂期间发生部分错误,详情请查看控制台。','is_user','\x20批次战役准备中...\x20(','】处理时发生严重错误:\x20','\x0a\x0a---\x0a\x0a','message','author','amily2_vectorize_summary_content','historiographySmallAutoEnable','\x20个条目进行批量编纂...','char','hidden','push','.historiography-message-item','closest','historiographySmallJailbreakPrompt','lorebook','未知错误','floor','请严格根据以下\x22对话记录\x22中的内容进行总结,不要添加任何额外信息。\x0a\x0a<对话记录>\x0a','\x20层历史,分\x20','#hist-include-char','prompt','content','historiographySmallSummaryPrompt','[大史官-微言录]\x20AI回复的全部内容:','当前角色未绑定主世界书。','[翰林院]\x20批量编纂错误详情:',':checked','正在召唤模型进行内容精炼...','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20','\x20个条目,共新增\x20','远征因第\x20','微言录总结:\x20','宏史卷重铸完毕','conditional','翰林院','秒后接敌)','name1','操作已取消','圣谕传达','AI你好,以上内容为rag向量化后注入的相关剧情,以下内容是已发生的剧情回顾。\x0a\x0a(前','\x20至\x20','条目【','\x0a-\x20','228222iMeWkI','close','.historiography-message-item:not([hidden])\x20textarea','模型未能返回有效的精炼内容。','113LQuFTb','远征军已在途中,无需重复下令。','未选择任何条目进行编纂。','无法加载书库《','[大史官]\x20检阅《','length','楼聊天记录总结已由翰林院向量化注入。)\x0a\x0a【以下内容为','远征战役\x20(','鸣金收兵','【敕史局】对话流水总帐','val','system','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20','》的数据。','6LaDbQK','comment','\x20条。','\x20条忆识。','【第\x20','未知的史册写入指令,无法为翰林院确定目标。','遵旨!正在为您重铸《','[大史官]\x20自动微言录已触发,处理\x20','name2','\x20-\x20国史馆','split','圣谕不明','filter','31814dTxOgr','\x20楼】\x20','请至少选择一条消息进行总结!','disable','each','[翰林院]\x20向量化处理失败:','\x20批次征服!','text','loreActivationMode','[翰林院]\x20批量条目入库失败:','遵旨!开始对《','isArray','正在将此份“微言录”送往翰林院...','Amily2-Lore-','user','请将以下多个零散的\x22详细总结记录\x22提炼并融合成一段连贯的章节历史。原文如下:\x0a\x0a','\x0a\x0a发生以下错误:\x0a-\x20','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\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\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20