diff --git a/core/table-system/batch-filler.js b/core/table-system/batch-filler.js index a3f74bb..ce14acb 100644 --- a/core/table-system/batch-filler.js +++ b/core/table-system/batch-filler.js @@ -1 +1 @@ -const _0x31264b=_0x40c5;(function(_0x6b1ef1,_0xc0b9b9){const _0x165e84=_0x40c5,_0x3317d6=_0x6b1ef1();while(!![]){try{const _0x3adc48=parseInt(_0x165e84(0xc0))/0x1+parseInt(_0x165e84(0xd6))/0x2*(parseInt(_0x165e84(0x11f))/0x3)+-parseInt(_0x165e84(0x120))/0x4*(-parseInt(_0x165e84(0x10d))/0x5)+-parseInt(_0x165e84(0xb8))/0x6*(parseInt(_0x165e84(0xa5))/0x7)+-parseInt(_0x165e84(0xf8))/0x8*(parseInt(_0x165e84(0x107))/0x9)+-parseInt(_0x165e84(0xe1))/0xa*(parseInt(_0x165e84(0xce))/0xb)+parseInt(_0x165e84(0x119))/0xc*(parseInt(_0x165e84(0xef))/0xd);if(_0x3adc48===_0xc0b9b9)break;else _0x3317d6['push'](_0x3317d6['shift']());}catch(_0x21ad81){_0x3317d6['push'](_0x3317d6['shift']());}}}(_0x2c3b,0xa60c3));import{getContext,extension_settings}from'/scripts/extensions.js';import{log}from'./logger.js';import{updateTableFromText}from'./manager.js';import{extensionName}from'../../utils/settings.js';import{renderTables}from'../../ui/table-bindings.js';import{getPresetPrompts,getMixedOrder}from'../../PresetSettings/index.js';import{callAI,generateRandomSeed}from'../api.js';import{extractBlocksByTags,applyExclusionRules}from'../utils/rag-tag-extractor.js';import{getBatchFillerRuleTemplate,getBatchFillerFlowTemplate,convertTablesToCsvString}from'./manager.js';let isFilling=![],manualStopRequested=![],currentBatch=0x0,totalBatches=0x0,chatHistoryLength=0x0,threshold=0x1e;const MAX_RETRIES=0x2,fillButton=()=>document[_0x31264b(0x11d)]('fill-table-now-btn');function updateButtonState(_0x3b8a55,_0xcef8ed=0x0,_0x2e89dc=0x0){const _0x2be588=_0x31264b,_0x4e5ac7=fillButton();if(!_0x4e5ac7)return;switch(_0x3b8a55){case _0x2be588(0xd5):let _0x22e739=_0x2e89dc>0x0?_0x2be588(0xad)+(_0x2e89dc+0x1)+')':'';_0x4e5ac7['textContent']=_0x2be588(0x11a)+_0xcef8ed+'/'+totalBatches+')'+_0x22e739,_0x4e5ac7[_0x2be588(0x111)]=![],isFilling=!![];break;case _0x2be588(0x118):_0x4e5ac7[_0x2be588(0xb0)]=_0x2be588(0xbf),_0x4e5ac7[_0x2be588(0x111)]=!![];break;case _0x2be588(0xdd):_0x4e5ac7[_0x2be588(0xb0)]=_0x2be588(0xc2),_0x4e5ac7[_0x2be588(0x111)]=![],isFilling=!![];break;case _0x2be588(0xd9):_0x4e5ac7[_0x2be588(0xb0)]=_0x2be588(0xb7),_0x4e5ac7[_0x2be588(0x111)]=![],isFilling=!![];break;case _0x2be588(0xfb):default:_0x4e5ac7['textContent']=_0x2be588(0x100),_0x4e5ac7[_0x2be588(0x111)]=![],isFilling=![],currentBatch=0x0,manualStopRequested=![];break;}}function _0x40c5(_0x2cf916,_0x5f4a27){const _0x2c3b7f=_0x2c3b();return _0x40c5=function(_0x40c58e,_0x93ad23){_0x40c58e=_0x40c58e-0xa5;let _0x133393=_0x2c3b7f[_0x40c58e];return _0x133393;},_0x40c5(_0x2cf916,_0x5f4a27);}async function callTableModel(_0xf907ec){const _0x557bee=_0x31264b;try{const _0x19c783=await callAI(_0xf907ec);if(!_0x19c783)throw new Error('API返回内容为空。');return _0x19c783;}catch(_0x39f248){return log(_0x557bee(0xac)+_0x39f248[_0x557bee(0xe5)],_0x557bee(0xd9)),toastr['error']('与模型通讯时发生异常:\x20'+_0x39f248['message'],_0x557bee(0xf7)),null;}}function getRawMessagesForSummary(_0x58a294,_0x34c849){const _0x18f914=_0x31264b,_0x1178cf=getContext(),_0x30f2bd=_0x1178cf[_0x18f914(0xc4)],_0x1ae226=extension_settings[extensionName],_0x4e1107=_0x30f2bd[_0x18f914(0x117)](_0x58a294-0x1,_0x34c849);if(_0x4e1107[_0x18f914(0xe8)]===0x0)return null;const _0x318ec2=_0x1178cf[_0x18f914(0xaa)]||'用户',_0x921b93=_0x1178cf[_0x18f914(0xe6)]||'角色',_0x223f4b=_0x1ae226[_0x18f914(0xd1)]??![],_0x2f2622=_0x223f4b?(_0x1ae226[_0x18f914(0xf4)]||'')['split'](',')['map'](_0x137b9=>_0x137b9[_0x18f914(0x104)]())[_0x18f914(0xc1)](Boolean):[],_0x1c418a=_0x1ae226[_0x18f914(0xab)]||[],_0x209c64=_0x4e1107[_0x18f914(0x110)]((_0x120895,_0x55c288)=>{const _0x12bdb5=_0x18f914;let _0x506231=_0x120895[_0x12bdb5(0xca)];if(_0x223f4b&&_0x2f2622[_0x12bdb5(0xe8)]>0x0){const _0x1d499c=extractBlocksByTags(_0x506231,_0x2f2622);_0x1d499c[_0x12bdb5(0xe8)]>0x0&&(_0x506231=_0x1d499c[_0x12bdb5(0x103)]('\x0a\x0a'));}_0x506231=applyExclusionRules(_0x506231,_0x1c418a);if(!_0x506231['trim']())return null;return{'floor':_0x58a294+_0x55c288,'author':_0x120895[_0x12bdb5(0xa7)]?_0x318ec2:_0x921b93,'authorType':_0x120895['is_user']?_0x12bdb5(0xe3):_0x12bdb5(0xbd),'content':_0x506231[_0x12bdb5(0x104)]()};})[_0x18f914(0xc1)](Boolean);return _0x209c64;}async function runBatchAttempt(_0x4590af,_0x5533a5){const _0x28b2ab=_0x31264b;try{if(manualStopRequested){log(_0x28b2ab(0xf6)+_0x4590af+'\x20开始前手动暂停。','warn'),updateButtonState(_0x28b2ab(0xdd));return;}updateButtonState(_0x28b2ab(0xd5),_0x4590af,_0x5533a5);const _0x37086a=(_0x4590af-0x1)*threshold+0x1,_0x5843c4=Math[_0x28b2ab(0xd0)](_0x37086a+threshold-0x1,chatHistoryLength);log(_0x28b2ab(0xeb)+_0x4590af+'/'+totalBatches+_0x28b2ab(0xb5)+_0x37086a+'-'+_0x5843c4+_0x28b2ab(0xb4)+(_0x5533a5+0x1)+'/'+(MAX_RETRIES+0x1)+')',_0x28b2ab(0xd8));const _0x49b119=getRawMessagesForSummary(_0x37086a,_0x5843c4);if(!_0x49b119||_0x49b119[_0x28b2ab(0xe8)]===0x0)throw new Error(_0x28b2ab(0xb9));const _0x350276=_0x49b119['map'](_0x119459=>'【第\x20'+_0x119459['floor']+_0x28b2ab(0xfd)+_0x119459['author']+':\x20'+_0x119459[_0x28b2ab(0xf0)])[_0x28b2ab(0x103)]('\x0a'),_0x6a7cdf=getBatchFillerRuleTemplate(),_0x2cbc77=getBatchFillerFlowTemplate(),_0x2eb646=convertTablesToCsvString(),_0x2dddf8=_0x2cbc77[_0x28b2ab(0xe4)](_0x28b2ab(0x108),_0x2eb646);let _0x9d10b;try{const _0x460b55=localStorage[_0x28b2ab(0xc6)](_0x28b2ab(0x10f));_0x460b55&&(_0x9d10b=JSON['parse'](_0x460b55));}catch(_0x235e46){console[_0x28b2ab(0xd9)](_0x28b2ab(0xbc),_0x235e46);}const _0x456ed4=getMixedOrder('batch_filler')||[],_0xce554b=getPresetPrompts(_0x28b2ab(0xfa)),_0x21a01b=[{'role':'system','content':generateRandomSeed()}];for(const _0x39781d of _0x456ed4){if(_0x39781d[_0x28b2ab(0xf3)]===_0x28b2ab(0xee))_0xce554b&&_0xce554b[_0x39781d[_0x28b2ab(0xea)]]&&_0x21a01b['push'](_0xce554b[_0x39781d[_0x28b2ab(0xea)]]);else{if(_0x39781d[_0x28b2ab(0xf3)]===_0x28b2ab(0xde))switch(_0x39781d['id']){case _0x28b2ab(0xbe):_0x21a01b[_0x28b2ab(0xfc)]({'role':_0x28b2ab(0x112),'content':_0x6a7cdf});break;case _0x28b2ab(0xcf):_0x21a01b[_0x28b2ab(0xfc)]({'role':_0x28b2ab(0x112),'content':_0x2dddf8});break;case'coreContent':_0x21a01b[_0x28b2ab(0xfc)]({'role':_0x28b2ab(0xe3),'content':_0x28b2ab(0xba)+_0x350276+_0x28b2ab(0xc5)});break;}}}if(!_0xce554b||_0xce554b['length']===0x0){const _0x3c7372=[{'role':'system','content':generateRandomSeed()}];_0x21a01b[_0x28b2ab(0xb1)](0x1,0x0,..._0x3c7372);}console[_0x28b2ab(0xd3)](_0x28b2ab(0x106)+_0x4590af+'/'+totalBatches+'\x20-\x20即将发送至\x20API\x20的内容'),console[_0x28b2ab(0x10e)](_0x21a01b),console[_0x28b2ab(0xbb)]();const _0x3c0a64=await callTableModel(_0x21a01b);console[_0x28b2ab(0xf1)](_0x28b2ab(0x106)+_0x4590af+'/'+totalBatches+'\x20-\x20收到\x20API\x20原始回复:',_0x3c0a64);if(!_0x3c0a64)throw new Error(_0x28b2ab(0xda));updateTableFromText(_0x3c0a64),renderTables(),log(_0x28b2ab(0xe7)+_0x4590af+'\x20处理成功。',_0x28b2ab(0x105)),currentBatch=_0x4590af,setTimeout(processNextBatch,0x3e8);}catch(_0x4367ee){log('批次\x20'+_0x4590af+_0x28b2ab(0xdf)+(_0x5533a5+0x1)+_0x28b2ab(0x114)+_0x4367ee[_0x28b2ab(0xe5)],'error'),_0x5533a5>=MAX_RETRIES?(log('批次\x20'+_0x4590af+_0x28b2ab(0xb6),_0x28b2ab(0xd9)),toastr[_0x28b2ab(0xd9)](_0x28b2ab(0xe7)+_0x4590af+'\x20多次失败,请检查网络或API设置后手动继续。',_0x28b2ab(0xd2)),currentBatch=_0x4590af-0x1,updateButtonState(_0x28b2ab(0xd9))):(log(_0x28b2ab(0x116)+_0x4590af+_0x28b2ab(0x102),_0x28b2ab(0x10b)),setTimeout(()=>runBatchAttempt(_0x4590af,_0x5533a5+0x1),0xbb8));}}async function processNextBatch(){const _0x21ccc2=_0x31264b;if(manualStopRequested){log(_0x21ccc2(0xf6)+(currentBatch+0x1)+_0x21ccc2(0xe0),'warn'),updateButtonState(_0x21ccc2(0xdd));return;}if(currentBatch>=totalBatches){log(_0x21ccc2(0xd4),_0x21ccc2(0x105)),updateButtonState('idle');return;}runBatchAttempt(currentBatch+0x1,0x0);}function _0x2c3b(){const _0x46cb84=['\x20的内容...','index','正在处理批次\x20','楼层\x20','\x20-\x20收到\x20API\x20原始回复:','prompt','5577611nEToDV','content','log','\x20填表失败:\x20','type','historiographyTags','[楼层填表]\x20加载混合顺序失败:','任务已在批次\x20','通讯异常','1500016wEgCkF','warning','batch_filler','idle','push','\x20楼】\x20','当前没有聊天记录。','表格系统总开关已关闭,无法执行楼层填表。','立即填表','\x20填表完成!','...','join','trim','success','[Amily2\x20立即远征]\x20批次\x20','45APFNSG','{{{Amily2TableData}}}','楼层填表失败:\x20','从上次暂停处继续处理...','warn','\x20超出了当前聊天记录长度\x20','23930skkfIF','dir','amily2_prompt_presets_v2_mixed_order','map','disabled','system','指定楼层范围内没有有效内容可处理。','\x20失败:\x20','聊天记录为空,无需填表。','将在3秒后自动重试批次\x20','slice','stopping','24iOjiOH','点击停止\x20(','startsWith','点击停止','getElementById','ceil','18723cYNGMg','132RZnUGV','\x20-\x20即将发送至\x20API\x20的内容','表格系统总开关已关闭,跳过楼层填表。','7sOStHJ','开始处理楼层\x20','is_user','batch-filling-threshold','表格系统总开关已关闭,无法执行批量填表。','name1','historiographyExclusionRules','与模型通讯时发生异常:\x20','\x20(尝试\x20','coreContent','无法开始','textContent','splice','parse','\x20个批次。',',\x20尝试\x20','\x20(楼层\x20','\x20已达到最大重试次数,任务暂停。','继续填表\x20(出错)','7532562SGotXe','净化后无有效内容可处理。','请严格根据以下\x22对话记录\x22中的内容进行填写表格,并按照指定的格式输出,不要添加任何额外信息。\x0a\x0a<对话记录>\x0a','groupEnd','[批量填表]\x20加载混合顺序失败:','char','ruleTemplate','正在停止...','1249238vyhxMb','filter','继续填表','处理失败','chat','\x0a','getItem','[Amily2\x20楼层填表]\x20楼层\x20','请确保\x22规则提示词\x22和\x22流程提示词\x22都已填写。','value','mes','准备开始批量填表任务,共\x20','停战敕令已下达!将在当前批次完成后暂停。','floor','55KLbqBS','flowTemplate','min','historiographyTagExtractionEnabled','任务暂停','groupCollapsed','所有批次处理完毕!','processing','366MlPdnF','【第\x20','info','error','API返回内容为空。','table_system_enabled','规则或流程提示词为空,无法开始填表。','paused','conditional','\x20尝试\x20','\x20开始前手动暂停。','1068610yIBpOF','author','user','replace','message','name2','批次\x20','length'];_0x2c3b=function(){return _0x46cb84;};return _0x2c3b();}export function startBatchFilling(){const _0x4a9150=_0x31264b,_0x13e102=fillButton();if(!_0x13e102)return;const _0x2e9508=extension_settings[extensionName],_0x9dc759=_0x2e9508[_0x4a9150(0xdb)]!==![];if(!_0x9dc759){log('表格系统总开关已关闭,跳过批量填表。','info'),toastr[_0x4a9150(0xd8)](_0x4a9150(0xa9));return;}if(isFilling){if(_0x13e102[_0x4a9150(0xb0)][_0x4a9150(0x11b)](_0x4a9150(0x11c)))manualStopRequested=!![],updateButtonState('stopping'),log(_0x4a9150(0xcc),'warn');else _0x13e102[_0x4a9150(0xb0)]['startsWith'](_0x4a9150(0xc2))&&(manualStopRequested=![],log(_0x4a9150(0x10a),_0x4a9150(0xd8)),processNextBatch());return;}manualStopRequested=![];const _0x17095c=getContext();chatHistoryLength=_0x17095c['chat'][_0x4a9150(0xe8)],threshold=parseInt(document[_0x4a9150(0x11d)](_0x4a9150(0xa8))?.[_0x4a9150(0xc9)],0xa)||0x1e;const _0x467513=getBatchFillerRuleTemplate(),_0x4edbd1=getBatchFillerFlowTemplate();if(!_0x467513||!_0x4edbd1){log(_0x4a9150(0xdc),_0x4a9150(0xd9)),toastr[_0x4a9150(0xd9)]('请确保\x22规则提示词\x22和\x22流程提示词\x22都已填写。','无法开始');return;}if(chatHistoryLength===0x0){log(_0x4a9150(0x115),_0x4a9150(0xd8));return;}totalBatches=Math[_0x4a9150(0x11e)](chatHistoryLength/threshold),currentBatch=0x0,log(_0x4a9150(0xcb)+totalBatches+_0x4a9150(0xb3),_0x4a9150(0xd8)),processNextBatch();}export async function startFloorRangeFilling(_0x4362de,_0x15af53){const _0x40ba4d=_0x31264b,_0x2078ae=extension_settings[extensionName],_0x31c688=_0x2078ae[_0x40ba4d(0xdb)]!==![];if(!_0x31c688){log(_0x40ba4d(0x122),'info'),toastr['info'](_0x40ba4d(0xff));return;}const _0x34c847=getContext(),_0x5e790f=_0x34c847['chat'][_0x40ba4d(0xe8)];if(_0x15af53>_0x5e790f){toastr[_0x40ba4d(0xf9)]('结束楼层\x20'+_0x15af53+_0x40ba4d(0x10c)+_0x5e790f+'。');return;}const _0xfaffad=getBatchFillerRuleTemplate(),_0x43e0c9=getBatchFillerFlowTemplate();if(!_0xfaffad||!_0x43e0c9){log('规则或流程提示词为空,无法开始楼层填表。',_0x40ba4d(0xd9)),toastr['error'](_0x40ba4d(0xc8),_0x40ba4d(0xaf));return;}try{log(_0x40ba4d(0xa6)+_0x4362de+'-'+_0x15af53+_0x40ba4d(0xe9),_0x40ba4d(0xd8));const _0x578595=getRawMessagesForSummary(_0x4362de,_0x15af53);if(!_0x578595||_0x578595[_0x40ba4d(0xe8)]===0x0){toastr[_0x40ba4d(0xf9)](_0x40ba4d(0x113));return;}const _0x326c5b=_0x578595[_0x40ba4d(0x110)](_0x28e4af=>_0x40ba4d(0xd7)+_0x28e4af[_0x40ba4d(0xcd)]+_0x40ba4d(0xfd)+_0x28e4af[_0x40ba4d(0xe2)]+':\x20'+_0x28e4af['content'])[_0x40ba4d(0x103)]('\x0a'),_0x50437c=convertTablesToCsvString(),_0x312ae6=_0x43e0c9[_0x40ba4d(0xe4)](_0x40ba4d(0x108),_0x50437c);let _0x23dfa4;try{const _0x3a773f=localStorage[_0x40ba4d(0xc6)](_0x40ba4d(0x10f));_0x3a773f&&(_0x23dfa4=JSON[_0x40ba4d(0xb2)](_0x3a773f));}catch(_0xf9c733){console[_0x40ba4d(0xd9)](_0x40ba4d(0xf5),_0xf9c733);}const _0x138d33=getMixedOrder(_0x40ba4d(0xfa))||[],_0x49248c=getPresetPrompts(_0x40ba4d(0xfa)),_0x4e9046=[{'role':_0x40ba4d(0x112),'content':generateRandomSeed()}];for(const _0x4114be of _0x138d33){if(_0x4114be[_0x40ba4d(0xf3)]==='prompt')_0x49248c&&_0x49248c[_0x4114be[_0x40ba4d(0xea)]]&&_0x4e9046[_0x40ba4d(0xfc)](_0x49248c[_0x4114be[_0x40ba4d(0xea)]]);else{if(_0x4114be[_0x40ba4d(0xf3)]===_0x40ba4d(0xde))switch(_0x4114be['id']){case _0x40ba4d(0xbe):_0x4e9046['push']({'role':_0x40ba4d(0x112),'content':_0xfaffad});break;case _0x40ba4d(0xcf):_0x4e9046[_0x40ba4d(0xfc)]({'role':_0x40ba4d(0x112),'content':_0x312ae6});break;case _0x40ba4d(0xae):_0x4e9046[_0x40ba4d(0xfc)]({'role':'user','content':_0x40ba4d(0xba)+_0x326c5b+'\x0a'});break;}}}if(!_0x49248c||_0x49248c['length']===0x0){const _0x215333=[{'role':'system','content':generateRandomSeed()}];_0x4e9046[_0x40ba4d(0xb1)](0x1,0x0,..._0x215333);}console[_0x40ba4d(0xd3)](_0x40ba4d(0xc7)+_0x4362de+'-'+_0x15af53+_0x40ba4d(0x121)),console[_0x40ba4d(0x10e)](_0x4e9046),console[_0x40ba4d(0xbb)]();const _0x552106=await callTableModel(_0x4e9046);console[_0x40ba4d(0xf1)]('[Amily2\x20楼层填表]\x20楼层\x20'+_0x4362de+'-'+_0x15af53+_0x40ba4d(0xed),_0x552106);if(!_0x552106)throw new Error(_0x40ba4d(0xda));updateTableFromText(_0x552106),renderTables(),toastr[_0x40ba4d(0x105)](_0x40ba4d(0xec)+_0x4362de+'-'+_0x15af53+_0x40ba4d(0x101)),log(_0x40ba4d(0xec)+_0x4362de+'-'+_0x15af53+'\x20填表处理完成。',_0x40ba4d(0x105));}catch(_0x2e7e0b){log(_0x40ba4d(0xec)+_0x4362de+'-'+_0x15af53+_0x40ba4d(0xf2)+_0x2e7e0b[_0x40ba4d(0xe5)],_0x40ba4d(0xd9)),toastr[_0x40ba4d(0xd9)](_0x40ba4d(0x109)+_0x2e7e0b[_0x40ba4d(0xe5)],_0x40ba4d(0xc3));}}export async function startCurrentFloorFilling(){const _0x20e15c=_0x31264b,_0x5b29e0=getContext(),_0x58a639=_0x5b29e0[_0x20e15c(0xc4)]['length'];if(_0x58a639===0x0){toastr[_0x20e15c(0xd8)](_0x20e15c(0xfe));return;}log('准备填写当前楼层(第\x20'+_0x58a639+'\x20楼)...',_0x20e15c(0xd8)),await startFloorRangeFilling(_0x58a639,_0x58a639);} +function _0x3ef0(_0x444a94,_0xe39457){const _0x154c8d=_0x154c();return _0x3ef0=function(_0x3ef0e4,_0x5dbcf5){_0x3ef0e4=_0x3ef0e4-0x17f;let _0x298393=_0x154c8d[_0x3ef0e4];return _0x298393;},_0x3ef0(_0x444a94,_0xe39457);}const _0x27e233=_0x3ef0;(function(_0x86b4b4,_0x11cc2d){const _0x2ea385=_0x3ef0,_0x3aac01=_0x86b4b4();while(!![]){try{const _0x209304=parseInt(_0x2ea385(0x1b2))/0x1+parseInt(_0x2ea385(0x192))/0x2+parseInt(_0x2ea385(0x1f1))/0x3*(parseInt(_0x2ea385(0x199))/0x4)+-parseInt(_0x2ea385(0x194))/0x5*(parseInt(_0x2ea385(0x1bc))/0x6)+parseInt(_0x2ea385(0x19b))/0x7*(-parseInt(_0x2ea385(0x183))/0x8)+parseInt(_0x2ea385(0x1b4))/0x9+-parseInt(_0x2ea385(0x1e9))/0xa;if(_0x209304===_0x11cc2d)break;else _0x3aac01['push'](_0x3aac01['shift']());}catch(_0x40e449){_0x3aac01['push'](_0x3aac01['shift']());}}}(_0x154c,0xbcbb7));import{getContext,extension_settings}from'/scripts/extensions.js';import{log}from'./logger.js';import{updateTableFromText}from'./manager.js';import{extensionName}from'../../utils/settings.js';function _0x154c(){const _0x3e6fb9=['任务已在批次\x20','getItem','error','conditional','\x20(楼层\x20','\x20个批次。','historiographyTags','\x20开始前手动暂停。','processing','处理失败','chat','join','[楼层填表]\x20加载混合顺序失败:','groupCollapsed','disabled','trim','coreContent','指定楼层范围内没有有效内容可处理。','223441BjsWCu','规则或流程提示词为空,无法开始填表。','8927226MmkJNY','\x20-\x20收到\x20API\x20原始回复:','停战敕令已下达!将在当前批次完成后暂停。','无法开始','min','点击停止','idle','结束楼层\x20','1164WJItCc','batch_filler','splice','表格系统总开关已关闭,跳过楼层填表。','warning','parse','batch-filling-threshold','正在处理批次\x20','\x20楼】\x20','准备填写当前楼层(第\x20','type','[Amily2\x20楼层填表]\x20楼层\x20','prompt','textContent','\x20失败:\x20','\x20超出了当前聊天记录长度\x20','点击停止\x20(','...','\x20的内容...','filter','replace','表格系统总开关已关闭,跳过批量填表。','表格系统总开关已关闭,无法执行楼层填表。','\x20已达到最大重试次数,任务暂停。','楼层\x20','char','通讯异常','name2','\x20楼)...','从上次暂停处继续处理...','楼层填表失败:\x20','getElementById','[批量填表]\x20加载混合顺序失败:','user','\x20填表处理完成。','聊天记录为空,无需填表。','请确保\x22规则提示词\x22和\x22流程提示词\x22都已填写。','success','system','\x20填表完成!','historiographyTagExtractionEnabled','\x20-\x20即将发送至\x20API\x20的内容','startsWith','stopping','length','25020KUQRVP','value','historiographyExclusionRules','table_system_enabled','正在停止...','fill-table-now-btn','请严格根据以下\x22对话记录\x22中的内容进行填写表格,并按照指定的格式输出,不要添加任何额外信息。\x0a\x0a<对话记录>\x0a',',\x20尝试\x20','459915cRbSZi','{{{Amily2TableData}}}','API返回内容为空。','log','is_user','\x20处理成功。','[Amily2\x20立即远征]\x20批次\x20','\x0a','map','amily2_prompt_presets_v2_mixed_order','8QEfAdV','floor','规则或流程提示词为空,无法开始楼层填表。','slice','所有批次处理完毕!','继续填表','flowTemplate','当前没有聊天记录。','【第\x20','与模型通讯时发生异常:\x20','message','立即填表','批次\x20','content','info','1793128BQUhoG','将在3秒后自动重试批次\x20','28265QgDTbC','warn','author','groupEnd','dir','4hVXPts','push','2750951JpYRnc','继续填表\x20(出错)','\x20多次失败,请检查网络或API设置后手动继续。','\x20填表失败:\x20','paused'];_0x154c=function(){return _0x3e6fb9;};return _0x154c();}import{renderTables}from'../../ui/table-bindings.js';import{getPresetPrompts,getMixedOrder}from'../../PresetSettings/index.js';import{callAI,generateRandomSeed}from'../api.js';import{extractBlocksByTags,applyExclusionRules}from'../utils/rag-tag-extractor.js';import{getBatchFillerRuleTemplate,getBatchFillerFlowTemplate,convertTablesToCsvString}from'./manager.js';let isFilling=![],manualStopRequested=![],currentBatch=0x0,totalBatches=0x0,chatHistoryLength=0x0,threshold=0x1e;const MAX_RETRIES=0x2,fillButton=()=>document[_0x27e233(0x1db)](_0x27e233(0x1ee));function updateButtonState(_0x3d6f13,_0xc4cd87=0x0,_0x258c2b=0x0){const _0x575c15=_0x27e233,_0x30a38a=fillButton();if(!_0x30a38a)return;switch(_0x3d6f13){case _0x575c15(0x1a8):let _0x59e3e7=_0x258c2b>0x0?'\x20(尝试\x20'+(_0x258c2b+0x1)+')':'';_0x30a38a[_0x575c15(0x1c9)]=_0x575c15(0x1cc)+_0xc4cd87+'/'+totalBatches+')'+_0x59e3e7,_0x30a38a[_0x575c15(0x1ae)]=![],isFilling=!![];break;case _0x575c15(0x1e7):_0x30a38a['textContent']=_0x575c15(0x1ed),_0x30a38a['disabled']=!![];break;case _0x575c15(0x19f):_0x30a38a['textContent']=_0x575c15(0x188),_0x30a38a['disabled']=![],isFilling=!![];break;case'error':_0x30a38a[_0x575c15(0x1c9)]=_0x575c15(0x19c),_0x30a38a['disabled']=![],isFilling=!![];break;case _0x575c15(0x1ba):default:_0x30a38a['textContent']=_0x575c15(0x18e),_0x30a38a[_0x575c15(0x1ae)]=![],isFilling=![],currentBatch=0x0,manualStopRequested=![];break;}}async function callTableModel(_0xb6cba1){const _0x2f4f2c=_0x27e233;try{const _0x428962=await callAI(_0xb6cba1);if(!_0x428962)throw new Error(_0x2f4f2c(0x1f3));return _0x428962;}catch(_0x44fdc0){return log(_0x2f4f2c(0x18c)+_0x44fdc0[_0x2f4f2c(0x18d)],_0x2f4f2c(0x1a2)),toastr[_0x2f4f2c(0x1a2)]('与模型通讯时发生异常:\x20'+_0x44fdc0[_0x2f4f2c(0x18d)],_0x2f4f2c(0x1d6)),null;}}function getRawMessagesForSummary(_0xc0321a,_0xd47196){const _0x230853=_0x27e233,_0x4b52ee=getContext(),_0xa953fa=_0x4b52ee[_0x230853(0x1aa)],_0x43e742=extension_settings[extensionName],_0x5f49d3=_0xa953fa[_0x230853(0x186)](_0xc0321a-0x1,_0xd47196);if(_0x5f49d3[_0x230853(0x1e8)]===0x0)return null;const _0x3dfba3=_0x4b52ee['name1']||'用户',_0x2cecc4=_0x4b52ee[_0x230853(0x1d7)]||'角色',_0x4f6dbf=_0x43e742[_0x230853(0x1e4)]??![],_0x457775=_0x4f6dbf?(_0x43e742[_0x230853(0x1a6)]||'')['split'](',')[_0x230853(0x181)](_0xeab8e5=>_0xeab8e5[_0x230853(0x1af)]())[_0x230853(0x1cf)](Boolean):[],_0x46f05e=_0x43e742[_0x230853(0x1eb)]||[],_0x57533a=_0x5f49d3[_0x230853(0x181)]((_0x44390d,_0xceb471)=>{const _0x505277=_0x230853;let _0x2afbe7=_0x44390d['mes'];if(_0x4f6dbf&&_0x457775[_0x505277(0x1e8)]>0x0){const _0x17b180=extractBlocksByTags(_0x2afbe7,_0x457775);_0x17b180['length']>0x0&&(_0x2afbe7=_0x17b180[_0x505277(0x1ab)]('\x0a\x0a'));}_0x2afbe7=applyExclusionRules(_0x2afbe7,_0x46f05e);if(!_0x2afbe7[_0x505277(0x1af)]())return null;return{'floor':_0xc0321a+_0xceb471,'author':_0x44390d[_0x505277(0x1f5)]?_0x3dfba3:_0x2cecc4,'authorType':_0x44390d[_0x505277(0x1f5)]?_0x505277(0x1dd):_0x505277(0x1d5),'content':_0x2afbe7[_0x505277(0x1af)]()};})['filter'](Boolean);return _0x57533a;}async function runBatchAttempt(_0x1127b3,_0x3751f4){const _0x2f61f1=_0x27e233;try{if(manualStopRequested){log(_0x2f61f1(0x1a0)+_0x1127b3+_0x2f61f1(0x1a7),_0x2f61f1(0x195)),updateButtonState(_0x2f61f1(0x19f));return;}updateButtonState('processing',_0x1127b3,_0x3751f4);const _0x5413a4=(_0x1127b3-0x1)*threshold+0x1,_0x47a516=Math[_0x2f61f1(0x1b8)](_0x5413a4+threshold-0x1,chatHistoryLength);log(_0x2f61f1(0x1c3)+_0x1127b3+'/'+totalBatches+_0x2f61f1(0x1a4)+_0x5413a4+'-'+_0x47a516+_0x2f61f1(0x1f0)+(_0x3751f4+0x1)+'/'+(MAX_RETRIES+0x1)+')','info');const _0x142f08=getRawMessagesForSummary(_0x5413a4,_0x47a516);if(!_0x142f08||_0x142f08['length']===0x0)throw new Error('净化后无有效内容可处理。');const _0x37440c=_0x142f08['map'](_0x4476f4=>_0x2f61f1(0x18b)+_0x4476f4[_0x2f61f1(0x184)]+_0x2f61f1(0x1c4)+_0x4476f4[_0x2f61f1(0x196)]+':\x20'+_0x4476f4['content'])[_0x2f61f1(0x1ab)]('\x0a'),_0x5048f0=getBatchFillerRuleTemplate(),_0x5f2c55=getBatchFillerFlowTemplate(),_0xc03a5c=convertTablesToCsvString(),_0x50aeb2=_0x5f2c55['replace'](_0x2f61f1(0x1f2),_0xc03a5c);let _0x88cc2c;try{const _0x1a17eb=localStorage[_0x2f61f1(0x1a1)](_0x2f61f1(0x182));_0x1a17eb&&(_0x88cc2c=JSON[_0x2f61f1(0x1c1)](_0x1a17eb));}catch(_0x27efad){console[_0x2f61f1(0x1a2)](_0x2f61f1(0x1dc),_0x27efad);}const _0x53145a=getMixedOrder(_0x2f61f1(0x1bd))||[],_0x4ccb9f=getPresetPrompts(_0x2f61f1(0x1bd)),_0x172640=[{'role':_0x2f61f1(0x1e2),'content':generateRandomSeed()}];let _0x549788=0x0;for(const _0x5841e6 of _0x53145a){if(_0x5841e6[_0x2f61f1(0x1c6)]===_0x2f61f1(0x1c8))_0x4ccb9f&&_0x4ccb9f[_0x549788]&&(_0x172640[_0x2f61f1(0x19a)](_0x4ccb9f[_0x549788]),_0x549788++);else{if(_0x5841e6[_0x2f61f1(0x1c6)]===_0x2f61f1(0x1a3))switch(_0x5841e6['id']){case'ruleTemplate':_0x172640[_0x2f61f1(0x19a)]({'role':_0x2f61f1(0x1e2),'content':_0x5048f0});break;case _0x2f61f1(0x189):_0x172640['push']({'role':_0x2f61f1(0x1e2),'content':_0x50aeb2});break;case _0x2f61f1(0x1b0):_0x172640['push']({'role':_0x2f61f1(0x1dd),'content':_0x2f61f1(0x1ef)+_0x37440c+_0x2f61f1(0x180)});break;}}}if(!_0x4ccb9f||_0x4ccb9f[_0x2f61f1(0x1e8)]===0x0){const _0x4bc58c=[{'role':_0x2f61f1(0x1e2),'content':generateRandomSeed()}];_0x172640[_0x2f61f1(0x1be)](0x1,0x0,..._0x4bc58c);}console[_0x2f61f1(0x1ad)](_0x2f61f1(0x17f)+_0x1127b3+'/'+totalBatches+'\x20-\x20即将发送至\x20API\x20的内容'),console[_0x2f61f1(0x198)](_0x172640),console[_0x2f61f1(0x197)]();const _0xefaaa6=await callTableModel(_0x172640);console['log']('[Amily2\x20立即远征]\x20批次\x20'+_0x1127b3+'/'+totalBatches+_0x2f61f1(0x1b5),_0xefaaa6);if(!_0xefaaa6)throw new Error('API返回内容为空。');updateTableFromText(_0xefaaa6),renderTables(),log(_0x2f61f1(0x18f)+_0x1127b3+_0x2f61f1(0x1f6),_0x2f61f1(0x1e1)),currentBatch=_0x1127b3,setTimeout(processNextBatch,0x3e8);}catch(_0x5b0016){log('批次\x20'+_0x1127b3+'\x20尝试\x20'+(_0x3751f4+0x1)+_0x2f61f1(0x1ca)+_0x5b0016[_0x2f61f1(0x18d)],_0x2f61f1(0x1a2)),_0x3751f4>=MAX_RETRIES?(log('批次\x20'+_0x1127b3+_0x2f61f1(0x1d3),_0x2f61f1(0x1a2)),toastr[_0x2f61f1(0x1a2)](_0x2f61f1(0x18f)+_0x1127b3+_0x2f61f1(0x19d),'任务暂停'),currentBatch=_0x1127b3-0x1,updateButtonState(_0x2f61f1(0x1a2))):(log(_0x2f61f1(0x193)+_0x1127b3+_0x2f61f1(0x1cd),_0x2f61f1(0x195)),setTimeout(()=>runBatchAttempt(_0x1127b3,_0x3751f4+0x1),0xbb8));}}async function processNextBatch(){const _0x596751=_0x27e233;if(manualStopRequested){log('任务已在批次\x20'+(currentBatch+0x1)+'\x20开始前手动暂停。',_0x596751(0x195)),updateButtonState('paused');return;}if(currentBatch>=totalBatches){log(_0x596751(0x187),'success'),updateButtonState('idle');return;}runBatchAttempt(currentBatch+0x1,0x0);}export function startBatchFilling(){const _0x48de8e=_0x27e233,_0x47137b=fillButton();if(!_0x47137b)return;const _0x546697=extension_settings[extensionName],_0x48aab7=_0x546697['table_system_enabled']!==![];if(!_0x48aab7){log(_0x48de8e(0x1d1),'info'),toastr[_0x48de8e(0x191)]('表格系统总开关已关闭,无法执行批量填表。');return;}if(isFilling){if(_0x47137b[_0x48de8e(0x1c9)]['startsWith'](_0x48de8e(0x1b9)))manualStopRequested=!![],updateButtonState('stopping'),log(_0x48de8e(0x1b6),'warn');else _0x47137b['textContent'][_0x48de8e(0x1e6)](_0x48de8e(0x188))&&(manualStopRequested=![],log(_0x48de8e(0x1d9),_0x48de8e(0x191)),processNextBatch());return;}manualStopRequested=![];const _0x35e4e7=getContext();chatHistoryLength=_0x35e4e7[_0x48de8e(0x1aa)][_0x48de8e(0x1e8)],threshold=parseInt(document[_0x48de8e(0x1db)](_0x48de8e(0x1c2))?.[_0x48de8e(0x1ea)],0xa)||0x1e;const _0x39b401=getBatchFillerRuleTemplate(),_0x23d377=getBatchFillerFlowTemplate();if(!_0x39b401||!_0x23d377){log(_0x48de8e(0x1b3),_0x48de8e(0x1a2)),toastr[_0x48de8e(0x1a2)](_0x48de8e(0x1e0),_0x48de8e(0x1b7));return;}if(chatHistoryLength===0x0){log(_0x48de8e(0x1df),_0x48de8e(0x191));return;}totalBatches=Math['ceil'](chatHistoryLength/threshold),currentBatch=0x0,log('准备开始批量填表任务,共\x20'+totalBatches+_0x48de8e(0x1a5),_0x48de8e(0x191)),processNextBatch();}export async function startFloorRangeFilling(_0x1565e0,_0xbc1023){const _0x35af92=_0x27e233,_0x40b86d=extension_settings[extensionName],_0x2bdab4=_0x40b86d[_0x35af92(0x1ec)]!==![];if(!_0x2bdab4){log(_0x35af92(0x1bf),_0x35af92(0x191)),toastr['info'](_0x35af92(0x1d2));return;}const _0x5cf0df=getContext(),_0x2ec694=_0x5cf0df['chat'][_0x35af92(0x1e8)];if(_0xbc1023>_0x2ec694){toastr[_0x35af92(0x1c0)](_0x35af92(0x1bb)+_0xbc1023+_0x35af92(0x1cb)+_0x2ec694+'。');return;}const _0x39ddbc=getBatchFillerRuleTemplate(),_0x5749a2=getBatchFillerFlowTemplate();if(!_0x39ddbc||!_0x5749a2){log(_0x35af92(0x185),_0x35af92(0x1a2)),toastr['error'](_0x35af92(0x1e0),_0x35af92(0x1b7));return;}try{log('开始处理楼层\x20'+_0x1565e0+'-'+_0xbc1023+_0x35af92(0x1ce),_0x35af92(0x191));const _0x4ff97a=getRawMessagesForSummary(_0x1565e0,_0xbc1023);if(!_0x4ff97a||_0x4ff97a[_0x35af92(0x1e8)]===0x0){toastr[_0x35af92(0x1c0)](_0x35af92(0x1b1));return;}const _0x3df1d0=_0x4ff97a[_0x35af92(0x181)](_0x3e80cd=>_0x35af92(0x18b)+_0x3e80cd['floor']+_0x35af92(0x1c4)+_0x3e80cd[_0x35af92(0x196)]+':\x20'+_0x3e80cd[_0x35af92(0x190)])['join']('\x0a'),_0x12da19=convertTablesToCsvString(),_0x4f7e78=_0x5749a2[_0x35af92(0x1d0)](_0x35af92(0x1f2),_0x12da19);let _0x3a89dc;try{const _0x2f8212=localStorage[_0x35af92(0x1a1)](_0x35af92(0x182));_0x2f8212&&(_0x3a89dc=JSON[_0x35af92(0x1c1)](_0x2f8212));}catch(_0x8120d8){console[_0x35af92(0x1a2)](_0x35af92(0x1ac),_0x8120d8);}const _0x40427c=getMixedOrder(_0x35af92(0x1bd))||[],_0x2d1307=getPresetPrompts(_0x35af92(0x1bd)),_0x2c17bd=[{'role':_0x35af92(0x1e2),'content':generateRandomSeed()}];let _0x112e4c=0x0;for(const _0x40bbcd of _0x40427c){if(_0x40bbcd[_0x35af92(0x1c6)]===_0x35af92(0x1c8))_0x2d1307&&_0x2d1307[_0x112e4c]&&(_0x2c17bd[_0x35af92(0x19a)](_0x2d1307[_0x112e4c]),_0x112e4c++);else{if(_0x40bbcd[_0x35af92(0x1c6)]===_0x35af92(0x1a3))switch(_0x40bbcd['id']){case'ruleTemplate':_0x2c17bd[_0x35af92(0x19a)]({'role':'system','content':_0x39ddbc});break;case'flowTemplate':_0x2c17bd[_0x35af92(0x19a)]({'role':_0x35af92(0x1e2),'content':_0x4f7e78});break;case'coreContent':_0x2c17bd[_0x35af92(0x19a)]({'role':'user','content':_0x35af92(0x1ef)+_0x3df1d0+_0x35af92(0x180)});break;}}}if(!_0x2d1307||_0x2d1307[_0x35af92(0x1e8)]===0x0){const _0x38f567=[{'role':_0x35af92(0x1e2),'content':generateRandomSeed()}];_0x2c17bd[_0x35af92(0x1be)](0x1,0x0,..._0x38f567);}console['groupCollapsed'](_0x35af92(0x1c7)+_0x1565e0+'-'+_0xbc1023+_0x35af92(0x1e5)),console['dir'](_0x2c17bd),console[_0x35af92(0x197)]();const _0x1a306b=await callTableModel(_0x2c17bd);console[_0x35af92(0x1f4)]('[Amily2\x20楼层填表]\x20楼层\x20'+_0x1565e0+'-'+_0xbc1023+_0x35af92(0x1b5),_0x1a306b);if(!_0x1a306b)throw new Error(_0x35af92(0x1f3));updateTableFromText(_0x1a306b),renderTables(),toastr[_0x35af92(0x1e1)](_0x35af92(0x1d4)+_0x1565e0+'-'+_0xbc1023+_0x35af92(0x1e3)),log(_0x35af92(0x1d4)+_0x1565e0+'-'+_0xbc1023+_0x35af92(0x1de),_0x35af92(0x1e1));}catch(_0x65f2df){log(_0x35af92(0x1d4)+_0x1565e0+'-'+_0xbc1023+_0x35af92(0x19e)+_0x65f2df[_0x35af92(0x18d)],'error'),toastr[_0x35af92(0x1a2)](_0x35af92(0x1da)+_0x65f2df['message'],_0x35af92(0x1a9));}}export async function startCurrentFloorFilling(){const _0x116bf2=_0x27e233,_0x57445a=getContext(),_0x1ec430=_0x57445a[_0x116bf2(0x1aa)][_0x116bf2(0x1e8)];if(_0x1ec430===0x0){toastr[_0x116bf2(0x191)](_0x116bf2(0x18a));return;}log(_0x116bf2(0x1c5)+_0x1ec430+_0x116bf2(0x1d8),_0x116bf2(0x191)),await startFloorRangeFilling(_0x1ec430,_0x1ec430);}