mirror of
https://github.com/SilenceLurker/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 22:55:51 +00:00
2 lines
15 KiB
JavaScript
2 lines
15 KiB
JavaScript
(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<Amily2Edit>\x0a<!--\x0a(这里是你的填表内容)\x0a-->\x0a</Amily2Edit><Additional\x20instructionsv>Optimisation\x20and\x20form\x20filling\x20have\x20been\x20completed.<Additional\x20instructions>','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<','<plot>','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+'<Additional\x20instructionsv>Start\x20and\x20end\x20labels\x20correctly.<Additional\x20instructions>'});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':'<!--','end':_0x4cffc8(0x20a)}],_0x109255=applyExclusionRules(_0x403516[_0x4cffc8(0x21b)][_0x4cffc8(0x210)](),_0x112f67);return _0x109255?(_0x403516[_0x4cffc8(0x1fb)]?_0x3b60e:_0xdb2726)+':\x20'+_0x109255:null;}return null;})[_0x3172c7(0x21c)](Boolean)['join']('\x0a');}const _0x35b5f8=getMixedOrder('plot_optimization')||[];for(const _0x5d03b9 of _0x35b5f8){if(_0x5d03b9[_0x3172c7(0x219)]==='prompt')_0x12cf11&&_0x12cf11[_0x5d03b9[_0x3172c7(0x201)]]&&_0x4a065e['push'](_0x12cf11[_0x5d03b9[_0x3172c7(0x201)]]);else{if(_0x5d03b9[_0x3172c7(0x219)]===_0x3172c7(0x1d9))switch(_0x5d03b9['id']){case _0x3172c7(0x1eb):_0xde1076['trim']()&&_0x4a065e['push']({'role':_0x3172c7(0x1ea),'content':_0xde1076[_0x3172c7(0x210)]()});break;case'systemPrompt':_0x66f750[_0x3172c7(0x210)]()&&_0x4a065e[_0x3172c7(0x228)]({'role':_0x3172c7(0x1ea),'content':_0x66f750[_0x3172c7(0x210)]()});break;case _0x3172c7(0x20e):_0x3d09de[_0x3172c7(0x210)]()&&_0x4a065e[_0x3172c7(0x228)]({'role':'user','content':_0x3172c7(0x1ec)+_0x3d09de['trim']()+_0x3172c7(0x1dd)});break;case _0x3172c7(0x1d8):_0x4a1e71&&_0x4a065e[_0x3172c7(0x228)]({'role':_0x3172c7(0x209),'content':_0x4a1e71});break;case _0x3172c7(0x203):_0x7124f6&&_0x4a065e[_0x3172c7(0x228)]({'role':_0x3172c7(0x209),'content':_0x3172c7(0x1ed)+_0x7124f6+'\x0a</前文内容>'});break;case _0x3172c7(0x1fa):_0x4a065e[_0x3172c7(0x228)]({'role':_0x3172c7(0x209),'content':_0x3172c7(0x217)+_0x2c5ab9});break;case _0x3172c7(0x1e9):_0x4a065e['push']({'role':_0x3172c7(0x1e8),'content':_0x3172c7(0x235)});break;}}}console[_0x3172c7(0x21d)]('['+extensionName+_0x3172c7(0x1f9)),console[_0x3172c7(0x211)](_0x4a065e),console[_0x3172c7(0x1fd)]();const _0x6972a7=await callAI(_0x4a065e);if(!_0x6972a7)throw new Error(_0x3172c7(0x1f1));console[_0x3172c7(0x21d)]('['+extensionName+']\x20从AI收到的原始回复'),console[_0x3172c7(0x222)](_0x6972a7),console[_0x3172c7(0x1fd)]();const _0x5dbbad=extractContentByTag(_0x6972a7,_0x3172c7(0x22c)),_0x5b8561=_0x5dbbad?.[_0x3172c7(0x210)]()?_0x5dbbad['trim']():_0x6972a7[_0x3172c7(0x210)]();if(_0x5b8561){let _0x44e932='',_0x4fa53a=_0x380a5a[_0x3172c7(0x1f5)]?.[_0x3172c7(0x210)]()||'';const _0x464003={'sulv1':_0x380a5a['plotOpt_rateMain']??0x1,'sulv2':_0x380a5a[_0x3172c7(0x1db)]??0x1,'sulv3':_0x380a5a[_0x3172c7(0x1e4)]??0x1,'sulv4':_0x380a5a['plotOpt_rateCuckold']??0x1};for(const _0x85b12 in _0x464003){const _0x381d5f=_0x464003[_0x85b12],_0x1f209d=new RegExp(_0x85b12[_0x3172c7(0x237)](/[-\/\\^$*+?.()|[\]{}]/g,_0x3172c7(0x23b)),'g');_0x4fa53a=_0x4fa53a[_0x3172c7(0x237)](_0x1f209d,_0x381d5f);}return _0x4fa53a?_0x44e932=_0x4fa53a[_0x3172c7(0x237)](_0x3172c7(0x235),_0x5b8561):_0x44e932=_0x5b8561,{'contentToAppend':_0x44e932};}else return null;}catch(_0x20822d){return console[_0x3172c7(0x236)]('['+extensionName+_0x3172c7(0x23a),_0x20822d),toastr[_0x3172c7(0x236)](_0x3172c7(0x20d)+_0x20822d[_0x3172c7(0x1fe)],_0x3172c7(0x221)),null;}finally{console[_0x3172c7(0x1ee)](_0x3172c7(0x22d)),console[_0x3172c7(0x1fd)]();}}
|