diff --git a/core/summarizer.js b/core/summarizer.js index 5efe8fa..90375ba 100644 --- a/core/summarizer.js +++ b/core/summarizer.js @@ -1 +1 @@ -(function(_0x5aeff6,_0xb9e4b4){const _0x3c742c=_0xfacb,_0x54311e=_0x5aeff6();while(!![]){try{const _0x41942a=parseInt(_0x3c742c(0x1e5))/0x1*(-parseInt(_0x3c742c(0x1e7))/0x2)+-parseInt(_0x3c742c(0x1f0))/0x3*(parseInt(_0x3c742c(0x229))/0x4)+-parseInt(_0x3c742c(0x1f6))/0x5+parseInt(_0x3c742c(0x224))/0x6+parseInt(_0x3c742c(0x21e))/0x7+parseInt(_0x3c742c(0x1ef))/0x8*(-parseInt(_0x3c742c(0x1df))/0x9)+parseInt(_0x3c742c(0x202))/0xa;if(_0x41942a===_0xb9e4b4)break;else _0x54311e['push'](_0x54311e['shift']());}catch(_0xf0b8b2){_0x54311e['push'](_0x54311e['shift']());}}}(_0x8448,0xa2d73));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';import{getCombinedWorldbookContent,getPlotOptimizedWorldbookContent}from'./lore.js';function _0xfacb(_0x477522,_0xc1179c){const _0x844851=_0x8448();return _0xfacb=function(_0xfacbb1,_0x111ce2){_0xfacbb1=_0xfacbb1-0x1d8;let _0x30999b=_0x844851[_0xfacbb1];return _0x30999b;},_0xfacb(_0x477522,_0xc1179c);}function _0x8448(){const _0x478e88=['trim','dir','name2','[Amily2-内容排除]\x20正文优化内容排除规则已生效,文本长度从\x20','optimizationExclusionEnabled','\x0a\x0a\x0a\x0aOptimisation\x20and\x20form\x20filling\x20have\x20been\x20completed.','optimizationTargetTag','[核心处理内容]:\x0a','lastPreOptimizationText','type','>,将保留原始消息。','mes','filter','groupCollapsed','3032554yXxNSH','toLocaleTimeString','optimizationEnabled','严重错误','log','plotOpt_contextLimit','2933394LLjaBT','worldbookEnabled','./table-system/manager.js','optimizationExclusionRules','push','4mRRELq','filling_mode','[Amily2-优化中填表]\x20流程已全部完成,并已强制保存和刷新UI。','plot','剧情优化任务总耗时','[Amily2号-最终国书内容\x20(发往AI)]','slice','请你在优化完成后,在正文标签外结合最新消息中的剧情、当前的表格内容进行填表任务:\x0a\x0a','dispatchEvent',']\x20剧情优化任务启动...\x20','length','[Amily2-外交部]\x20目标标签\x20<','','error','replace','optimized','plotOpt_rateCuckold',']\x20剧情优化任务发生严重错误:','\x5c$&','characterId','prompt','[Amily2-表格系统]\x20注入表格内容时出错:','[Amily2号-正文优化任务]\x20','tableEnabled','conditional','content','plotOpt_ratePersonal','plotOpt_rateMain','','plot_optimization','261PZLRhP','[Amily2号-原始回复]','[世界书档案]:\x0a','world','fillingMode','plotOpt_rateErotic','15757EuFicX','优化任务总耗时','68vnSUgt','assistant','plotTag','system','mainPrompt','<世界书内容>\x0a','<前文内容>\x0a','timeEnd','268168ozdydD','2182968JMGKtI','AI响应为空或格式不正确。','(AI)最新消息,[核心处理内容]:','##以下内容是故事发生的剧情中提取出的内容,已经转化为表格形式呈现给你,请将以下内容作为后续剧情的一部分参考:<表格内容>\x0a{{{Amily2TableDataContent}}}','AMILY2_SYSTEM_PARALYZED','plotOpt_finalSystemDirective','999120HuYeHV','[上下文参考]:\x0a','plotOpt_mainPrompt',']\x20发送给AI的最终请求内容','coreContent','is_user','join','groupEnd','message','extensions','systemPrompt','index','21802010TyzEtW','contextLimit','chat','plotOpt_tableEnabled','preOptimizationTextUpdated','name1','>\x20未找到或为空,或内容已被完全排除,优化任务已跳过。','user','-->','[Amily2-外交部]\x20未能获取AI响应内容','data','剧情优化任务失败:\x20','worldbook','main-api'];_0x8448=function(){return _0x478e88;};return _0x8448();}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';import{callAI,generateRandomSeed}from'./api.js';export async function processOptimization(_0x4ae1fb,_0xfbb2b8){const _0x5ab6ef=_0xfacb;if(window[_0x5ab6ef(0x1f4)]===!![])return console[_0x5ab6ef(0x236)]('[Amily2-制裁]\x20系统完整性已受损,所有外交活动被无限期中止。'),null;const _0x959232=extension_settings[extensionName],_0x226ea8=_0x959232[_0x5ab6ef(0x220)];if(!_0x226ea8)return null;console[_0x5ab6ef(0x21d)](_0x5ab6ef(0x23f)+new Date()[_0x5ab6ef(0x21f)]()),console['time'](_0x5ab6ef(0x1e6));try{const _0x4e9412=_0x4ae1fb[_0x5ab6ef(0x21b)];let _0x314489=_0x4e9412;if(_0x959232[_0x5ab6ef(0x214)]&&_0x959232[_0x5ab6ef(0x227)]?.[_0x5ab6ef(0x233)]>0x0){const _0x3018bc=_0x314489['length'];_0x314489=applyExclusionRules(_0x314489,_0x959232[_0x5ab6ef(0x227)]);const _0x3f0fff=_0x314489[_0x5ab6ef(0x233)];_0x3018bc!==_0x3f0fff&&console[_0x5ab6ef(0x222)](_0x5ab6ef(0x213)+_0x3018bc+'\x20变为\x20'+_0x3f0fff+'。');}const _0x4b191f=_0x959232[_0x5ab6ef(0x216)]||_0x5ab6ef(0x1da),_0x3db310=extractFullTagBlock(_0x314489,_0x4b191f);if(!_0x3db310||extractContentByTag(_0x3db310,_0x4b191f)?.['trim']()==='')return console[_0x5ab6ef(0x222)](_0x5ab6ef(0x234)+_0x4b191f+_0x5ab6ef(0x208)),console['timeEnd'](_0x5ab6ef(0x1e6)),console[_0x5ab6ef(0x1fd)](),null;_0x314489=_0x3db310;const _0x4247f2=getContext(),_0x564a8f=_0x4247f2['name1']||'用户',_0x582d42=_0x4247f2[_0x5ab6ef(0x212)]||'角色',_0x32ce3d=_0xfbb2b8[_0x5ab6ef(0x233)]>0x0&&_0xfbb2b8[_0xfbb2b8[_0x5ab6ef(0x233)]-0x1]['is_user']?_0xfbb2b8[_0xfbb2b8[_0x5ab6ef(0x233)]-0x1]:null,_0x365ee8=_0x32ce3d?_0xfbb2b8[_0x5ab6ef(0x22f)](0x0,-0x1):_0xfbb2b8,_0x724c3c=_0x365ee8['map'](_0x52dca8=>_0x52dca8['mes']&&_0x52dca8[_0x5ab6ef(0x21b)][_0x5ab6ef(0x210)]()?(_0x52dca8[_0x5ab6ef(0x1fb)]?_0x564a8f:_0x582d42)+':\x20'+_0x52dca8[_0x5ab6ef(0x21b)][_0x5ab6ef(0x210)]():null)['filter'](Boolean)[_0x5ab6ef(0x1fc)]('\x0a');let _0x38e896='';if(_0x959232[_0x5ab6ef(0x225)]){const _0x14f174=characters[_0x4247f2[_0x5ab6ef(0x23c)]];_0x14f174?.[_0x5ab6ef(0x20c)]?.[_0x5ab6ef(0x1ff)]?.[_0x5ab6ef(0x1e2)]&&(_0x38e896=await getCombinedWorldbookContent(_0x14f174[_0x5ab6ef(0x20c)][_0x5ab6ef(0x1ff)][_0x5ab6ef(0x1e2)]));}const _0x3cb130=getPresetPrompts('optimization'),_0xf7ec99=[{'role':_0x5ab6ef(0x1ea),'content':generateRandomSeed()}];let _0x210cbe=_0x32ce3d?_0x564a8f+'(用户)最新消息:'+_0x32ce3d[_0x5ab6ef(0x21b)]+'\x0a'+_0x582d42+'(AI)最新消息,[核心处理内容]:'+_0x314489:_0x582d42+_0x5ab6ef(0x1f2)+_0x314489;const _0x109f46=_0x959232[_0x5ab6ef(0x22a)]||_0x5ab6ef(0x20f);window[_0x5ab6ef(0x218)]=_0x210cbe,document[_0x5ab6ef(0x231)](new CustomEvent(_0x5ab6ef(0x206)));const _0x558374=getMixedOrder('optimization')||[];for(const _0x1e1934 of _0x558374){if(_0x1e1934['type']===_0x5ab6ef(0x23d))_0x3cb130&&_0x3cb130[_0x1e1934['index']]&&_0xf7ec99[_0x5ab6ef(0x228)](_0x3cb130[_0x1e1934[_0x5ab6ef(0x201)]]);else{if(_0x1e1934['type']===_0x5ab6ef(0x1d9))switch(_0x1e1934['id']){case _0x5ab6ef(0x1eb):_0x959232[_0x5ab6ef(0x1eb)]?.[_0x5ab6ef(0x210)]()&&_0xf7ec99[_0x5ab6ef(0x228)]({'role':_0x5ab6ef(0x1ea),'content':_0x959232['mainPrompt'][_0x5ab6ef(0x210)]()});break;case'systemPrompt':_0x959232[_0x5ab6ef(0x200)]?.['trim']()&&_0xf7ec99[_0x5ab6ef(0x228)]({'role':_0x5ab6ef(0x1ea),'content':_0x959232[_0x5ab6ef(0x200)][_0x5ab6ef(0x210)]()});break;case'worldbook':_0x38e896&&_0xf7ec99['push']({'role':_0x5ab6ef(0x209),'content':_0x5ab6ef(0x1e1)+_0x38e896});break;case'history':_0x724c3c&&_0xf7ec99[_0x5ab6ef(0x228)]({'role':'user','content':_0x5ab6ef(0x1f7)+_0x724c3c});break;case _0x5ab6ef(0x1e3):if(_0x226ea8&&_0x109f46===_0x5ab6ef(0x238)){const _0x4326e5=getBatchFillerFlowTemplate(),_0x6f8dbd=convertTablesToCsvString(),_0x3fda15=_0x4326e5[_0x5ab6ef(0x237)]('{{{Amily2TableData}}}',_0x6f8dbd);_0xf7ec99[_0x5ab6ef(0x228)]({'role':_0x5ab6ef(0x209),'content':_0x210cbe}),_0xf7ec99[_0x5ab6ef(0x228)]({'role':_0x5ab6ef(0x1ea),'content':_0x5ab6ef(0x230)+_0x3fda15+_0x5ab6ef(0x215)});}else _0xf7ec99[_0x5ab6ef(0x228)]({'role':_0x5ab6ef(0x209),'content':'[目标内容]:\x0a'+_0x210cbe+'Start\x20and\x20end\x20labels\x20correctly.'});break;}}}window[_0x5ab6ef(0x218)]=_0x210cbe,document['dispatchEvent'](new CustomEvent('preOptimizationTextUpdated')),console[_0x5ab6ef(0x21d)](_0x5ab6ef(0x22e)),console['dir'](_0xf7ec99),console['groupEnd']();const _0x183360=await callAI(_0xf7ec99);if(!_0x183360)return console['error'](_0x5ab6ef(0x20b)),null;console['groupCollapsed'](_0x5ab6ef(0x1e0)),console[_0x5ab6ef(0x222)](_0x183360),console[_0x5ab6ef(0x1fd)]();let _0x2a0ce3=_0x4e9412;const _0xaf983a=extractContentByTag(_0x183360,_0x4b191f);_0xaf983a?.['trim']()?_0x2a0ce3=replaceContentByTag(_0x4e9412,_0x4b191f,_0xaf983a):console['warn']('[Amily2-外交部]\x20AI的回复中未找到有效的目标标签\x20<'+_0x4b191f+_0x5ab6ef(0x21a));if(_0x226ea8&&_0x109f46==='optimized'){await updateTableFromText(_0x183360);const _0x20b015=getContext();if(_0x20b015[_0x5ab6ef(0x204)]&&_0x20b015[_0x5ab6ef(0x204)]['length']>0x0){const _0x20a01e=_0x20b015[_0x5ab6ef(0x204)][_0x20b015[_0x5ab6ef(0x204)][_0x5ab6ef(0x233)]-0x1];saveStateToMessage(getMemoryState(),_0x20a01e)&&(await saveChat(),renderTables(),console[_0x5ab6ef(0x222)](_0x5ab6ef(0x22b)));}}const _0x18778c={'optimizedContent':_0x2a0ce3};return console[_0x5ab6ef(0x1ee)](_0x5ab6ef(0x1e6)),console[_0x5ab6ef(0x1fd)](),_0x18778c;}catch(_0x89ae24){return console[_0x5ab6ef(0x236)]('[Amily2-外交部]\x20发生严重错误:',_0x89ae24),toastr['error']('Amily2号任务失败:\x20'+_0x89ae24[_0x5ab6ef(0x1fe)],_0x5ab6ef(0x221)),console[_0x5ab6ef(0x1ee)](_0x5ab6ef(0x1e6)),console['groupEnd'](),null;}}export async function processPlotOptimization(_0x2535a2,_0x4becd2){const _0x3172c7=_0xfacb,_0x380a5a=extension_settings[extensionName];if(_0x380a5a['plotOpt_enabled']===![])return null;console[_0x3172c7(0x21d)]('['+extensionName+_0x3172c7(0x232)+new Date()['toLocaleTimeString']()),console['time'](_0x3172c7(0x22d));try{const _0x2c5ab9=_0x2535a2[_0x3172c7(0x21b)];if(!_0x2c5ab9||_0x2c5ab9['trim']()==='')return console[_0x3172c7(0x222)]('['+extensionName+']\x20用户输入为空,跳过优化。'),null;const _0x499a5f=getContext(),_0x3b60e=_0x499a5f[_0x3172c7(0x207)]||'用户',_0xdb2726=_0x499a5f[_0x3172c7(0x212)]||'角色',_0x12cf11=getPresetPrompts(_0x3172c7(0x1de)),_0x4a065e=[{'role':'system','content':generateRandomSeed()}],_0x4b3b0f={'sulv1':_0x380a5a[_0x3172c7(0x1dc)]??0x1,'sulv2':_0x380a5a[_0x3172c7(0x1db)]??0x1,'sulv3':_0x380a5a[_0x3172c7(0x1e4)]??0x1,'sulv4':_0x380a5a[_0x3172c7(0x239)]??0x1};let _0xde1076=_0x380a5a[_0x3172c7(0x1f8)]||'',_0x66f750=_0x380a5a['plotOpt_systemPrompt']||'';for(const _0x5a7548 in _0x4b3b0f){const _0x5acdc2=_0x4b3b0f[_0x5a7548],_0x558253=new RegExp(_0x5a7548[_0x3172c7(0x237)](/[-\/\\^$*+?.()|[\]{}]/g,_0x3172c7(0x23b)),'g');_0xde1076=_0xde1076[_0x3172c7(0x237)](_0x558253,_0x5acdc2),_0x66f750=_0x66f750[_0x3172c7(0x237)](_0x558253,_0x5acdc2);}const _0x3d09de=await getPlotOptimizedWorldbookContent(_0x499a5f,_0x380a5a);let _0x4a1e71='';if(_0x380a5a[_0x3172c7(0x205)])try{const {convertTablesToCsvStringForContentOnly:_0x330b00}=await import(_0x3172c7(0x226)),_0x27433e=_0x3172c7(0x1f3),_0x3e27dd=_0x330b00();_0x3e27dd['trim']()&&(_0x4a1e71=_0x27433e[_0x3172c7(0x237)]('{{{Amily2TableDataContent}}}',_0x3e27dd));}catch(_0x53b71c){console[_0x3172c7(0x236)](_0x3172c7(0x23e),_0x53b71c);}let _0x7124f6='';const _0x9d3823=_0x380a5a[_0x3172c7(0x223)]||0x0;if(_0x9d3823>0x0&&_0x4becd2[_0x3172c7(0x233)]>0x0){const _0x2cfeb4=_0x4becd2['slice'](-_0x9d3823);_0x7124f6=_0x2cfeb4['map'](_0x403516=>{const _0x4cffc8=_0x3172c7;if(_0x403516['mes']&&_0x403516[_0x4cffc8(0x21b)][_0x4cffc8(0x210)]()){const _0x112f67=[{'start':'','[上下文参考]:\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)]();}}