Files
ST-Amily2-Chat-Optimisation/core/events.js
2025-08-21 10:59:00 +08:00

2 lines
6.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
(function(_0x37ffd4,_0x51608f){const _0x54cc6e=_0xb6f7,_0x34916a=_0x37ffd4();while(!![]){try{const _0x14a35b=parseInt(_0x54cc6e(0x16f))/0x1*(-parseInt(_0x54cc6e(0x174))/0x2)+-parseInt(_0x54cc6e(0x184))/0x3+-parseInt(_0x54cc6e(0x185))/0x4*(-parseInt(_0x54cc6e(0x18d))/0x5)+parseInt(_0x54cc6e(0x171))/0x6*(parseInt(_0x54cc6e(0x170))/0x7)+parseInt(_0x54cc6e(0x189))/0x8*(-parseInt(_0x54cc6e(0x16c))/0x9)+-parseInt(_0x54cc6e(0x16e))/0xa*(-parseInt(_0x54cc6e(0x179))/0xb)+parseInt(_0x54cc6e(0x167))/0xc*(parseInt(_0x54cc6e(0x17f))/0xd);if(_0x14a35b===_0x51608f)break;else _0x34916a['push'](_0x34916a['shift']());}catch(_0x441b5a){_0x34916a['push'](_0x34916a['shift']());}}}(_0x5458,0xae27d));import{getContext,extension_settings}from'/scripts/extensions.js';import{saveChatConditional}from'/script.js';import{extensionName}from'../utils/settings.js';function _0xb6f7(_0x4dafd1,_0x54971f){const _0x54580a=_0x5458();return _0xb6f7=function(_0xb6f7e4,_0x2a6bf8){_0xb6f7e4=_0xb6f7e4-0x167;let _0x85326f=_0x54580a[_0xb6f7e4];return _0x85326f;},_0xb6f7(_0x4dafd1,_0x54971f);}import*as _0x4e9594 from'./table-system/manager.js';import*as _0x111e8c from'./table-system/executor.js';import{renderTables}from'../ui/table-bindings.js';function _0x5458(){const _0x23a030=['【监察系统-步骤2】推演完毕。是否有变化:\x20','365724ddlHIy','optimizationEnabled','enabled','log','forEach','9BWWUHS','warn','94070OmIsdD','6HFYqAj','8066849eOeCiM','6xjIeuS','【监察系统-步骤3】检测到变化已将新状态写入消息\x20','is_user','171764eZSeGB','tableIndex','rowIndex','optimizedContent','[Amily2号-正文优化]\x20检测到消息并非AI对用户的直接回复已跳过优化。','671dNSuWy','success','\x20是用户消息无需处理。','table_system_enabled','executeCommands','[分步填表]\x20表格系统总开关已关闭跳过分步填表处理。','247ZVdDCS','info','chat','【监察系统】接到圣旨,开始处理消息\x20ID:\x20','optimizationMode','3402777qWuYYP','2344IndvWe','...\x22','filling_mode','refresh','1798856BusqsT','error','\x20并保存。','saveStateToMessage','2410eFQQmP','length','main-api','max','slice','secondary-api','addHighlight','contextMessages','\x20加载了基准状态。','【监察系统】错误:未找到消息\x20ID:\x20','mes','【监察系统】检测到\x22分步填表\x22或\x22优化中填表\x22模式已启用主API填表逻辑已自动禁用。','isWaitingForUserInput'];_0x5458=function(){return _0x23a030;};return _0x5458();}import{log}from'./table-system/logger.js';async function handleTableUpdate(_0x34bad4){const _0x361b89=_0xb6f7,_0x40b5aa=extension_settings[extensionName],_0x2aebeb=_0x40b5aa[_0x361b89(0x17c)]!==![];if(!_0x2aebeb){log('【监察系统】表格系统总开关已关闭,跳过所有表格处理。','info');return;}const _0x2f6c13=_0x40b5aa['filling_mode']||_0x361b89(0x18f);if(_0x2f6c13===_0x361b89(0x192)||_0x2f6c13==='optimized'){log(_0x361b89(0x198),_0x361b89(0x180));return;}log(_0x361b89(0x182)+_0x34bad4,_0x361b89(0x16d));const _0x193366=getContext(),_0x27aff6=_0x193366[_0x361b89(0x181)][_0x34bad4];if(!_0x27aff6){log(_0x361b89(0x196)+_0x34bad4+',流程中止。','error');return;}if(_0x27aff6[_0x361b89(0x173)]){log('【监察系统】消息\x20ID:\x20'+_0x34bad4+_0x361b89(0x17b),_0x361b89(0x180));return;}log('【监察系统】正在处理的奏折内容:\x20\x22'+_0x27aff6[_0x361b89(0x197)]['substring'](0x0,0x32)+_0x361b89(0x186),_0x361b89(0x180));const _0x46b308=_0x4e9594['loadTables'](_0x34bad4);log('【监察系统-步骤1】为消息\x20'+_0x34bad4+_0x361b89(0x195),_0x361b89(0x180),_0x46b308);const {finalState:_0x25b032,hasChanges:_0x4f472f,changes:_0x338cda}=_0x111e8c[_0x361b89(0x17d)](_0x27aff6['mes'],_0x46b308);log(_0x361b89(0x19a)+_0x4f472f,_0x361b89(0x180),_0x25b032),_0x4f472f?(_0x338cda&&_0x338cda[_0x361b89(0x18e)]>0x0&&_0x338cda[_0x361b89(0x16b)](_0x37c937=>{const _0x321a59=_0x361b89;_0x4e9594[_0x321a59(0x193)](_0x37c937[_0x321a59(0x175)],_0x37c937[_0x321a59(0x176)],_0x37c937['colIndex']);}),_0x4e9594[_0x361b89(0x18c)](_0x25b032,_0x27aff6),_0x4e9594['setMemoryState'](_0x25b032),await saveChatConditional(),log(_0x361b89(0x172)+_0x34bad4+_0x361b89(0x18b),_0x361b89(0x17a))):log('【监察系统-步骤3】未检测到有效指令或变化无需写入。',_0x361b89(0x180)),_0x4f472f&&renderTables();}import{processOptimization}from'./summarizer.js';import{executeAutoHide}from'./autoHideManager.js';import{checkAndTriggerAutoSummary}from'./historiographer.js';import{fillWithSecondaryApi}from'./table-system/secondary-filler.js';export async function onMessageReceived(_0x488f5c){const _0x1e7416=_0xb6f7,_0x176228=getContext();if(_0x488f5c&&_0x488f5c[_0x1e7416(0x173)]||_0x176228[_0x1e7416(0x199)])return;const _0x278c06=extension_settings[extensionName],_0x5ed7c1=_0x176228[_0x1e7416(0x181)];if(!_0x5ed7c1||_0x5ed7c1[_0x1e7416(0x18e)]===0x0)return;const _0x45507=_0x5ed7c1[_0x5ed7c1['length']-0x1];if(_0x45507['is_user'])return;const _0x1dbdfc=_0x278c06[_0x1e7416(0x17c)]!==![];await executeAutoHide();const _0x2dce5e=_0x278c06[_0x1e7416(0x169)]&&_0x278c06[_0x1e7416(0x168)]&&_0x278c06['apiUrl'];if(_0x2dce5e){if(_0x5ed7c1[_0x1e7416(0x18e)]>=0x2&&_0x5ed7c1[_0x5ed7c1['length']-0x2][_0x1e7416(0x173)]){const _0x5ca0c9=_0x278c06[_0x1e7416(0x194)]||0x2,_0xed3ec=Math[_0x1e7416(0x190)](0x0,_0x5ed7c1[_0x1e7416(0x18e)]-0x1-_0x5ca0c9),_0x25e4e8=_0x5ed7c1[_0x1e7416(0x191)](_0xed3ec,_0x5ed7c1[_0x1e7416(0x18e)]-0x1),_0x40c8ef=await processOptimization(_0x45507,_0x25e4e8);_0x40c8ef&&_0x40c8ef[_0x1e7416(0x177)]&&_0x40c8ef[_0x1e7416(0x177)]!==_0x45507[_0x1e7416(0x197)]&&(_0x45507[_0x1e7416(0x197)]=_0x40c8ef[_0x1e7416(0x177)],await saveChatConditional(),_0x278c06[_0x1e7416(0x183)]===_0x1e7416(0x188)&&await reloadCurrentChat());}else console[_0x1e7416(0x16a)](_0x1e7416(0x178));}if(_0x1dbdfc){const _0x25b885=_0x278c06[_0x1e7416(0x187)]||'main-api';_0x25b885===_0x1e7416(0x192)&&fillWithSecondaryApi(_0x45507);}else log(_0x1e7416(0x17e),_0x1e7416(0x180));((async()=>{const _0x4ddbd5=_0x1e7416;try{await new Promise(_0xd35529=>setTimeout(_0xd35529,0x64)),await checkAndTriggerAutoSummary();}catch(_0x46454a){console[_0x4ddbd5(0x18a)]('[大史官]\x20后台自动总结任务执行时发生错误:',_0x46454a);}})());}export{handleTableUpdate};