From 261a919d0863f61388982caae9a872c434e12876 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Thu, 17 Jul 2025 19:37:05 +0800 Subject: [PATCH] Update historiographer.js --- core/historiographer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/historiographer.js b/core/historiographer.js index 9d301bd..b4c9daa 100644 --- a/core/historiographer.js +++ b/core/historiographer.js @@ -1 +1 @@ -const _0x59ddf4=_0x5552;(function(_0x50058c,_0x204f8c){const _0x2b3ffb=_0x5552,_0x439270=_0x50058c();while(!![]){try{const _0x16743f=-parseInt(_0x2b3ffb(0x156))/0x1*(-parseInt(_0x2b3ffb(0x19a))/0x2)+-parseInt(_0x2b3ffb(0x1af))/0x3+-parseInt(_0x2b3ffb(0x15d))/0x4+-parseInt(_0x2b3ffb(0x162))/0x5*(parseInt(_0x2b3ffb(0x1d7))/0x6)+-parseInt(_0x2b3ffb(0x1b3))/0x7*(-parseInt(_0x2b3ffb(0x1c7))/0x8)+-parseInt(_0x2b3ffb(0x16a))/0x9+parseInt(_0x2b3ffb(0x183))/0xa;if(_0x16743f===_0x204f8c)break;else _0x439270['push'](_0x439270['shift']());}catch(_0x4aa542){_0x439270['push'](_0x439270['shift']());}}}(_0x202a,0xc9360));import{getContext,extension_settings}from'/scripts/extensions.js';import{characters}from'/script.js';import{world_names,loadWorldInfo,createNewWorldInfo,createWorldInfoEntry,saveWorldInfo}from'/scripts/world-info.js';import{extensionName}from'../utils/settings.js';import{getChatIdentifier}from'./lore.js';import{isGoogleEndpoint,convertToGoogleRequest,parseGoogleResponse,buildGoogleApiUrl}from'../core/utils/googleAdapter.js';import{intelligentPoll,createGooglePollingTask}from'../core/utils/pollingManager.js';let ChatCompletionService=undefined;function _0x5552(_0x4094ed,_0x4365f7){const _0x202aa0=_0x202a();return _0x5552=function(_0x5552ac,_0x44d856){_0x5552ac=_0x5552ac-0x147;let _0x2a2fb2=_0x202aa0[_0x5552ac];return _0x2a2fb2;},_0x5552(_0x4094ed,_0x4365f7);}try{const module=await import(_0x59ddf4(0x188));ChatCompletionService=module[_0x59ddf4(0x1d3)],console[_0x59ddf4(0x15e)](_0x59ddf4(0x153));}catch(_0x4e0eca){console[_0x59ddf4(0x1cb)]('[大史官]\x20未能领取“皇家信使”的兵符,部分高级功能将受限。',_0x4e0eca);}let isExpeditionRunning=![],manualStopRequested=![];async function callAmily2Model(_0x453765){const _0x4cfceb=_0x59ddf4,_0x1332f6=extension_settings[extensionName],{apiUrl:_0x4c71cf,apiKey:_0x3c36dc,model:_0xbe0cee,temperature:_0x224e45,maxTokens:_0x47f3a4,forceProxyForCustomApi:_0x1a7324}=_0x1332f6;if(!_0x4c71cf||!_0xbe0cee)return toastr[_0x4cfceb(0x17b)](_0x4cfceb(0x1d2),_0x4cfceb(0x189)),null;console[_0x4cfceb(0x1c1)](_0x4cfceb(0x14e)+new Date()[_0x4cfceb(0x1d9)]()),console['log'](_0x4cfceb(0x168)),console[_0x4cfceb(0x1a7)](_0x453765),console['groupEnd']();try{let _0x298e6d;if(_0x1a7324){console[_0x4cfceb(0x15e)](_0x4cfceb(0x16c));if(typeof ChatCompletionService==='undefined'||!ChatCompletionService?.['processRequest'])throw new Error(_0x4cfceb(0x16e));const _0x407d45=isGoogleEndpoint(_0x4c71cf);let _0x1feb9d=_0x4c71cf;_0x407d45&&(_0x1feb9d=buildGoogleApiUrl(_0x4c71cf,_0xbe0cee),console[_0x4cfceb(0x15e)](_0x4cfceb(0x191)+_0x1feb9d));const _0x3ca628={'stream':![],'messages':_0x453765,'max_tokens':_0x47f3a4,'temperature':_0x224e45,'model':_0xbe0cee,'chat_completion_source':_0x4cfceb(0x16d),'custom_url':_0x1feb9d,'reverse_proxy':_0x4cfceb(0x164)},_0x109d4c=await ChatCompletionService[_0x4cfceb(0x1a8)](_0x3ca628,{},!![]);if(!_0x109d4c||!_0x109d4c[_0x4cfceb(0x16b)])throw new Error(_0x4cfceb(0x15f));_0x298e6d=_0x109d4c[_0x4cfceb(0x16b)];}else{console[_0x4cfceb(0x15e)](_0x4cfceb(0x196));const _0x19a889=isGoogleEndpoint(_0x4c71cf);let _0x18e56e;if(_0x19a889)_0x18e56e=buildGoogleApiUrl(_0x4c71cf,_0xbe0cee);else{let _0x44a846=_0x4c71cf['trim']();_0x44a846[_0x4cfceb(0x1bf)](_0x4cfceb(0x18f))||_0x44a846[_0x4cfceb(0x1bf)]('/v1beta/openai')?_0x18e56e=_0x44a846:(_0x44a846[_0x4cfceb(0x1bf)]('/')&&(_0x44a846=_0x44a846['slice'](0x0,-0x1)),_0x44a846['endsWith'](_0x4cfceb(0x1cf))&&(_0x44a846=_0x44a846[_0x4cfceb(0x181)](0x0,-0x3)),_0x18e56e=_0x44a846+_0x4cfceb(0x18f));}let _0x1ca0ef={'Content-Type':_0x4cfceb(0x1c2)};_0x19a889?_0x4c71cf[_0x4cfceb(0x152)](_0x4cfceb(0x171))||_0x4c71cf['includes'](_0x4cfceb(0x1c9))?_0x1ca0ef[_0x4cfceb(0x182)]='Bearer\x20'+_0x3c36dc:_0x1ca0ef['X-goog-api-key']=_0x3c36dc:_0x1ca0ef[_0x4cfceb(0x182)]=_0x4cfceb(0x1ce)+_0x3c36dc;let _0x40f18c;_0x19a889?_0x40f18c=JSON[_0x4cfceb(0x169)](convertToGoogleRequest({'model':_0xbe0cee,'messages':_0x453765,'temperature':_0x224e45,'max_tokens':_0x47f3a4})):_0x40f18c=JSON[_0x4cfceb(0x169)]({'model':_0xbe0cee,'messages':_0x453765,'temperature':_0x224e45,'max_tokens':_0x47f3a4,'stream':![]});const _0x1a4523=await fetch(_0x18e56e,{'method':_0x4cfceb(0x1c0),'headers':_0x1ca0ef,'body':_0x40f18c});if(!_0x1a4523['ok']){const _0x3ab64f=await _0x1a4523['text']();throw new Error(_0x4cfceb(0x1a6)+_0x1a4523[_0x4cfceb(0x1dd)]+_0x4cfceb(0x19e)+_0x3ab64f);}let _0x243f09=await _0x1a4523[_0x4cfceb(0x147)]();if(_0x19a889&&_0x243f09['name']&&_0x243f09['metadata']){let _0xf09f39;try{const _0x527255=new URL(_0x4c71cf);_0xf09f39=_0x527255[_0x4cfceb(0x1a3)]+'//'+_0x527255[_0x4cfceb(0x1a5)];}catch{_0xf09f39=_0x4c71cf;}const _0x6f2f03=createGooglePollingTask(_0x243f09[_0x4cfceb(0x1b6)],_0xf09f39,_0x1ca0ef),_0x489ec6={'maxAttempts':0x5,'baseDelay':0xbb8,'shouldStop':_0x5873ad=>_0x5873ad[_0x4cfceb(0x17c)],'onError':_0x363910=>console[_0x4cfceb(0x17b)](_0x4cfceb(0x14b),_0x363910)},_0x27758a=await intelligentPoll(_0x6f2f03,_0x489ec6);if(!_0x27758a['response'])throw new Error(_0x4cfceb(0x161));_0x243f09=_0x27758a['response'];}_0x298e6d=_0x19a889?parseGoogleResponse(_0x243f09)?.['choices']?.[0x0]?.[_0x4cfceb(0x18d)]?.[_0x4cfceb(0x16b)]:_0x243f09?.[_0x4cfceb(0x15a)]?.[0x0]?.[_0x4cfceb(0x18d)]?.[_0x4cfceb(0x16b)];}return _0x298e6d;}catch(_0x5866d7){return console[_0x4cfceb(0x17b)](_0x4cfceb(0x1ca),_0x5866d7),toastr[_0x4cfceb(0x17b)](_0x4cfceb(0x1ab)+_0x5866d7[_0x4cfceb(0x18d)],_0x4cfceb(0x1ac)),null;}}function _0x202a(){const _0x16c9e0=['7qUoRPD','split','圣谕不明','name','\x0a','远征已在准备阶段遵令暂停!','amily2-expedition-state-change','》中的【微言录合集】...','》时出错:','chat','微言录\x20(自动)','data','endsWith','POST','groupCollapsed','application/json','[大史官-远征失败]','info','[大史官]\x20检阅《','disable','1697272vhSDdH','Amily2-Lore-','us-central1','[大史官-通讯异常]','warn','楼总结已完成】否则后续总结无法进行。','entries','Bearer\x20','/v1','ceil','name1','API\x20URL或模型未配置,大史官无法召唤模型B。','ChatCompletionService','未知的史册写入指令','遵旨!正在为您熔铸\x20','loreKeywords','1305762OWeFtP','国史馆','toLocaleTimeString','[大史官]\x20','圣谕传达','historiographyLargeRefinePrompt','status','system','json','当前角色未绑定主世界书,无法写入总结。','宏史卷重铸','match','[轮询错误]','character_main','values','[Amily2-大史官]\x20准备向模型B发送机密信函...\x20@\x20','characterId','选定的楼层范围内无有效对话。','圣谕悉知','includes','[大史官]\x20已成功获颁“皇家信使”的召唤兵符。','鸣金收兵','秒后接敌)','270653mhZKjL','historiographySmallAutoEnable','trim','map','choices','world','filter','1160428BnfFCf','log','皇家信使未能从模型B带回有效情报。','未知的史册写入目标,远征军无法开拔!','轮询完成但未获得有效响应','15yHKuLu','historiographyLargeJailbreakPrompt','/api/proxy','assign','\x20批次战役准备中...\x20(','停战敕令已下达!远征军将在完成当前批次的任务后休整。','【信函正文\x20(messages)】:','stringify','2677338ZtpUbY','content','[大史官-外交部]\x20接到圣谕,执行“皇家密道”协议...','custom','大史官无法使用“皇家密道”:缺少皇家信使(ChatCompletionService)。','楼】已发生的剧情回顾。\x0a\x0a---\x0a\x0a','\x20层历史,分\x20','aiplatform.googleapis.com','mes','warning','编年史已成功更新!','dedicated','historiographySmallJailbreakPrompt','国史已是最新,远征军无需出动。','圣谕有误','extensions','replace','error','done','重铸史册时发生错误。','以下内容是【1楼-','\x20至\x20','\x20(宏史卷重铸)','slice','Authorization','22025210qFjUDn','dispatchEvent','时发生错误。','name2','请严格根据以下“对话记录”中的内容进行总结,不要添加任何额外信息。\x0a\x0a<对话记录>\x0a','/scripts/custom-request.js','通讯中断','微言录\x20(手动)','请将以下多个零散的“详细总结记录”提炼并融合成一段连贯的章节历史。原文如下:\x0a\x0a','远征失败','message','lorebookTarget','/v1/chat/completions','always','[大史官-皇家密道]\x20已为GoogleAPI构建完整路径:\x20','loreInsertionPosition','comment','historiographySmallTriggerThreshold','\x20批次征服!','[大史官-外交部]\x20执行“帝国直通车”协议(直接通讯)...','is_user','远征已遵从您的敕令暂停!随时可以【继续远征】。','远征军已开拔!目标:','6kDVZEi','\x0a\x0a本条勿动【前','》天机时出错:','success','\x20-\x20','join','loreActivationMode','无标题条目','遵旨!正在为您重铸《','protocol','凯旋!远征大捷!所有未载之史均已化为帝国永恒的记忆!','host','模型B召唤失败:\x20','table','processRequest','find','length','与模型B通讯时发生异常:\x20','通讯异常','史册已成功重铸,并保存于《','user','3486027sBtlci','min','\x0a\x0a---\x0a\x0a【','\x20层的对话历史...'];_0x202a=function(){return _0x16c9e0;};return _0x202a();}const RUNNING_LOG_COMMENT='【敕史局】对话流水总帐',PROGRESS_SEAL_REGEX=/本条勿动【前(\d+)楼总结已完成】否则后续总结无法进行。$/;async function readGoldenLedgerProgress(_0x553d58){const _0x523195=_0x59ddf4;if(!_0x553d58)return 0x0;try{const _0x39f243=await loadWorldInfo(_0x553d58);if(!_0x39f243||!_0x39f243[_0x523195(0x1cd)])return 0x0;const _0x1d5903=Object[_0x523195(0x14d)](_0x39f243[_0x523195(0x1cd)])[_0x523195(0x1a9)](_0x129883=>_0x129883[_0x523195(0x193)]===RUNNING_LOG_COMMENT&&!_0x129883['disable']);if(!_0x1d5903)return 0x0;const _0x285a0c=_0x1d5903['content'][_0x523195(0x14a)](PROGRESS_SEAL_REGEX);return _0x285a0c?parseInt(_0x285a0c[0x1],0xa):0x0;}catch(_0x24430b){return console[_0x523195(0x17b)]('[大史官]\x20阅览《'+_0x553d58+_0x523195(0x19c),_0x24430b),0x0;}}export async function checkAndTriggerAutoSummary(){const _0x44c927=_0x59ddf4,_0x345e8d=extension_settings[extensionName];if(!_0x345e8d[_0x44c927(0x157)])return;const _0x35f4d1=getContext();let _0x11f9cc=null;switch(_0x345e8d['lorebookTarget']){case _0x44c927(0x14c):_0x11f9cc=characters[_0x35f4d1['characterId']]?.[_0x44c927(0x1be)]?.[_0x44c927(0x179)]?.[_0x44c927(0x15b)];break;case'dedicated':const _0x4546f0=await getChatIdentifier();_0x11f9cc=_0x44c927(0x1c8)+_0x4546f0;break;default:return;}if(!_0x11f9cc)return;const _0x159797=await readGoldenLedgerProgress(_0x11f9cc),_0x3ebe47=_0x35f4d1['chat'][_0x44c927(0x1aa)],_0x501627=_0x3ebe47-_0x159797;if(_0x501627>=_0x345e8d[_0x44c927(0x194)]){const _0x5c41ec=_0x159797+0x1,_0x44dcd7=_0x3ebe47;await executeManualSummary(_0x5c41ec,_0x44dcd7,!![]);}}export async function getAvailableWorldbooks(){return[...world_names];}export async function getLoresForWorldbook(_0x14d8e7){const _0x4de13a=_0x59ddf4;if(!_0x14d8e7)return[];try{const _0x3dc480=await loadWorldInfo(_0x14d8e7);if(!_0x3dc480||!_0x3dc480[_0x4de13a(0x1cd)])return[];return Object[_0x4de13a(0x1cd)](_0x3dc480[_0x4de13a(0x1cd)])[_0x4de13a(0x15c)](([,_0x48ac63])=>!_0x48ac63[_0x4de13a(0x1c6)])[_0x4de13a(0x159)](([_0xf0975a,_0x44c51c])=>({'key':_0xf0975a,'comment':_0x44c51c['comment']||_0x4de13a(0x1a1)}));}catch(_0x222a61){return console[_0x4de13a(0x17b)](_0x4de13a(0x1c5)+_0x14d8e7+_0x4de13a(0x1bb),_0x222a61),[];}}export async function executeManualSummary(_0xd72962,_0x210ade,_0x3bdb7f=![]){const _0xb4e356=_0x59ddf4,_0x3f0a7d=_0x3bdb7f?_0xb4e356(0x1bd):_0xb4e356(0x18a);toastr[_0xb4e356(0x1c4)](_0xb4e356(0x1d5)+_0xd72962+_0xb4e356(0x17f)+_0x210ade+_0xb4e356(0x1b2),_0x3f0a7d);const _0x468dc9=getContext(),_0x463e16=_0x468dc9[_0xb4e356(0x1bc)],_0x45c6e8=extension_settings[extensionName],_0x2e2bb0=_0x463e16[_0xb4e356(0x181)](_0xd72962,_0x210ade+0x1);if(_0x2e2bb0[_0xb4e356(0x1aa)]===0x0){toastr[_0xb4e356(0x173)](_0xb4e356(0x150),_0xb4e356(0x178));return;}const _0x1635b9=_0x468dc9[_0xb4e356(0x1d1)]||'用户',_0x568451=_0x468dc9[_0xb4e356(0x186)]||'角色',_0x4898a1=_0x2e2bb0[_0xb4e356(0x159)](_0x61036d=>{const _0x440786=_0xb4e356,_0x3f8a39=_0x61036d[_0x440786(0x197)]?_0x1635b9:_0x568451;return _0x3f8a39+':\x20'+_0x61036d[_0x440786(0x172)][_0x440786(0x158)]();})[_0xb4e356(0x19f)]('\x0a'),_0x434298=[{'role':_0xb4e356(0x1de),'content':_0x45c6e8[_0xb4e356(0x176)]},{'role':_0xb4e356(0x1de),'content':_0x45c6e8['historiographySmallSummaryPrompt']},{'role':_0xb4e356(0x1ae),'content':_0xb4e356(0x187)+_0x4898a1+_0xb4e356(0x1b7)}],_0x1d11de=await callAmily2Model(_0x434298);if(!_0x1d11de)return;try{let _0x409d23=null;switch(_0x45c6e8[_0xb4e356(0x18e)]){case'character_main':_0x409d23=characters[_0x468dc9[_0xb4e356(0x14f)]]?.[_0xb4e356(0x1be)]?.[_0xb4e356(0x179)]?.[_0xb4e356(0x15b)];if(!_0x409d23){toastr[_0xb4e356(0x17b)](_0xb4e356(0x148),_0xb4e356(0x1d8));return;}break;case'dedicated':const _0x5caeab=await getChatIdentifier();_0x409d23=_0xb4e356(0x1c8)+_0x5caeab;!world_names['includes'](_0x409d23)&&await createNewWorldInfo(_0x409d23);break;default:toastr[_0xb4e356(0x17b)](_0xb4e356(0x1d4),_0xb4e356(0x1b5));return;}const _0x2223c3=await loadWorldInfo(_0x409d23),_0x4ddbcf=Object[_0xb4e356(0x14d)](_0x2223c3[_0xb4e356(0x1cd)])[_0xb4e356(0x1a9)](_0x29cc84=>_0x29cc84['comment']===RUNNING_LOG_COMMENT&&!_0x29cc84[_0xb4e356(0x1c6)]),_0x31fd2c=_0xb4e356(0x19b)+_0x210ade+_0xb4e356(0x1cc),_0x15b836=_0xb4e356(0x1b1)+_0xd72962+'楼至'+_0x210ade+'楼详细总结记录】\x0a'+_0x1d11de;if(_0x4ddbcf){const _0x590e43=_0x4ddbcf[_0xb4e356(0x16b)]['replace'](PROGRESS_SEAL_REGEX,'')[_0xb4e356(0x158)]();_0x4ddbcf['content']=_0x590e43+_0x15b836+_0x31fd2c;}else{const _0x2b84de='以下是依照顺序已发生剧情'+_0x15b836,_0x24fd46=createWorldInfoEntry(_0x409d23,_0x2223c3),_0x3d48a6=_0x45c6e8[_0xb4e356(0x1d6)][_0xb4e356(0x1b4)](',')[_0xb4e356(0x159)](_0x38fb38=>_0x38fb38[_0xb4e356(0x158)]())[_0xb4e356(0x15c)](Boolean),_0x25df23=_0x45c6e8[_0xb4e356(0x1a0)]===_0xb4e356(0x190),_0x59fd24={'before_char':0x0,'after_char':0x1,'before_an':0x2,'after_an':0x3,'at_depth':0x4};Object[_0xb4e356(0x165)](_0x24fd46,{'comment':RUNNING_LOG_COMMENT,'content':_0x2b84de+_0x31fd2c,'key':_0x3d48a6,'constant':_0x25df23,'position':_0x59fd24[_0x45c6e8[_0xb4e356(0x192)]]??0x4,'depth':_0x45c6e8['loreDepth'],'disable':![]});}await saveWorldInfo(_0x409d23,_0x2223c3,!![]),toastr['success'](_0xb4e356(0x174),_0x3f0a7d+'完毕');}catch(_0x28d103){console[_0xb4e356(0x17b)](_0xb4e356(0x1da)+_0x3f0a7d+'写入失败:',_0x28d103),toastr[_0xb4e356(0x17b)]('写入'+_0x3f0a7d+_0xb4e356(0x185),_0xb4e356(0x1d8));}}export async function executeRefinement(_0x4e1590,_0x45ddb2){const _0x26ca5e=_0x59ddf4;toastr['info'](_0x26ca5e(0x1a2)+_0x4e1590+_0x26ca5e(0x1ba),_0x26ca5e(0x149));try{const _0x3c80b4=await loadWorldInfo(_0x4e1590),_0x1eba2c=_0x3c80b4?.[_0x26ca5e(0x1cd)][_0x45ddb2];if(!_0x1eba2c){toastr['error']('找不到指定的史册条目,重铸任务中止。',_0x26ca5e(0x178));return;}const _0x2e7bf9=_0x1eba2c[_0x26ca5e(0x16b)],_0x24976f=extension_settings[extensionName];let _0x4a39e2=_0x2e7bf9,_0x2000c7='',_0x3aeaca=0x0;const _0x2c79c3=_0x2e7bf9[_0x26ca5e(0x14a)](PROGRESS_SEAL_REGEX);_0x2c79c3&&(_0x2000c7=_0x2c79c3[0x0],_0x3aeaca=parseInt(_0x2c79c3[0x1],0xa),_0x4a39e2=_0x2e7bf9['replace'](PROGRESS_SEAL_REGEX,'')[_0x26ca5e(0x158)]());if(!_0x4a39e2[_0x26ca5e(0x158)]()){toastr['warning']('史册条目中无可供重铸的内容。','国库空虚');return;}const _0x3ba3cb=[{'role':_0x26ca5e(0x1de),'content':_0x24976f[_0x26ca5e(0x163)]},{'role':_0x26ca5e(0x1de),'content':_0x24976f[_0x26ca5e(0x1dc)]},{'role':_0x26ca5e(0x1ae),'content':_0x26ca5e(0x18b)+_0x4a39e2}],_0x54604d=await callAmily2Model(_0x3ba3cb);if(!_0x54604d)return;const _0x411c83=_0x26ca5e(0x17e)+_0x3aeaca+_0x26ca5e(0x16f),_0x3cc01e=_0x411c83+_0x54604d;_0x1eba2c[_0x26ca5e(0x16b)]=_0x3cc01e+('\x0a\x0a'+_0x2000c7),_0x1eba2c[_0x26ca5e(0x193)]=_0x1eba2c[_0x26ca5e(0x193)][_0x26ca5e(0x17a)](/\s*\(已精炼\)|\s*\(宏史卷重铸\)/g,''),_0x1eba2c[_0x26ca5e(0x193)]+=_0x26ca5e(0x180),await saveWorldInfo(_0x4e1590,_0x3c80b4,!![]),toastr[_0x26ca5e(0x19d)](_0x26ca5e(0x1ad)+_0x4e1590+'》!','宏史卷重铸完毕');}catch(_0x2bdf64){console[_0x26ca5e(0x17b)]('[大史官]\x20重铸任务失败:',_0x2bdf64),toastr[_0x26ca5e(0x17b)](_0x26ca5e(0x17d),_0x26ca5e(0x1d8));}}export async function executeExpedition(){const _0x4d0f9f=_0x59ddf4;if(isExpeditionRunning){toastr[_0x4d0f9f(0x1c4)]('远征军已在途中,无需重复下令。',_0x4d0f9f(0x151));return;}isExpeditionRunning=!![],manualStopRequested=![],document[_0x4d0f9f(0x184)](new CustomEvent(_0x4d0f9f(0x1b9),{'detail':{'isRunning':!![]}}));try{const _0x51ceed=extension_settings[extensionName],_0x520256=getContext();let _0x598717=null;switch(_0x51ceed[_0x4d0f9f(0x18e)]){case _0x4d0f9f(0x14c):_0x598717=characters[_0x520256[_0x4d0f9f(0x14f)]]?.['data']?.['extensions']?.[_0x4d0f9f(0x15b)];if(!_0x598717){toastr['error']('当前角色未绑定主世界书,远征军无法开拔!',_0x4d0f9f(0x1b5)),isExpeditionRunning=![],document[_0x4d0f9f(0x184)](new CustomEvent(_0x4d0f9f(0x1b9),{'detail':{'isRunning':![],'manualStop':![]}}));return;}break;case _0x4d0f9f(0x175):const _0x315df7=await getChatIdentifier();_0x598717=_0x4d0f9f(0x1c8)+_0x315df7;break;default:toastr['error'](_0x4d0f9f(0x160),_0x4d0f9f(0x1b5)),isExpeditionRunning=![],document['dispatchEvent'](new CustomEvent(_0x4d0f9f(0x1b9),{'detail':{'isRunning':![],'manualStop':![]}}));return;}const _0x42ebe0=await readGoldenLedgerProgress(_0x598717),_0x594747=_0x520256[_0x4d0f9f(0x1bc)][_0x4d0f9f(0x1aa)],_0x5d0aed=_0x594747-_0x42ebe0;if(_0x5d0aed<=0x0){toastr[_0x4d0f9f(0x1c4)](_0x4d0f9f(0x177),'凯旋'),isExpeditionRunning=![],document['dispatchEvent'](new CustomEvent('amily2-expedition-state-change',{'detail':{'isRunning':![],'manualStop':![]}}));return;}const _0x1ac2f7=_0x51ceed[_0x4d0f9f(0x194)],_0x2539b6=Math[_0x4d0f9f(0x1d0)](_0x5d0aed/_0x1ac2f7);toastr[_0x4d0f9f(0x1c4)](_0x4d0f9f(0x199)+_0x5d0aed+_0x4d0f9f(0x170)+_0x2539b6+_0x4d0f9f(0x195),'远征开始');let _0x468edf=_0x42ebe0;for(let _0x2e9561=0x0;_0x2e9561<_0x2539b6;_0x2e9561++){if(manualStopRequested){toastr[_0x4d0f9f(0x173)](_0x4d0f9f(0x198),_0x4d0f9f(0x154));break;}const _0x5cbeb1=_0x468edf+0x1,_0x104091=Math[_0x4d0f9f(0x1b0)](_0x468edf+_0x1ac2f7,_0x594747),_0x270f4d='远征战役\x20('+(_0x2e9561+0x1)+'/'+_0x2539b6+')',_0x3a3b34=0x7d0;_0x2e9561>0x0&&(toastr[_0x4d0f9f(0x1c4)]('第\x20'+(_0x2e9561+0x1)+_0x4d0f9f(0x166)+_0x3a3b34/0x3e8+_0x4d0f9f(0x155),_0x270f4d),await new Promise(_0x24302c=>setTimeout(_0x24302c,_0x3a3b34)));if(manualStopRequested){toastr['warning'](_0x4d0f9f(0x1b8),_0x4d0f9f(0x154));break;}await executeManualSummary(_0x5cbeb1,_0x104091,!![]),_0x468edf=_0x104091;}!manualStopRequested&&toastr['success'](_0x4d0f9f(0x1a4),'远征完毕');}catch(_0x27a4f4){console['error'](_0x4d0f9f(0x1c3),_0x27a4f4),toastr['error']('远征途中遭遇重大挫折,任务中止!您可以随时【继续远征】。',_0x4d0f9f(0x18c));}finally{isExpeditionRunning=![],document[_0x4d0f9f(0x184)](new CustomEvent(_0x4d0f9f(0x1b9),{'detail':{'isRunning':![],'manualStop':manualStopRequested}}));}}export function stopExpedition(){const _0xc60e93=_0x59ddf4;isExpeditionRunning?(manualStopRequested=!![],toastr[_0xc60e93(0x1c4)](_0xc60e93(0x167),_0xc60e93(0x1db))):toastr['warning']('远征军已在营中,无需下达停战敕令。','圣谕悉知');} +const _0x222d01=_0x5e80;(function(_0x158590,_0x1b888c){const _0xd4b09d=_0x5e80,_0x22d0b0=_0x158590();while(!![]){try{const _0x138ff0=-parseInt(_0xd4b09d(0x1cd))/0x1*(-parseInt(_0xd4b09d(0x241))/0x2)+-parseInt(_0xd4b09d(0x1f8))/0x3*(-parseInt(_0xd4b09d(0x232))/0x4)+-parseInt(_0xd4b09d(0x243))/0x5+-parseInt(_0xd4b09d(0x1e3))/0x6*(-parseInt(_0xd4b09d(0x1be))/0x7)+parseInt(_0xd4b09d(0x1e7))/0x8+-parseInt(_0xd4b09d(0x245))/0x9+parseInt(_0xd4b09d(0x1ca))/0xa*(-parseInt(_0xd4b09d(0x234))/0xb);if(_0x138ff0===_0x1b888c)break;else _0x22d0b0['push'](_0x22d0b0['shift']());}catch(_0x150f12){_0x22d0b0['push'](_0x22d0b0['shift']());}}}(_0x588c,0xa5607));import{getContext,extension_settings}from'/scripts/extensions.js';import{characters}from'/script.js';import{world_names,loadWorldInfo,createNewWorldInfo,createWorldInfoEntry,saveWorldInfo}from'/scripts/world-info.js';import{extensionName}from'../utils/settings.js';import{getChatIdentifier}from'./lore.js';import{updateVectorIndex}from'./rag-processor.js';import{isGoogleEndpoint,convertToGoogleRequest,parseGoogleResponse,buildGoogleApiUrl}from'../core/utils/googleAdapter.js';import{intelligentPoll,createGooglePollingTask}from'../core/utils/pollingManager.js';function _0x5e80(_0x559c58,_0x469709){const _0x588c18=_0x588c();return _0x5e80=function(_0x5e802c,_0x2b3b38){_0x5e802c=_0x5e802c-0x1b2;let _0x412154=_0x588c18[_0x5e802c];return _0x412154;},_0x5e80(_0x559c58,_0x469709);}let ChatCompletionService=undefined;try{const module=await import(_0x222d01(0x1eb));ChatCompletionService=module['ChatCompletionService'],console[_0x222d01(0x23f)](_0x222d01(0x251));}catch(_0x57c67b){console['warn'](_0x222d01(0x1f9),_0x57c67b);}let isExpeditionRunning=![],manualStopRequested=![];async function callAmily2Model(_0x31d85a){const _0x3ec55f=_0x222d01,_0x180882=extension_settings[extensionName],{apiUrl:_0xd1336,apiKey:_0x421269,model:_0x96880a,temperature:_0x2320ce,maxTokens:_0x217d4f,forceProxyForCustomApi:_0x51d437}=_0x180882;if(!_0xd1336||!_0x96880a)return toastr['error'](_0x3ec55f(0x1bf),_0x3ec55f(0x1cc)),null;console[_0x3ec55f(0x203)](_0x3ec55f(0x231)+new Date()['toLocaleTimeString']()),console[_0x3ec55f(0x23f)](_0x3ec55f(0x221)),console['table'](_0x31d85a),console[_0x3ec55f(0x21c)]();try{let _0x183d11;if(_0x51d437){console[_0x3ec55f(0x23f)]('[大史官-外交部]\x20接到圣谕,执行“皇家密道”协议...');if(typeof ChatCompletionService===_0x3ec55f(0x1b5)||!ChatCompletionService?.['processRequest'])throw new Error(_0x3ec55f(0x1e9));const _0x33a5fa=isGoogleEndpoint(_0xd1336);let _0x2b39d2=_0xd1336;_0x33a5fa&&(_0x2b39d2=buildGoogleApiUrl(_0xd1336,_0x96880a),console[_0x3ec55f(0x23f)]('[大史官-皇家密道]\x20已为GoogleAPI构建完整路径:\x20'+_0x2b39d2));const _0xea91a4={'stream':![],'messages':_0x31d85a,'max_tokens':_0x217d4f,'temperature':_0x2320ce,'model':_0x96880a,'chat_completion_source':_0x3ec55f(0x1c9),'custom_url':_0x2b39d2,'reverse_proxy':_0x3ec55f(0x218)},_0x4bcf89=await ChatCompletionService['processRequest'](_0xea91a4,{},!![]);if(!_0x4bcf89||!_0x4bcf89[_0x3ec55f(0x20f)])throw new Error(_0x3ec55f(0x1d6));_0x183d11=_0x4bcf89[_0x3ec55f(0x20f)];}else{console[_0x3ec55f(0x23f)]('[大史官-外交部]\x20执行“帝国直通车”协议(直接通讯)...');const _0x351c76=isGoogleEndpoint(_0xd1336);let _0x1cc870;if(_0x351c76)_0x1cc870=buildGoogleApiUrl(_0xd1336,_0x96880a);else{let _0x1bc918=_0xd1336['trim']();_0x1bc918[_0x3ec55f(0x1c8)](_0x3ec55f(0x1f4))||_0x1bc918[_0x3ec55f(0x1c8)](_0x3ec55f(0x20a))?_0x1cc870=_0x1bc918:(_0x1bc918[_0x3ec55f(0x1c8)]('/')&&(_0x1bc918=_0x1bc918[_0x3ec55f(0x206)](0x0,-0x1)),_0x1bc918['endsWith']('/v1')&&(_0x1bc918=_0x1bc918[_0x3ec55f(0x206)](0x0,-0x3)),_0x1cc870=_0x1bc918+_0x3ec55f(0x1f4));}let _0x549f2c={'Content-Type':_0x3ec55f(0x1bb)};_0x351c76?_0xd1336[_0x3ec55f(0x1ef)](_0x3ec55f(0x1fc))||_0xd1336[_0x3ec55f(0x1ef)]('us-central1')?_0x549f2c[_0x3ec55f(0x1b3)]=_0x3ec55f(0x1fe)+_0x421269:_0x549f2c[_0x3ec55f(0x1c4)]=_0x421269:_0x549f2c['Authorization']='Bearer\x20'+_0x421269;let _0x2ea909;_0x351c76?_0x2ea909=JSON[_0x3ec55f(0x1fb)](convertToGoogleRequest({'model':_0x96880a,'messages':_0x31d85a,'temperature':_0x2320ce,'max_tokens':_0x217d4f})):_0x2ea909=JSON[_0x3ec55f(0x1fb)]({'model':_0x96880a,'messages':_0x31d85a,'temperature':_0x2320ce,'max_tokens':_0x217d4f,'stream':![]});const _0x11ad40=await fetch(_0x1cc870,{'method':_0x3ec55f(0x213),'headers':_0x549f2c,'body':_0x2ea909});if(!_0x11ad40['ok']){const _0x297046=await _0x11ad40[_0x3ec55f(0x237)]();throw new Error(_0x3ec55f(0x1f0)+_0x11ad40[_0x3ec55f(0x1b4)]+'\x20-\x20'+_0x297046);}let _0x159e5b=await _0x11ad40[_0x3ec55f(0x1d8)]();if(_0x351c76&&_0x159e5b[_0x3ec55f(0x23d)]&&_0x159e5b[_0x3ec55f(0x1b9)]){let _0x24b40d;try{const _0x5d002e=new URL(_0xd1336);_0x24b40d=_0x5d002e[_0x3ec55f(0x216)]+'//'+_0x5d002e[_0x3ec55f(0x1c6)];}catch{_0x24b40d=_0xd1336;}const _0x82e09a=createGooglePollingTask(_0x159e5b['name'],_0x24b40d,_0x549f2c),_0x1c94e0={'maxAttempts':0x5,'baseDelay':0xbb8,'shouldStop':_0x4027ce=>_0x4027ce[_0x3ec55f(0x24d)],'onError':_0xb21f0=>console['error'](_0x3ec55f(0x1c0),_0xb21f0)},_0x240ccf=await intelligentPoll(_0x82e09a,_0x1c94e0);if(!_0x240ccf[_0x3ec55f(0x211)])throw new Error(_0x3ec55f(0x220));_0x159e5b=_0x240ccf[_0x3ec55f(0x211)];}_0x183d11=_0x351c76?parseGoogleResponse(_0x159e5b)?.[_0x3ec55f(0x1d7)]?.[0x0]?.['message']?.[_0x3ec55f(0x20f)]:_0x159e5b?.['choices']?.[0x0]?.[_0x3ec55f(0x238)]?.['content'];}return _0x183d11;}catch(_0xd4aa9e){return console['error'](_0x3ec55f(0x240),_0xd4aa9e),toastr[_0x3ec55f(0x22f)](_0x3ec55f(0x1dc)+_0xd4aa9e['message'],_0x3ec55f(0x1ce)),null;}}const RUNNING_LOG_COMMENT=_0x222d01(0x1de),PROGRESS_SEAL_REGEX=/本条勿动【前(\d+)楼总结已完成】否则后续总结无法进行。$/;async function readGoldenLedgerProgress(_0x247817){const _0x50c77d=_0x222d01;if(!_0x247817)return 0x0;try{const _0x190f62=await loadWorldInfo(_0x247817);if(!_0x190f62||!_0x190f62[_0x50c77d(0x1bd)])return 0x0;const _0x4c4305=Object['values'](_0x190f62['entries'])[_0x50c77d(0x22c)](_0x256277=>_0x256277[_0x50c77d(0x1c2)]===RUNNING_LOG_COMMENT&&!_0x256277['disable']);if(!_0x4c4305)return 0x0;const _0x5db593=_0x4c4305[_0x50c77d(0x20f)][_0x50c77d(0x1c5)](PROGRESS_SEAL_REGEX);return _0x5db593?parseInt(_0x5db593[0x1],0xa):0x0;}catch(_0x4ce6e8){return console[_0x50c77d(0x22f)]('[大史官]\x20阅览《'+_0x247817+_0x50c77d(0x1bc),_0x4ce6e8),0x0;}}export async function checkAndTriggerAutoSummary(){const _0x353816=_0x222d01,_0xdfb71=extension_settings[extensionName];if(!_0xdfb71[_0x353816(0x1d3)])return;const _0x31823e=getContext();let _0x35704a=null;switch(_0xdfb71[_0x353816(0x1ba)]){case _0x353816(0x229):_0x35704a=characters[_0x31823e[_0x353816(0x239)]]?.[_0x353816(0x202)]?.[_0x353816(0x1e4)]?.[_0x353816(0x20b)];break;case _0x353816(0x1b7):const _0x4ab7da=await getChatIdentifier();_0x35704a=_0x353816(0x1cb)+_0x4ab7da;break;default:return;}if(!_0x35704a)return;const _0x12f1c9=await readGoldenLedgerProgress(_0x35704a),_0x406948=_0x31823e[_0x353816(0x20d)][_0x353816(0x1d9)],_0x4fb48c=_0x406948-_0x12f1c9;if(_0x4fb48c>=_0xdfb71['historiographySmallTriggerThreshold']){const _0x55da83=_0x12f1c9+0x1,_0x2d05a4=_0x406948;await executeManualSummary(_0x55da83,_0x2d05a4,!![]);}}export async function getAvailableWorldbooks(){return[...world_names];}export async function getLoresForWorldbook(_0x932d19){const _0x135ec8=_0x222d01;if(!_0x932d19)return[];try{const _0x37d438=await loadWorldInfo(_0x932d19);if(!_0x37d438||!_0x37d438['entries'])return[];return Object[_0x135ec8(0x1bd)](_0x37d438['entries'])[_0x135ec8(0x247)](([,_0x25c1ed])=>!_0x25c1ed[_0x135ec8(0x246)])[_0x135ec8(0x1b6)](([_0x5793b2,_0x40a326])=>({'key':_0x5793b2,'comment':_0x40a326[_0x135ec8(0x1c2)]||_0x135ec8(0x225)}));}catch(_0x22af57){return console[_0x135ec8(0x22f)](_0x135ec8(0x21a)+_0x932d19+_0x135ec8(0x24a),_0x22af57),[];}}function _0x588c(){const _0x199052=['通讯异常','翰林院','\x20层的对话历史...','[大史官]\x20重铸任务失败:','name2','historiographySmallAutoEnable','“写入史册”和“存入翰林院”均未启用,总结任务已完成但未保存。','微言录\x20(手动)','皇家信使未能从模型B带回有效情报。','choices','json','length','join','远征已在准备阶段遵令暂停!','与模型B通讯时发生异常:\x20','system','【敕史局】对话流水总帐','success','远征完毕','replace','远征已遵从您的敕令暂停!随时可以【继续远征】。','6WSsQfZ','extensions','当前角色未绑定主世界书。','送往翰林院的文书处理失败:\x20','7160784JdfJix','选定的楼层范围内无有效对话。','大史官无法使用“皇家密道”:缺少皇家信使(ChatCompletionService)。','宏史卷重铸','/scripts/custom-request.js','楼总结已完成】否则后续总结无法进行。','historiographyLargeJailbreakPrompt','》中的【微言录合集】...','includes','模型B召唤失败:\x20','is_user','loreKeywords','\x20批次战役准备中...\x20(','/v1/chat/completions','楼详细总结记录】\x0a','\x0a\x0a---\x0a\x0a【','远征开始','186918keCmXb','[大史官]\x20未能领取“皇家信使”的兵符,部分高级功能将受限。','amily2-expedition-state-change','stringify','aiplatform.googleapis.com','远征失败','Bearer\x20','远征军已在营中,无需下达停战敕令。','未知的史册写入目标,远征军无法开拔!','\x20-\x20国史馆','data','groupCollapsed','warning','user','slice','ceil','loreDepth','秒后接敌)','/v1beta/openai','world','找不到指定的史册条目,重铸任务中止。','chat','当前角色未绑定主世界书,远征军无法开拔!','content','请将以下多个零散的“详细总结记录”提炼并融合成一段连贯的章节历史。原文如下:\x0a\x0a','response','\x20层历史,分\x20','POST','正在将此份“微言录”送往翰林院进行向量化处理...','info','protocol','遵旨!正在为您熔铸\x20','/api/proxy','trim','[大史官]\x20检阅《','historiographyLargeRefinePrompt','groupEnd','鸣金收兵','以下是依照顺序已发生剧情','dispatchEvent','轮询完成但未获得有效响应','【信函正文\x20(messages)】:','圣谕传达','historiographyWriteToLorebook','historiographySmallSummaryPrompt','无标题条目','\x20(宏史卷重铸)','编年史已成功更新!','\x20至\x20','character_main','圣谕悉知','assign','find','圣谕不明','国史馆','error','微言录\x20(自动)','[Amily2-大史官]\x20准备向模型B发送机密信函...\x20@\x20','24ZitXmz','请严格根据以下“对话记录”中的内容进行总结,不要添加任何额外信息。\x0a\x0a<对话记录>\x0a','11lJHiJk','翰林院已成功接收并索引了新的记忆碎片!','values','text','message','characterId','name1','远征途中遭遇重大挫折,任务中止!您可以随时【继续远征】。','未知的史册写入指令。','name','远征军已开拔!目标:','log','[大史官-通讯异常]','2213286qjBYmw','historiographySmallJailbreakPrompt','2069245uztSaA','停战敕令已下达!远征军将在完成当前批次的任务后休整。','286830yWjAVD','disable','filter','[翰林院]\x20向量化处理失败:','远征战役\x20(','》时出错:','\x20批次征服!','圣谕有误','done','\x0a','宏史卷重铸完毕','historiographyIngestToRag','[大史官]\x20已成功获颁“皇家信使”的召唤兵符。','写入国史馆时发生错误:\x20','Authorization','status','undefined','map','dedicated','史册条目中无可供重铸的内容。','metadata','lorebookTarget','application/json','》天机时出错:','entries','5720834CegTqH','API\x20URL或模型未配置,大史官无法召唤模型B。','[轮询错误]','loreActivationMode','comment','远征军已在途中,无需重复下令。','X-goog-api-key','match','host','史册已成功重铸,并保存于《','endsWith','custom','20697370KagReG','Amily2-Lore-','通讯中断','1kCQLHs'];_0x588c=function(){return _0x199052;};return _0x588c();}export async function executeManualSummary(_0x353296,_0x2f4b9f,_0x5e42b5=![]){const _0x4a48f0=_0x222d01,_0x46ca46=_0x5e42b5?_0x4a48f0(0x230):_0x4a48f0(0x1d5);toastr['info'](_0x4a48f0(0x217)+_0x353296+_0x4a48f0(0x228)+_0x2f4b9f+_0x4a48f0(0x1d0),_0x46ca46);const _0x437aed=getContext(),_0x484a40=_0x437aed[_0x4a48f0(0x20d)],_0x1ba366=extension_settings[extensionName],_0xb5c10b=_0x484a40[_0x4a48f0(0x206)](_0x353296,_0x2f4b9f+0x1);if(_0xb5c10b[_0x4a48f0(0x1d9)]===0x0){toastr['warning'](_0x4a48f0(0x1e8),_0x4a48f0(0x24c));return;}const _0x1009a0=_0x437aed[_0x4a48f0(0x23a)]||'用户',_0x23feeb=_0x437aed[_0x4a48f0(0x1d2)]||'角色',_0x134f68=_0xb5c10b['map'](_0x5d8129=>{const _0x4c055b=_0x4a48f0,_0x5f289a=_0x5d8129[_0x4c055b(0x1f1)]?_0x1009a0:_0x23feeb;return _0x5f289a+':\x20'+_0x5d8129['mes'][_0x4c055b(0x219)]();})[_0x4a48f0(0x1da)]('\x0a'),_0x1ba506=[{'role':_0x4a48f0(0x1dd),'content':_0x1ba366[_0x4a48f0(0x242)]},{'role':_0x4a48f0(0x1dd),'content':_0x1ba366[_0x4a48f0(0x224)]},{'role':_0x4a48f0(0x205),'content':_0x4a48f0(0x233)+_0x134f68+_0x4a48f0(0x24e)}],_0x40f366=await callAmily2Model(_0x1ba506);if(!_0x40f366)return;const _0x490797=_0x1ba366[_0x4a48f0(0x223)]??!![],_0x3897cc=_0x1ba366[_0x4a48f0(0x250)]??![];if(!_0x490797&&!_0x3897cc){toastr['warning'](_0x4a48f0(0x1d4),_0x46ca46);return;}if(_0x490797)try{let _0x5c2628=null;switch(_0x1ba366[_0x4a48f0(0x1ba)]){case _0x4a48f0(0x229):_0x5c2628=characters[_0x437aed[_0x4a48f0(0x239)]]?.[_0x4a48f0(0x202)]?.['extensions']?.['world'];if(!_0x5c2628)throw new Error(_0x4a48f0(0x1e5));break;case'dedicated':const _0x2cfbe3=await getChatIdentifier();_0x5c2628=_0x4a48f0(0x1cb)+_0x2cfbe3;!world_names[_0x4a48f0(0x1ef)](_0x5c2628)&&await createNewWorldInfo(_0x5c2628);break;default:throw new Error(_0x4a48f0(0x23c));}const _0x2972fd=await loadWorldInfo(_0x5c2628),_0x4279ad=Object[_0x4a48f0(0x236)](_0x2972fd['entries'])['find'](_0x39e149=>_0x39e149[_0x4a48f0(0x1c2)]===RUNNING_LOG_COMMENT&&!_0x39e149[_0x4a48f0(0x246)]),_0x2cd873='\x0a\x0a本条勿动【前'+_0x2f4b9f+_0x4a48f0(0x1ec),_0x2fcb7a=_0x4a48f0(0x1f6)+_0x353296+'楼至'+_0x2f4b9f+_0x4a48f0(0x1f5)+_0x40f366;if(_0x4279ad){const _0x422db5=_0x4279ad[_0x4a48f0(0x20f)]['replace'](PROGRESS_SEAL_REGEX,'')['trim']();_0x4279ad[_0x4a48f0(0x20f)]=_0x422db5+_0x2fcb7a+_0x2cd873;}else{const _0x2c3d05=_0x4a48f0(0x21e)+_0x2fcb7a,_0x44571c=createWorldInfoEntry(_0x5c2628,_0x2972fd),_0x2f2278=_0x1ba366[_0x4a48f0(0x1f2)]['split'](',')[_0x4a48f0(0x1b6)](_0x4405d=>_0x4405d[_0x4a48f0(0x219)]())['filter'](Boolean),_0x2ca0ad=_0x1ba366[_0x4a48f0(0x1c1)]==='always',_0x43ddcd={'before_char':0x0,'after_char':0x1,'before_an':0x2,'after_an':0x3,'at_depth':0x4};Object[_0x4a48f0(0x22b)](_0x44571c,{'comment':RUNNING_LOG_COMMENT,'content':_0x2c3d05+_0x2cd873,'key':_0x2f2278,'constant':_0x2ca0ad,'position':_0x43ddcd[_0x1ba366['loreInsertionPosition']]??0x4,'depth':_0x1ba366[_0x4a48f0(0x208)],'disable':![]});}await saveWorldInfo(_0x5c2628,_0x2972fd,!![]),toastr['success'](_0x4a48f0(0x227),_0x46ca46+_0x4a48f0(0x201));}catch(_0x4b9bfe){console[_0x4a48f0(0x22f)]('[大史官]\x20'+_0x46ca46+'写入国史馆失败:',_0x4b9bfe),toastr[_0x4a48f0(0x22f)](_0x4a48f0(0x1b2)+_0x4b9bfe[_0x4a48f0(0x238)],_0x4a48f0(0x22e));}if(_0x3897cc)try{toastr[_0x4a48f0(0x215)](_0x4a48f0(0x214),_0x4a48f0(0x1cf));const _0x788efc=_0x437aed['characterId'],_0xf21f08=await updateVectorIndex(_0x788efc,_0x40f366);if(_0xf21f08['success'])toastr[_0x4a48f0(0x1df)](_0x4a48f0(0x235),'翰林院');else throw new Error(_0xf21f08['error']);}catch(_0x22f9c3){console[_0x4a48f0(0x22f)](_0x4a48f0(0x248),_0x22f9c3),toastr['error'](_0x4a48f0(0x1e6)+_0x22f9c3['message'],_0x4a48f0(0x1cf));}}export async function executeRefinement(_0x3d4392,_0x24d1a6){const _0x3582bf=_0x222d01;toastr[_0x3582bf(0x215)]('遵旨!正在为您重铸《'+_0x3d4392+_0x3582bf(0x1ee),_0x3582bf(0x1ea));try{const _0x1e99b6=await loadWorldInfo(_0x3d4392),_0x5174ea=_0x1e99b6?.[_0x3582bf(0x1bd)][_0x24d1a6];if(!_0x5174ea){toastr[_0x3582bf(0x22f)](_0x3582bf(0x20c),_0x3582bf(0x24c));return;}const _0x33d8c3=_0x5174ea[_0x3582bf(0x20f)],_0x466e73=extension_settings[extensionName];let _0x4f4eff=_0x33d8c3,_0x9b1c52='',_0x228011=0x0;const _0x5f4eab=_0x33d8c3[_0x3582bf(0x1c5)](PROGRESS_SEAL_REGEX);_0x5f4eab&&(_0x9b1c52=_0x5f4eab[0x0],_0x228011=parseInt(_0x5f4eab[0x1],0xa),_0x4f4eff=_0x33d8c3[_0x3582bf(0x1e1)](PROGRESS_SEAL_REGEX,'')[_0x3582bf(0x219)]());if(!_0x4f4eff['trim']()){toastr['warning'](_0x3582bf(0x1b8),'国库空虚');return;}const _0x4e6fe8=[{'role':_0x3582bf(0x1dd),'content':_0x466e73[_0x3582bf(0x1ed)]},{'role':'system','content':_0x466e73[_0x3582bf(0x21b)]},{'role':'user','content':_0x3582bf(0x210)+_0x4f4eff}],_0x3604ac=await callAmily2Model(_0x4e6fe8);if(!_0x3604ac)return;const _0x21b920='以下内容是【1楼-'+_0x228011+'楼】已发生的剧情回顾。\x0a\x0a---\x0a\x0a',_0x284f2f=_0x21b920+_0x3604ac;_0x5174ea['content']=_0x284f2f+('\x0a\x0a'+_0x9b1c52),_0x5174ea['comment']=_0x5174ea['comment'][_0x3582bf(0x1e1)](/\s*\(已精炼\)|\s*\(宏史卷重铸\)/g,''),_0x5174ea[_0x3582bf(0x1c2)]+=_0x3582bf(0x226),await saveWorldInfo(_0x3d4392,_0x1e99b6,!![]),toastr['success'](_0x3582bf(0x1c7)+_0x3d4392+'》!',_0x3582bf(0x24f));}catch(_0x3672e5){console[_0x3582bf(0x22f)](_0x3582bf(0x1d1),_0x3672e5),toastr[_0x3582bf(0x22f)]('重铸史册时发生错误。','国史馆');}}export async function executeExpedition(){const _0x4fc7c7=_0x222d01;if(isExpeditionRunning){toastr[_0x4fc7c7(0x215)](_0x4fc7c7(0x1c3),_0x4fc7c7(0x22a));return;}isExpeditionRunning=!![],manualStopRequested=![],document[_0x4fc7c7(0x21f)](new CustomEvent(_0x4fc7c7(0x1fa),{'detail':{'isRunning':!![]}}));try{const _0x531d98=extension_settings[extensionName],_0x44db95=getContext();let _0x196f08=null;switch(_0x531d98[_0x4fc7c7(0x1ba)]){case'character_main':_0x196f08=characters[_0x44db95[_0x4fc7c7(0x239)]]?.['data']?.[_0x4fc7c7(0x1e4)]?.[_0x4fc7c7(0x20b)];if(!_0x196f08){toastr[_0x4fc7c7(0x22f)](_0x4fc7c7(0x20e),_0x4fc7c7(0x22d)),isExpeditionRunning=![],document[_0x4fc7c7(0x21f)](new CustomEvent(_0x4fc7c7(0x1fa),{'detail':{'isRunning':![],'manualStop':![]}}));return;}break;case _0x4fc7c7(0x1b7):const _0x1fd508=await getChatIdentifier();_0x196f08=_0x4fc7c7(0x1cb)+_0x1fd508;break;default:toastr[_0x4fc7c7(0x22f)](_0x4fc7c7(0x200),'圣谕不明'),isExpeditionRunning=![],document[_0x4fc7c7(0x21f)](new CustomEvent(_0x4fc7c7(0x1fa),{'detail':{'isRunning':![],'manualStop':![]}}));return;}const _0x114b1b=await readGoldenLedgerProgress(_0x196f08),_0x1454a5=_0x44db95[_0x4fc7c7(0x20d)][_0x4fc7c7(0x1d9)],_0x3d79fc=_0x1454a5-_0x114b1b;if(_0x3d79fc<=0x0){toastr[_0x4fc7c7(0x215)]('国史已是最新,远征军无需出动。','凯旋'),isExpeditionRunning=![],document['dispatchEvent'](new CustomEvent(_0x4fc7c7(0x1fa),{'detail':{'isRunning':![],'manualStop':![]}}));return;}const _0x1aa481=_0x531d98['historiographySmallTriggerThreshold'],_0x4fa01a=Math[_0x4fc7c7(0x207)](_0x3d79fc/_0x1aa481);toastr[_0x4fc7c7(0x215)](_0x4fc7c7(0x23e)+_0x3d79fc+_0x4fc7c7(0x212)+_0x4fa01a+_0x4fc7c7(0x24b),_0x4fc7c7(0x1f7));let _0x2a5f9a=_0x114b1b;for(let _0x3c17ef=0x0;_0x3c17ef<_0x4fa01a;_0x3c17ef++){if(manualStopRequested){toastr[_0x4fc7c7(0x204)](_0x4fc7c7(0x1e2),_0x4fc7c7(0x21d));break;}const _0x5bac12=_0x2a5f9a+0x1,_0x465c20=Math['min'](_0x2a5f9a+_0x1aa481,_0x1454a5),_0x40cb57=_0x4fc7c7(0x249)+(_0x3c17ef+0x1)+'/'+_0x4fa01a+')',_0x18b24d=0x7d0;_0x3c17ef>0x0&&(toastr['info']('第\x20'+(_0x3c17ef+0x1)+_0x4fc7c7(0x1f3)+_0x18b24d/0x3e8+_0x4fc7c7(0x209),_0x40cb57),await new Promise(_0x4bca3d=>setTimeout(_0x4bca3d,_0x18b24d)));if(manualStopRequested){toastr[_0x4fc7c7(0x204)](_0x4fc7c7(0x1db),_0x4fc7c7(0x21d));break;}await executeManualSummary(_0x5bac12,_0x465c20,!![]),_0x2a5f9a=_0x465c20;}!manualStopRequested&&toastr['success']('凯旋!远征大捷!所有未载之史均已化为帝国永恒的记忆!',_0x4fc7c7(0x1e0));}catch(_0x5f3ed1){console[_0x4fc7c7(0x22f)]('[大史官-远征失败]',_0x5f3ed1),toastr[_0x4fc7c7(0x22f)](_0x4fc7c7(0x23b),_0x4fc7c7(0x1fd));}finally{isExpeditionRunning=![],document[_0x4fc7c7(0x21f)](new CustomEvent(_0x4fc7c7(0x1fa),{'detail':{'isRunning':![],'manualStop':manualStopRequested}}));}}export function stopExpedition(){const _0x1d522d=_0x222d01;isExpeditionRunning?(manualStopRequested=!![],toastr[_0x1d522d(0x215)](_0x1d522d(0x244),_0x1d522d(0x222))):toastr['warning'](_0x1d522d(0x1ff),_0x1d522d(0x22a));}