diff --git a/core/summarizer.js b/core/summarizer.js index 90375ba..4cb056c 100644 --- a/core/summarizer.js +++ b/core/summarizer.js @@ -1 +1 @@ -(function(_0x31e857,_0xfaa44d){const _0x4e3d60=_0x419e,_0x2c5f8a=_0x31e857();while(!![]){try{const _0x6c9d58=-parseInt(_0x4e3d60(0xf4))/0x1+-parseInt(_0x4e3d60(0xd5))/0x2*(parseInt(_0x4e3d60(0x9f))/0x3)+-parseInt(_0x4e3d60(0xe3))/0x4*(-parseInt(_0x4e3d60(0x93))/0x5)+-parseInt(_0x4e3d60(0xa6))/0x6*(-parseInt(_0x4e3d60(0xb6))/0x7)+parseInt(_0x4e3d60(0xeb))/0x8+parseInt(_0x4e3d60(0xf1))/0x9*(-parseInt(_0x4e3d60(0xa0))/0xa)+parseInt(_0x4e3d60(0xda))/0xb*(parseInt(_0x4e3d60(0xec))/0xc);if(_0x6c9d58===_0xfaa44d)break;else _0x2c5f8a['push'](_0x2c5f8a['shift']());}catch(_0x57a401){_0x2c5f8a['push'](_0x2c5f8a['shift']());}}}(_0x5693,0x37c19));import{extension_settings,getContext}from'/scripts/extensions.js';import{characters}from'/script.js';import{world_info}from'/scripts/world-info.js';import{extensionName}from'../utils/settings.js';import{extractContentByTag,replaceContentByTag,extractFullTagBlock}from'../utils/tagProcessor.js';import{isGoogleEndpoint,convertToGoogleRequest,parseGoogleResponse,buildGoogleApiUrl,buildPlotOptimizationGoogleRequest,parsePlotOptimizationGoogleResponse}from'./utils/googleAdapter.js';import{applyExclusionRules}from'./utils/rag-tag-extractor.js';function _0x419e(_0x912c1a,_0x8e1609){const _0x56936b=_0x5693();return _0x419e=function(_0x419ee2,_0x472742){_0x419ee2=_0x419ee2-0x91;let _0x4241bd=_0x56936b[_0x419ee2];return _0x4241bd;},_0x419e(_0x912c1a,_0x8e1609);}import{getCombinedWorldbookContent,getPlotOptimizedWorldbookContent}from'./lore.js';import{getBatchFillerFlowTemplate,convertTablesToCsvString,updateTableFromText,saveStateToMessage,getMemoryState}from'./table-system/manager.js';import{saveChat}from'/script.js';import{renderTables}from'../ui/table-bindings.js';import{getPresetPrompts,getMixedOrder}from'../PresetSettings/index.js';function _0x5693(){const _0x378575=['optimized','59845PYcHnD','error','replace','<世界书内容>\x0a','trim','plot','world','mainPrompt','plot_optimization','slice','[Amily2号-原始回复]','[Amily2-外交部]\x20未能获取AI响应内容','9cfJiyx','55800YWzujc','main-api','optimizationExclusionRules','请你在优化完成后,在正文标签外结合最新消息中的剧情、当前的表格内容进行填表任务:\x0a\x0a','preOptimizationTextUpdated','dispatchEvent','1890evAPjX','-->','[上下文参考]:\x0a','\x0a','timeEnd','toLocaleTimeString','name2','AMILY2_SYSTEM_PARALYZED','chat',']\x20发送给AI的最终请求内容','filter','\x5c$&','is_user','Start\x20and\x20end\x20labels\x20correctly.','AI响应为空或格式不正确。','message','3955CpCmtM','Amily2号任务失败:\x20','join','plotOpt_tableEnabled','[Amily2-内容排除]\x20正文优化内容排除规则已生效,文本长度从\x20','\x20变为\x20','优化任务总耗时','[Amily2号-最终国书内容\x20(发往AI)]','log','[Amily2-外交部]\x20目标标签\x20<','\x0aOptimisation\x20and\x20form\x20filling\x20have\x20been\x20completed.','worldbook','extensions','{{{Amily2TableData}}}','##以下内容是故事发生的剧情中提取出的内容,已经转化为表格形式呈现给你,请将以下内容作为后续剧情的一部分参考:<表格内容>\x0a{{{Amily2TableDataContent}}}','optimizationExclusionEnabled','contextLimit','plotTag','[目标内容]:\x0a','push','optimizationEnabled','name1','158820hqrZzb','plotOpt_ratePersonal','[世界书档案]:\x0a','groupCollapsed','dir','2024ajgvYp','剧情优化任务失败:\x20','user','(AI)最新消息,[核心处理内容]:','plotOpt_enabled','lastPreOptimizationText','characterId','>,将保留原始消息。','coreContent','144srHkfU',']\x20用户输入为空,跳过优化。','>\x20未找到或为空,或内容已被完全排除,优化任务已跳过。',']\x20剧情优化任务发生严重错误:','[Amily2-制裁]\x20系统完整性已受损,所有外交活动被无限期中止。','systemPrompt','plotOpt_rateErotic','剧情优化任务总耗时','550928MsaLys','18168vxjrBm','','map','prompt','time','648BtLcYm','(用户)最新消息:','plotOpt_systemPrompt','87934aRqTng','plotOpt_mainPrompt','type','optimization','','mes','filling_mode','worldbookEnabled','plotOpt_contextLimit','{{{Amily2TableDataContent}}}',']\x20从AI收到的原始回复','system'];_0x5693=function(){return _0x378575;};return _0x5693();}import{callAI,generateRandomSeed}from'./api.js';export async function processOptimization(_0x1d02cd,_0x192388){const _0x266d16=_0x419e;if(window[_0x266d16(0xad)]===!![])return console[_0x266d16(0x94)](_0x266d16(0xe7)),null;const _0x434c2e=extension_settings[extensionName],_0x4ed1d8=_0x434c2e[_0x266d16(0xd3)];if(!_0x4ed1d8)return null;console[_0x266d16(0xd8)]('[Amily2号-正文优化任务]\x20'+new Date()[_0x266d16(0xab)]()),console[_0x266d16(0xf0)]('优化任务总耗时');try{const _0x32c935=_0x1d02cd[_0x266d16(0xf9)];let _0x3cb828=_0x32c935;if(_0x434c2e[_0x266d16(0xce)]&&_0x434c2e[_0x266d16(0xa2)]?.['length']>0x0){const _0xb36678=_0x3cb828[_0x266d16(0xc4)];_0x3cb828=applyExclusionRules(_0x3cb828,_0x434c2e[_0x266d16(0xa2)]);const _0x177592=_0x3cb828[_0x266d16(0xc4)];_0xb36678!==_0x177592&&console[_0x266d16(0xbe)](_0x266d16(0xba)+_0xb36678+_0x266d16(0xbb)+_0x177592+'。');}const _0x1197e2=_0x434c2e['optimizationTargetTag']||'content',_0x113432=extractFullTagBlock(_0x3cb828,_0x1197e2);if(!_0x113432||extractContentByTag(_0x113432,_0x1197e2)?.[_0x266d16(0x97)]()==='')return console[_0x266d16(0xbe)](_0x266d16(0xbf)+_0x1197e2+_0x266d16(0xe5)),console[_0x266d16(0xaa)](_0x266d16(0xbc)),console['groupEnd'](),null;_0x3cb828=_0x113432;const _0x26717c=getContext(),_0x3e073c=_0x26717c[_0x266d16(0xd4)]||'用户',_0x1e8b5b=_0x26717c[_0x266d16(0xac)]||'角色',_0x3ebeb2=_0x192388[_0x266d16(0xc4)]>0x0&&_0x192388[_0x192388[_0x266d16(0xc4)]-0x1][_0x266d16(0xb2)]?_0x192388[_0x192388[_0x266d16(0xc4)]-0x1]:null,_0x50c15b=_0x3ebeb2?_0x192388['slice'](0x0,-0x1):_0x192388,_0x8289e9=_0x50c15b['map'](_0xe3acc6=>_0xe3acc6[_0x266d16(0xf9)]&&_0xe3acc6[_0x266d16(0xf9)]['trim']()?(_0xe3acc6[_0x266d16(0xb2)]?_0x3e073c:_0x1e8b5b)+':\x20'+_0xe3acc6[_0x266d16(0xf9)][_0x266d16(0x97)]():null)['filter'](Boolean)['join']('\x0a');let _0x21a43d='';if(_0x434c2e[_0x266d16(0xfb)]){const _0x4fe8cc=characters[_0x26717c[_0x266d16(0xe0)]];_0x4fe8cc?.[_0x266d16(0xc8)]?.[_0x266d16(0xcb)]?.['world']&&(_0x21a43d=await getCombinedWorldbookContent(_0x4fe8cc['data'][_0x266d16(0xcb)][_0x266d16(0x99)]));}const _0xef0435=getPresetPrompts(_0x266d16(0xf7)),_0x182a8b=[{'role':_0x266d16(0x91),'content':generateRandomSeed()}];let _0x14aef5=_0x3ebeb2?_0x3e073c+_0x266d16(0xf2)+_0x3ebeb2[_0x266d16(0xf9)]+'\x0a'+_0x1e8b5b+_0x266d16(0xdd)+_0x3cb828:_0x1e8b5b+_0x266d16(0xdd)+_0x3cb828;const _0x15887a=_0x434c2e[_0x266d16(0xfa)]||_0x266d16(0xa1);window[_0x266d16(0xdf)]=_0x14aef5,document[_0x266d16(0xa5)](new CustomEvent(_0x266d16(0xa4)));const _0x3a0386=getMixedOrder('optimization')||[];let _0x1207b0=0x0;for(const _0x5340a3 of _0x3a0386){if(_0x5340a3[_0x266d16(0xf6)]==='prompt')_0xef0435&&_0xef0435[_0x1207b0]&&(_0x182a8b[_0x266d16(0xd2)](_0xef0435[_0x1207b0]),_0x1207b0++);else{if(_0x5340a3[_0x266d16(0xf6)]===_0x266d16(0xc5))switch(_0x5340a3['id']){case _0x266d16(0x9a):_0x434c2e[_0x266d16(0x9a)]?.[_0x266d16(0x97)]()&&_0x182a8b[_0x266d16(0xd2)]({'role':_0x266d16(0x91),'content':_0x434c2e['mainPrompt'][_0x266d16(0x97)]()});break;case _0x266d16(0xe8):_0x434c2e[_0x266d16(0xe8)]?.[_0x266d16(0x97)]()&&_0x182a8b[_0x266d16(0xd2)]({'role':_0x266d16(0x91),'content':_0x434c2e['systemPrompt'][_0x266d16(0x97)]()});break;case _0x266d16(0xca):_0x21a43d&&_0x182a8b[_0x266d16(0xd2)]({'role':_0x266d16(0xdc),'content':_0x266d16(0xd7)+_0x21a43d});break;case'history':_0x8289e9&&_0x182a8b['push']({'role':_0x266d16(0xdc),'content':_0x266d16(0xa8)+_0x8289e9});break;case _0x266d16(0xc2):if(_0x4ed1d8&&_0x15887a===_0x266d16(0x92)){const _0x34a705=getBatchFillerFlowTemplate(),_0x386df5=convertTablesToCsvString(),_0x5be1b4=_0x34a705[_0x266d16(0x95)](_0x266d16(0xcc),_0x386df5);_0x182a8b[_0x266d16(0xd2)]({'role':'user','content':_0x14aef5}),_0x182a8b['push']({'role':_0x266d16(0x91),'content':_0x266d16(0xa3)+_0x5be1b4+_0x266d16(0xc9)});}else _0x182a8b[_0x266d16(0xd2)]({'role':_0x266d16(0xdc),'content':_0x266d16(0xd1)+_0x14aef5+_0x266d16(0xb3)});break;}}}window[_0x266d16(0xdf)]=_0x14aef5,document[_0x266d16(0xa5)](new CustomEvent(_0x266d16(0xa4))),console['groupCollapsed'](_0x266d16(0xbd)),console[_0x266d16(0xd9)](_0x182a8b),console[_0x266d16(0xc6)]();const _0x4611db=await callAI(_0x182a8b);if(!_0x4611db)return console[_0x266d16(0x94)](_0x266d16(0x9e)),null;console[_0x266d16(0xd8)](_0x266d16(0x9d)),console[_0x266d16(0xbe)](_0x4611db),console[_0x266d16(0xc6)]();let _0x2897df=_0x32c935;const _0x2bf1d5=extractContentByTag(_0x4611db,_0x1197e2);_0x2bf1d5?.[_0x266d16(0x97)]()?_0x2897df=replaceContentByTag(_0x32c935,_0x1197e2,_0x2bf1d5):console['warn']('[Amily2-外交部]\x20AI的回复中未找到有效的目标标签\x20<'+_0x1197e2+_0x266d16(0xe1));if(_0x4ed1d8&&_0x15887a===_0x266d16(0x92)){await updateTableFromText(_0x4611db);const _0x2053d4=getContext();if(_0x2053d4['chat']&&_0x2053d4[_0x266d16(0xae)][_0x266d16(0xc4)]>0x0){const _0x3b4dd1=_0x2053d4[_0x266d16(0xae)][_0x2053d4[_0x266d16(0xae)][_0x266d16(0xc4)]-0x1];saveStateToMessage(getMemoryState(),_0x3b4dd1)&&(await saveChat(),renderTables(),console[_0x266d16(0xbe)]('[Amily2-优化中填表]\x20流程已全部完成,并已强制保存和刷新UI。'));}}const _0x430beb={'optimizedContent':_0x2897df};return console['timeEnd'](_0x266d16(0xbc)),console[_0x266d16(0xc6)](),_0x430beb;}catch(_0x54adfd){return console[_0x266d16(0x94)](_0x266d16(0xc7),_0x54adfd),toastr[_0x266d16(0x94)](_0x266d16(0xb7)+_0x54adfd['message'],'严重错误'),console[_0x266d16(0xaa)](_0x266d16(0xbc)),console[_0x266d16(0xc6)](),null;}}export async function processPlotOptimization(_0x150966,_0x4cfd87){const _0x1b0e8f=_0x419e,_0x2368c6=extension_settings[extensionName];if(_0x2368c6[_0x1b0e8f(0xde)]===![])return null;console[_0x1b0e8f(0xd8)]('['+extensionName+']\x20剧情优化任务启动...\x20'+new Date()[_0x1b0e8f(0xab)]()),console['time'](_0x1b0e8f(0xea));try{const _0x265d2f=_0x150966[_0x1b0e8f(0xf9)];if(!_0x265d2f||_0x265d2f[_0x1b0e8f(0x97)]()==='')return console['log']('['+extensionName+_0x1b0e8f(0xe4)),null;const _0x49d241=getContext(),_0x2edbb8=_0x49d241[_0x1b0e8f(0xd4)]||'用户',_0x5d07e3=_0x49d241[_0x1b0e8f(0xac)]||'角色',_0x3b6d33=getPresetPrompts(_0x1b0e8f(0x9b)),_0x3506b9=[{'role':_0x1b0e8f(0x91),'content':generateRandomSeed()}],_0x2833aa={'sulv1':_0x2368c6['plotOpt_rateMain']??0x1,'sulv2':_0x2368c6[_0x1b0e8f(0xd6)]??0x1,'sulv3':_0x2368c6[_0x1b0e8f(0xe9)]??0x1,'sulv4':_0x2368c6[_0x1b0e8f(0xc3)]??0x1};let _0xafa2d7=_0x2368c6[_0x1b0e8f(0xf5)]||'',_0x3aad51=_0x2368c6[_0x1b0e8f(0xf3)]||'';for(const _0x997c51 in _0x2833aa){const _0x2f2586=_0x2833aa[_0x997c51],_0x5b95e8=new RegExp(_0x997c51['replace'](/[-\/\\^$*+?.()|[\]{}]/g,_0x1b0e8f(0xb1)),'g');_0xafa2d7=_0xafa2d7['replace'](_0x5b95e8,_0x2f2586),_0x3aad51=_0x3aad51['replace'](_0x5b95e8,_0x2f2586);}const _0x37ee1f=await getPlotOptimizedWorldbookContent(_0x49d241,_0x2368c6);let _0x3bf0a1='';if(_0x2368c6[_0x1b0e8f(0xb9)])try{const {convertTablesToCsvStringForContentOnly:_0x3b95b6}=await import('./table-system/manager.js'),_0x29b5d4=_0x1b0e8f(0xcd),_0x335559=_0x3b95b6();_0x335559[_0x1b0e8f(0x97)]()&&(_0x3bf0a1=_0x29b5d4['replace'](_0x1b0e8f(0xfd),_0x335559));}catch(_0x3e8e84){console[_0x1b0e8f(0x94)]('[Amily2-表格系统]\x20注入表格内容时出错:',_0x3e8e84);}let _0x128154='';const _0x5402a3=_0x2368c6[_0x1b0e8f(0xfc)]||0x0;if(_0x5402a3>0x0&&_0x4cfd87[_0x1b0e8f(0xc4)]>0x0){const _0x1096c1=_0x4cfd87[_0x1b0e8f(0x9c)](-_0x5402a3);_0x128154=_0x1096c1[_0x1b0e8f(0xee)](_0x4a34ee=>{const _0x3cef6d=_0x1b0e8f;if(_0x4a34ee['mes']&&_0x4a34ee[_0x3cef6d(0xf9)][_0x3cef6d(0x97)]()){const _0x2bc50d=[{'start':_0x3cef6d(0xc0),'end':_0x3cef6d(0xa7)}],_0x15c1ea=applyExclusionRules(_0x4a34ee[_0x3cef6d(0xf9)][_0x3cef6d(0x97)](),_0x2bc50d);return _0x15c1ea?(_0x4a34ee['is_user']?_0x2edbb8:_0x5d07e3)+':\x20'+_0x15c1ea:null;}return null;})[_0x1b0e8f(0xb0)](Boolean)[_0x1b0e8f(0xb8)]('\x0a');}const _0x4b6bb8=getMixedOrder(_0x1b0e8f(0x9b))||[];let _0x2ef47e=0x0;for(const _0x4bdb39 of _0x4b6bb8){if(_0x4bdb39['type']===_0x1b0e8f(0xef))_0x3b6d33&&_0x3b6d33[_0x2ef47e]&&(_0x3506b9[_0x1b0e8f(0xd2)](_0x3b6d33[_0x2ef47e]),_0x2ef47e++);else{if(_0x4bdb39['type']===_0x1b0e8f(0xc5))switch(_0x4bdb39['id']){case _0x1b0e8f(0x9a):_0xafa2d7['trim']()&&_0x3506b9['push']({'role':_0x1b0e8f(0x91),'content':_0xafa2d7[_0x1b0e8f(0x97)]()});break;case'systemPrompt':_0x3aad51[_0x1b0e8f(0x97)]()&&_0x3506b9[_0x1b0e8f(0xd2)]({'role':'system','content':_0x3aad51[_0x1b0e8f(0x97)]()});break;case _0x1b0e8f(0xca):_0x37ee1f[_0x1b0e8f(0x97)]()&&_0x3506b9['push']({'role':_0x1b0e8f(0xdc),'content':_0x1b0e8f(0x96)+_0x37ee1f[_0x1b0e8f(0x97)]()+_0x1b0e8f(0xf8)});break;case'tableEnabled':_0x3bf0a1&&_0x3506b9[_0x1b0e8f(0xd2)]({'role':_0x1b0e8f(0xdc),'content':_0x3bf0a1});break;case _0x1b0e8f(0xcf):_0x128154&&_0x3506b9[_0x1b0e8f(0xd2)]({'role':_0x1b0e8f(0xdc),'content':'<前文内容>\x0a'+_0x128154+_0x1b0e8f(0xa9)});break;case _0x1b0e8f(0xe2):_0x3506b9[_0x1b0e8f(0xd2)]({'role':'user','content':'[核心处理内容]:\x0a'+_0x265d2f});break;case _0x1b0e8f(0xd0):_0x3506b9['push']({'role':'assistant','content':_0x1b0e8f(0xed)});break;}}}console['groupCollapsed']('['+extensionName+_0x1b0e8f(0xaf)),console[_0x1b0e8f(0xd9)](_0x3506b9),console[_0x1b0e8f(0xc6)]();const _0x2ff3f1=await callAI(_0x3506b9);if(!_0x2ff3f1)throw new Error(_0x1b0e8f(0xb4));console[_0x1b0e8f(0xd8)]('['+extensionName+_0x1b0e8f(0xfe)),console[_0x1b0e8f(0xbe)](_0x2ff3f1),console[_0x1b0e8f(0xc6)]();const _0x363e6c=extractContentByTag(_0x2ff3f1,_0x1b0e8f(0x98)),_0x34b5ca=_0x363e6c?.[_0x1b0e8f(0x97)]()?_0x363e6c[_0x1b0e8f(0x97)]():_0x2ff3f1[_0x1b0e8f(0x97)]();if(_0x34b5ca){let _0x35dfd8='',_0x2c02b9=_0x2368c6['plotOpt_finalSystemDirective']?.[_0x1b0e8f(0x97)]()||'';const _0x454ca9={'sulv1':_0x2368c6[_0x1b0e8f(0xc1)]??0x1,'sulv2':_0x2368c6[_0x1b0e8f(0xd6)]??0x1,'sulv3':_0x2368c6[_0x1b0e8f(0xe9)]??0x1,'sulv4':_0x2368c6[_0x1b0e8f(0xc3)]??0x1};for(const _0x42e7d4 in _0x454ca9){const _0x274fbc=_0x454ca9[_0x42e7d4],_0x2cbd5d=new RegExp(_0x42e7d4[_0x1b0e8f(0x95)](/[-\/\\^$*+?.()|[\]{}]/g,_0x1b0e8f(0xb1)),'g');_0x2c02b9=_0x2c02b9[_0x1b0e8f(0x95)](_0x2cbd5d,_0x274fbc);}return _0x2c02b9?_0x35dfd8=_0x2c02b9[_0x1b0e8f(0x95)](_0x1b0e8f(0xed),_0x34b5ca):_0x35dfd8=_0x34b5ca,{'contentToAppend':_0x35dfd8};}else return null;}catch(_0x4acee7){return console[_0x1b0e8f(0x94)]('['+extensionName+_0x1b0e8f(0xe6),_0x4acee7),toastr[_0x1b0e8f(0x94)](_0x1b0e8f(0xdb)+_0x4acee7[_0x1b0e8f(0xb5)],'严重错误'),null;}finally{console[_0x1b0e8f(0xaa)](_0x1b0e8f(0xea)),console[_0x1b0e8f(0xc6)]();}} +(function(_0x2f3d5d,_0x1723ba){const _0x5a4f58=_0x18e0,_0x203c7c=_0x2f3d5d();while(!![]){try{const _0x4bba3e=-parseInt(_0x5a4f58(0x18e))/0x1*(parseInt(_0x5a4f58(0x19b))/0x2)+parseInt(_0x5a4f58(0x1e8))/0x3+parseInt(_0x5a4f58(0x1fd))/0x4+-parseInt(_0x5a4f58(0x1b3))/0x5*(parseInt(_0x5a4f58(0x1ec))/0x6)+-parseInt(_0x5a4f58(0x1c0))/0x7*(parseInt(_0x5a4f58(0x202))/0x8)+-parseInt(_0x5a4f58(0x1fe))/0x9+parseInt(_0x5a4f58(0x19e))/0xa;if(_0x4bba3e===_0x1723ba)break;else _0x203c7c['push'](_0x203c7c['shift']());}catch(_0x38c13a){_0x203c7c['push'](_0x203c7c['shift']());}}}(_0x5a58,0x2d398));import{extension_settings,getContext}from'/scripts/extensions.js';import{characters}from'/script.js';import{world_info}from'/scripts/world-info.js';function _0x18e0(_0x53f90b,_0x2c46e4){const _0x5a5863=_0x5a58();return _0x18e0=function(_0x18e039,_0x3e3e37){_0x18e039=_0x18e039-0x18e;let _0x507735=_0x5a5863[_0x18e039];return _0x507735;},_0x18e0(_0x53f90b,_0x2c46e4);}import{extensionName}from'../utils/settings.js';import{extractContentByTag,replaceContentByTag,extractFullTagBlock}from'../utils/tagProcessor.js';import{isGoogleEndpoint,convertToGoogleRequest,parseGoogleResponse,buildGoogleApiUrl,buildPlotOptimizationGoogleRequest,parsePlotOptimizationGoogleResponse}from'./utils/googleAdapter.js';import{applyExclusionRules}from'./utils/rag-tag-extractor.js';import{getCombinedWorldbookContent,getPlotOptimizedWorldbookContent}from'./lore.js';import{getBatchFillerFlowTemplate,convertTablesToCsvString,updateTableFromText,saveStateToMessage,getMemoryState}from'./table-system/manager.js';import{saveChat}from'/script.js';function _0x5a58(){const _0xae13cd=['plotOpt_rateErotic',']\x20优化任务在API调用后被中止。','[Amily2-外交部]\x20AI的回复中未找到有效的目标标签\x20<','is_user','toLocaleTimeString','system','error','[核心处理内容]:\x0a','plotOpt_rateCuckold','tableEnabled','##以下内容是故事发生的剧情中提取出的内容,已经转化为表格形式呈现给你,请将以下内容作为后续剧情的一部分参考:<表格内容>\x0a{{{Amily2TableDataContent}}}','jqyhEnabled','(AI)最新消息,[核心处理内容]:','严重错误','optimizationExclusionRules','mes','push','','15vypqHl','join','[Amily2-内容排除]\x20正文优化内容排除规则已生效,文本长度从\x20','warn','optimizationExclusionEnabled','plotOpt_contextLimit','plotOpt_ratePersonal','mainPrompt','[Amily2-优化中填表]\x20流程已全部完成,并已强制保存和刷新UI。',']\x20优化任务在尝试前被中止。','optimizationTargetTag','plotOpt_enabled','Start\x20and\x20end\x20labels\x20correctly.','10262KJkctl','plot_optimization',']\x20发送给AI的最终请求内容','[Amily2-制裁]\x20系统完整性已受损,所有外交活动被无限期中止。','optimized',']\x20从AI收到的原始回复','[Amily2-外交部]\x20发生严重错误:','message','[Amily2-外交部]\x20目标标签\x20<','优化失败','world','\x20次尝试获取响应失败,AI返回为空。','[目标内容]:\x0a','\x0aOptimisation\x20and\x20form\x20filling\x20have\x20been\x20completed.',')\x20且未获得符合要求的回复,优化任务中止。','plotOpt_finalSystemDirective','name2','\x20次尝试后失败。','groupEnd','Amily2号任务失败:\x20','>\x20未找到或为空,或内容已被完全排除,优化任务已跳过。','\x5c$&','time','dispatchEvent','type','569744BjLHhX','2184525gNGepf','[Amily2-外交部]\x20未能获取AI响应内容','plotOpt_rateMain','coreContent','184lLdYpz','map','length','groupCollapsed','\x0a','2630hgIXwi','lastPreOptimizationText','timeEnd',']\x20剧情优化任务启动...\x20','optimizationEnabled','剧情优化在\x20','<世界书内容>\x0a','plot','replace',']\x20剧情优化任务发生严重错误:',')\x20符合要求。','extensions','(用户)最新消息:','6XVAaWW','优化任务总耗时','data','5204040BntXLK',',小于100字符。','plotOpt_systemPrompt'];_0x5a58=function(){return _0xae13cd;};return _0x5a58();}import{renderTables}from'../ui/table-bindings.js';import{getPresetPrompts,getMixedOrder}from'../PresetSettings/index.js';import{callAI,generateRandomSeed}from'./api.js';import{callJqyhAI}from'./api/JqyhApi.js';export async function processOptimization(_0x272e8a,_0x1e9e80){const _0x327338=_0x18e0;if(window['AMILY2_SYSTEM_PARALYZED']===!![])return console[_0x327338(0x1a7)](_0x327338(0x1c3)),null;const _0x402ece=extension_settings[extensionName],_0x1652c3=_0x402ece[_0x327338(0x192)];if(!_0x1652c3)return null;console['groupCollapsed']('[Amily2号-正文优化任务]\x20'+new Date()['toLocaleTimeString']()),console[_0x327338(0x1fa)](_0x327338(0x19c));try{const _0x214fda=_0x272e8a['mes'];let _0x5bc433=_0x214fda;if(_0x402ece[_0x327338(0x1b7)]&&_0x402ece[_0x327338(0x1af)]?.[_0x327338(0x204)]>0x0){const _0x592cb6=_0x5bc433[_0x327338(0x204)];_0x5bc433=applyExclusionRules(_0x5bc433,_0x402ece[_0x327338(0x1af)]);const _0x251c3d=_0x5bc433[_0x327338(0x204)];_0x592cb6!==_0x251c3d&&console[_0x327338(0x1d3)](_0x327338(0x1b5)+_0x592cb6+'\x20变为\x20'+_0x251c3d+'。');}const _0x1f6f6f=_0x402ece[_0x327338(0x1bd)]||_0x327338(0x1df),_0x51f664=extractFullTagBlock(_0x5bc433,_0x1f6f6f);if(!_0x51f664||extractContentByTag(_0x51f664,_0x1f6f6f)?.['trim']()==='')return console[_0x327338(0x1d3)](_0x327338(0x1c8)+_0x1f6f6f+_0x327338(0x1f8)),console[_0x327338(0x190)]('优化任务总耗时'),console[_0x327338(0x1f6)](),null;_0x5bc433=_0x51f664;const _0x59290e=getContext(),_0x3d3a69=_0x59290e[_0x327338(0x1ea)]||'用户',_0x36ef0d=_0x59290e[_0x327338(0x1f4)]||'角色',_0x28d86d=_0x1e9e80['length']>0x0&&_0x1e9e80[_0x1e9e80[_0x327338(0x204)]-0x1][_0x327338(0x1a4)]?_0x1e9e80[_0x1e9e80[_0x327338(0x204)]-0x1]:null,_0x1029fd=_0x28d86d?_0x1e9e80[_0x327338(0x1d5)](0x0,-0x1):_0x1e9e80,_0x4c6c38=_0x1029fd['map'](_0x54eabe=>_0x54eabe['mes']&&_0x54eabe[_0x327338(0x1b0)][_0x327338(0x1d0)]()?(_0x54eabe[_0x327338(0x1a4)]?_0x3d3a69:_0x36ef0d)+':\x20'+_0x54eabe[_0x327338(0x1b0)][_0x327338(0x1d0)]():null)[_0x327338(0x1ed)](Boolean)[_0x327338(0x1b4)]('\x0a');let _0x4e8d2f='';if(_0x402ece[_0x327338(0x1ce)]){const _0x276744=characters[_0x59290e['characterId']];_0x276744?.[_0x327338(0x19d)]?.[_0x327338(0x199)]?.[_0x327338(0x1ca)]&&(_0x4e8d2f=await getCombinedWorldbookContent(_0x276744['data'][_0x327338(0x199)]['world']));}const _0x2d7370=getPresetPrompts(_0x327338(0x1ee)),_0x373c2d=[{'role':_0x327338(0x1a6),'content':generateRandomSeed()}];let _0xf1fe05=_0x28d86d?_0x3d3a69+_0x327338(0x19a)+_0x28d86d[_0x327338(0x1b0)]+'\x0a'+_0x36ef0d+_0x327338(0x1ad)+_0x5bc433:_0x36ef0d+_0x327338(0x1ad)+_0x5bc433;const _0x6ddf33=_0x402ece[_0x327338(0x1d1)]||_0x327338(0x1e2);window[_0x327338(0x18f)]=_0xf1fe05,document['dispatchEvent'](new CustomEvent('preOptimizationTextUpdated'));const _0x42abfd=getMixedOrder(_0x327338(0x1ee))||[];let _0x254582=0x0;for(const _0x52c52c of _0x42abfd){if(_0x52c52c['type']===_0x327338(0x1e6))_0x2d7370&&_0x2d7370[_0x254582]&&(_0x373c2d['push'](_0x2d7370[_0x254582]),_0x254582++);else{if(_0x52c52c['type']===_0x327338(0x1d9))switch(_0x52c52c['id']){case'mainPrompt':_0x402ece[_0x327338(0x1ba)]?.[_0x327338(0x1d0)]()&&_0x373c2d[_0x327338(0x1b1)]({'role':_0x327338(0x1a6),'content':_0x402ece[_0x327338(0x1ba)][_0x327338(0x1d0)]()});break;case _0x327338(0x1dd):_0x402ece[_0x327338(0x1dd)]?.[_0x327338(0x1d0)]()&&_0x373c2d[_0x327338(0x1b1)]({'role':'system','content':_0x402ece[_0x327338(0x1dd)][_0x327338(0x1d0)]()});break;case _0x327338(0x1e4):_0x4e8d2f&&_0x373c2d['push']({'role':'user','content':_0x327338(0x1e9)+_0x4e8d2f});break;case _0x327338(0x1e0):_0x4c6c38&&_0x373c2d[_0x327338(0x1b1)]({'role':_0x327338(0x1e1),'content':_0x327338(0x1dc)+_0x4c6c38});break;case'fillingMode':if(_0x1652c3&&_0x6ddf33===_0x327338(0x1c4)){const _0x16c264=getBatchFillerFlowTemplate(),_0x19392f=convertTablesToCsvString(),_0x45aa09=_0x16c264[_0x327338(0x196)](_0x327338(0x1ef),_0x19392f);_0x373c2d['push']({'role':'user','content':_0xf1fe05}),_0x373c2d[_0x327338(0x1b1)]({'role':_0x327338(0x1a6),'content':_0x327338(0x1d8)+_0x45aa09+_0x327338(0x1f1)});}else _0x373c2d[_0x327338(0x1b1)]({'role':'user','content':_0x327338(0x1cc)+_0xf1fe05+_0x327338(0x1bf)});break;}}}window['lastPreOptimizationText']=_0xf1fe05,document[_0x327338(0x1fb)](new CustomEvent('preOptimizationTextUpdated')),console[_0x327338(0x205)]('[Amily2号-最终国书内容\x20(发往AI)]'),console['dir'](_0x373c2d),console[_0x327338(0x1f6)]();const _0xcb03e8=await callAI(_0x373c2d);if(!_0xcb03e8)return console[_0x327338(0x1a7)](_0x327338(0x1ff)),null;console['groupCollapsed'](_0x327338(0x1d2)),console['log'](_0xcb03e8),console[_0x327338(0x1f6)]();let _0x5ec73f=_0x214fda;const _0x5c1d3e=extractContentByTag(_0xcb03e8,_0x1f6f6f);_0x5c1d3e?.[_0x327338(0x1d0)]()?_0x5ec73f=replaceContentByTag(_0x214fda,_0x1f6f6f,_0x5c1d3e):console['warn'](_0x327338(0x1a3)+_0x1f6f6f+_0x327338(0x1e3));if(_0x1652c3&&_0x6ddf33===_0x327338(0x1c4)){await updateTableFromText(_0xcb03e8);const _0x5437ec=getContext();if(_0x5437ec['chat']&&_0x5437ec['chat']['length']>0x0){const _0x13bd4d=_0x5437ec['chat'][_0x5437ec['chat'][_0x327338(0x204)]-0x1];saveStateToMessage(getMemoryState(),_0x13bd4d)&&(await saveChat(),renderTables(),console[_0x327338(0x1d3)](_0x327338(0x1bb)));}}const _0x577f94={'optimizedContent':_0x5ec73f};return console['timeEnd']('优化任务总耗时'),console[_0x327338(0x1f6)](),_0x577f94;}catch(_0x951e2a){return console[_0x327338(0x1a7)](_0x327338(0x1c6),_0x951e2a),toastr['error'](_0x327338(0x1f7)+_0x951e2a[_0x327338(0x1c7)],_0x327338(0x1ae)),console['timeEnd'](_0x327338(0x19c)),console[_0x327338(0x1f6)](),null;}}export async function processPlotOptimization(_0x15ce15,_0x420234,_0xb56f7={'isCancelled':![]}){const _0x41f752=_0x18e0,_0x19fac2=extension_settings[extensionName];if(_0x19fac2[_0x41f752(0x1be)]===![])return null;console[_0x41f752(0x205)]('['+extensionName+_0x41f752(0x191)+new Date()[_0x41f752(0x1a5)]()),console[_0x41f752(0x1fa)](_0x41f752(0x1e7));try{const _0x3de6a5=_0x15ce15[_0x41f752(0x1b0)];if(!_0x3de6a5||_0x3de6a5[_0x41f752(0x1d0)]()==='')return console['log']('['+extensionName+']\x20用户输入为空,跳过优化。'),null;const _0xd952fa=getContext(),_0x248807=_0xd952fa[_0x41f752(0x1ea)]||'用户',_0x191f6c=_0xd952fa[_0x41f752(0x1f4)]||'角色',_0xe6386e=getPresetPrompts(_0x41f752(0x1c1)),_0x16d903=[{'role':_0x41f752(0x1a6),'content':generateRandomSeed()}],_0x1c7db9={'sulv1':_0x19fac2[_0x41f752(0x200)]??0x1,'sulv2':_0x19fac2[_0x41f752(0x1b9)]??0x1,'sulv3':_0x19fac2[_0x41f752(0x1a1)]??0x1,'sulv4':_0x19fac2[_0x41f752(0x1a9)]??0x1};let _0x14e489=_0x19fac2[_0x41f752(0x1d4)]||'',_0x261a15=_0x19fac2[_0x41f752(0x1a0)]||'';for(const _0x331c9e in _0x1c7db9){const _0x3f71a2=_0x1c7db9[_0x331c9e],_0x2ad2fe=new RegExp(_0x331c9e[_0x41f752(0x196)](/[-\/\\^$*+?.()|[\]{}]/g,_0x41f752(0x1f9)),'g');_0x14e489=_0x14e489[_0x41f752(0x196)](_0x2ad2fe,_0x3f71a2),_0x261a15=_0x261a15[_0x41f752(0x196)](_0x2ad2fe,_0x3f71a2);}const _0x147668=await getPlotOptimizedWorldbookContent(_0xd952fa,_0x19fac2);let _0x176ba2='';if(_0x19fac2[_0x41f752(0x1db)])try{const {convertTablesToCsvStringForContentOnly:_0x51397d}=await import('./table-system/manager.js'),_0x548663=_0x41f752(0x1ab),_0x5718fc=_0x51397d();_0x5718fc['trim']()&&(_0x176ba2=_0x548663['replace']('{{{Amily2TableDataContent}}}',_0x5718fc));}catch(_0x493eb0){console[_0x41f752(0x1a7)]('[Amily2-表格系统]\x20注入表格内容时出错:',_0x493eb0);}let _0x196c65='';const _0x29a546=_0x19fac2[_0x41f752(0x1b8)]||0x0;if(_0x29a546>0x0&&_0x420234['length']>0x0){const _0x5eb8ae=_0x420234['slice'](-_0x29a546);_0x196c65=_0x5eb8ae[_0x41f752(0x203)](_0x12520d=>{const _0x1f9cb7=_0x41f752;if(_0x12520d['mes']&&_0x12520d[_0x1f9cb7(0x1b0)][_0x1f9cb7(0x1d0)]()){const _0x7ab654=[{'start':_0x1f9cb7(0x1cd),'end':'-->'}],_0xce9165=applyExclusionRules(_0x12520d['mes'][_0x1f9cb7(0x1d0)](),_0x7ab654);return _0xce9165?(_0x12520d[_0x1f9cb7(0x1a4)]?_0x248807:_0x191f6c)+':\x20'+_0xce9165:null;}return null;})['filter'](Boolean)[_0x41f752(0x1b4)]('\x0a');}const _0x1061e9=getMixedOrder('plot_optimization')||[];let _0x5ced23=0x0;for(const _0x1d42ae of _0x1061e9){if(_0x1d42ae['type']===_0x41f752(0x1e6))_0xe6386e&&_0xe6386e[_0x5ced23]&&(_0x16d903['push'](_0xe6386e[_0x5ced23]),_0x5ced23++);else{if(_0x1d42ae[_0x41f752(0x1fc)]==='conditional')switch(_0x1d42ae['id']){case _0x41f752(0x1ba):_0x14e489['trim']()&&_0x16d903[_0x41f752(0x1b1)]({'role':_0x41f752(0x1a6),'content':_0x14e489[_0x41f752(0x1d0)]()});break;case _0x41f752(0x1dd):_0x261a15['trim']()&&_0x16d903[_0x41f752(0x1b1)]({'role':_0x41f752(0x1a6),'content':_0x261a15[_0x41f752(0x1d0)]()});break;case _0x41f752(0x1e4):_0x147668[_0x41f752(0x1d0)]()&&_0x16d903[_0x41f752(0x1b1)]({'role':_0x41f752(0x1e1),'content':_0x41f752(0x194)+_0x147668['trim']()+_0x41f752(0x1e5)});break;case _0x41f752(0x1aa):_0x176ba2&&_0x16d903['push']({'role':_0x41f752(0x1e1),'content':_0x176ba2});break;case _0x41f752(0x1d6):_0x196c65&&_0x16d903[_0x41f752(0x1b1)]({'role':_0x41f752(0x1e1),'content':_0x41f752(0x1cf)+_0x196c65+_0x41f752(0x206)});break;case _0x41f752(0x201):_0x16d903[_0x41f752(0x1b1)]({'role':_0x41f752(0x1e1),'content':_0x41f752(0x1a8)+_0x3de6a5});break;case _0x41f752(0x1eb):_0x16d903[_0x41f752(0x1b1)]({'role':_0x41f752(0x1d7),'content':_0x41f752(0x1b2)});break;}}}console[_0x41f752(0x205)]('['+extensionName+_0x41f752(0x1c2)),console['dir'](_0x16d903),console[_0x41f752(0x1f6)]();let _0x4cace0='',_0x5433c8=0x0;const _0xc7bb43=0x3;let _0x3ba5ae=![];while(_0x5433c8<_0xc7bb43&&!_0x3ba5ae){if(_0xb56f7[_0x41f752(0x1da)])return console[_0x41f752(0x1d3)]('['+extensionName+_0x41f752(0x1bc)),null;_0x5433c8++,console[_0x41f752(0x1d3)]('['+extensionName+']\x20剧情优化第\x20'+_0x5433c8+'\x20次尝试...');const _0x28ba81=_0x19fac2[_0x41f752(0x1ac)]?await callJqyhAI(_0x16d903):await callAI(_0x16d903,_0x41f752(0x1c1));if(_0xb56f7[_0x41f752(0x1da)])return console[_0x41f752(0x1d3)]('['+extensionName+_0x41f752(0x1a2)),null;if(!_0x28ba81){console[_0x41f752(0x1b6)]('['+extensionName+_0x41f752(0x1f0)+_0x5433c8+_0x41f752(0x1cb));continue;}const _0x71f6a1=extractContentByTag(_0x28ba81,'plot'),_0x7302f4=_0x71f6a1?.[_0x41f752(0x1d0)]()?_0x71f6a1[_0x41f752(0x1d0)]():_0x28ba81[_0x41f752(0x1d0)]();_0x7302f4['length']>=0x64?(_0x4cace0=_0x28ba81,_0x3ba5ae=!![],console[_0x41f752(0x1d3)]('['+extensionName+_0x41f752(0x1f0)+_0x5433c8+'\x20次尝试成功,内容长度\x20('+_0x7302f4[_0x41f752(0x204)]+_0x41f752(0x198))):console[_0x41f752(0x1b6)]('['+extensionName+_0x41f752(0x1f0)+_0x5433c8+'\x20次尝试失败,回复内容长度为\x20'+_0x7302f4[_0x41f752(0x204)]+_0x41f752(0x19f));}if(!_0x3ba5ae)return console[_0x41f752(0x1a7)]('['+extensionName+']\x20已达到最大重试次数\x20('+_0xc7bb43+_0x41f752(0x1f2)),toastr[_0x41f752(0x1a7)](_0x41f752(0x193)+_0xc7bb43+_0x41f752(0x1f5),_0x41f752(0x1c9)),null;console[_0x41f752(0x205)]('['+extensionName+_0x41f752(0x1c5)),console[_0x41f752(0x1d3)](_0x4cace0),console[_0x41f752(0x1f6)]();const _0x1765d5=extractContentByTag(_0x4cace0,_0x41f752(0x195)),_0x5d58b3=_0x1765d5?.['trim']()?_0x1765d5[_0x41f752(0x1d0)]():_0x4cace0[_0x41f752(0x1d0)]();if(_0x5d58b3){let _0x5781a8='',_0x1c0ee6=_0x19fac2[_0x41f752(0x1f3)]?.[_0x41f752(0x1d0)]()||'';const _0x251fd0={'sulv1':_0x19fac2['plotOpt_rateMain']??0x1,'sulv2':_0x19fac2[_0x41f752(0x1b9)]??0x1,'sulv3':_0x19fac2[_0x41f752(0x1a1)]??0x1,'sulv4':_0x19fac2[_0x41f752(0x1a9)]??0x1};for(const _0x42f680 in _0x251fd0){const _0x28685d=_0x251fd0[_0x42f680],_0x2358b3=new RegExp(_0x42f680[_0x41f752(0x196)](/[-\/\\^$*+?.()|[\]{}]/g,_0x41f752(0x1f9)),'g');_0x1c0ee6=_0x1c0ee6[_0x41f752(0x196)](_0x2358b3,_0x28685d);}return _0x1c0ee6?_0x5781a8=_0x1c0ee6[_0x41f752(0x196)](_0x41f752(0x1b2),_0x5d58b3):_0x5781a8=_0x5d58b3,{'contentToAppend':_0x5781a8};}else return null;}catch(_0x59fec4){return console[_0x41f752(0x1a7)]('['+extensionName+_0x41f752(0x197),_0x59fec4),toastr['error'](_0x41f752(0x1de)+_0x59fec4[_0x41f752(0x1c7)],_0x41f752(0x1ae)),null;}finally{console[_0x41f752(0x190)]('剧情优化任务总耗时'),console[_0x41f752(0x1f6)]();}}