From 983caf0a9c7a9539fcff547b18c1c52d3e47b8b2 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 31 Aug 2025 20:33:03 +0800 Subject: [PATCH] Update rag-processor.js --- core/rag-processor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/rag-processor.js b/core/rag-processor.js index 032e917..9d5bf15 100644 --- a/core/rag-processor.js +++ b/core/rag-processor.js @@ -1 +1 @@ -'use strict';const _0x1cd2d7=_0xe42b;(function(_0x30ea5c,_0x4a3282){const _0x52a690=_0xe42b,_0x48f367=_0x30ea5c();while(!![]){try{const _0x6e1de7=-parseInt(_0x52a690(0x239))/0x1+parseInt(_0x52a690(0x199))/0x2*(parseInt(_0x52a690(0x183))/0x3)+-parseInt(_0x52a690(0x224))/0x4*(-parseInt(_0x52a690(0x229))/0x5)+parseInt(_0x52a690(0x176))/0x6*(-parseInt(_0x52a690(0x1a8))/0x7)+-parseInt(_0x52a690(0x1c2))/0x8+-parseInt(_0x52a690(0x195))/0x9+parseInt(_0x52a690(0x19a))/0xa;if(_0x6e1de7===_0x4a3282)break;else _0x48f367['push'](_0x48f367['shift']());}catch(_0x1c16fb){_0x48f367['push'](_0x48f367['shift']());}}}(_0x2d0a,0x28041));import{extension_prompt_roles,setExtensionPrompt}from'/script.js';import*as _0x215c17 from'./utils/context-utils.js';import{getCollectionIdInfo,getCharacterId,getCharacterStableId}from'./utils/context-utils.js';import{defaultSettings as _0x24e517}from'./rag-settings.js';import*as _0x55731b from'./ingestion-manager.js';import{getEmbeddings,fetchEmbeddingModels as _0x43083b,fetchRerankModels as _0xbd2ece,executeRerank,testApiConnection as _0x4e38d5}from'./rag-api.js';const MODULE_NAME='hanlinyuan-rag-core',OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME=_0x1cd2d7(0x230);let context=null,settings=null,lockedCollectionId=null;export{initialize,getSettings,saveSettings,resetSettings,_0x4e38d5 as testApiConnection,_0x43083b as fetchEmbeddingModels,_0xbd2ece as fetchRerankModels,getVectorCount,purgeStorage,getMessagesForCondensation,processCondensation,ingestTextToHanlinyuan,getCollectionId,toggleSessionLock,isSessionLocked,getLockedSessionInfo,addKnowledgeBase,removeKnowledgeBase,getKnowledgeBases,toggleKnowledgeBase};function initialize(){const _0x3cc720=_0x1cd2d7;context=SillyTavern[_0x3cc720(0x1e0)]();if(!context){console[_0x3cc720(0x186)](_0x3cc720(0x1b1));return;}settings=getSettings(),!window['hanlinyuanRagProcessor']&&(window[_0x3cc720(0x175)]={}),window[_0x3cc720(0x175)][_0x3cc720(0x1f1)]=rearrangeChat,window[_0x3cc720(0x175)][_0x3cc720(0x1f8)]=!![],console[_0x3cc720(0x189)](_0x3cc720(0x1d0));}async function ingestTextToHanlinyuan(_0x13c196,_0xafb920=_0x1cd2d7(0x19c),_0xe77aaa={},_0x1f81b0=()=>{},_0x1ce4a9=null,_0x5aec60=()=>{},_0x424ca0=()=>{},_0x5f4ffe=null,_0x5d8fca=0x0){const _0x1e2877=_0x1cd2d7;if(!_0x13c196||!_0x13c196[_0x1e2877(0x190)]())return{'success':![],'error':_0x1e2877(0x166)};if(!settings)return{'success':![],'error':'核心未初始化'};try{const _0x38c6ce=getCollectionIdInfo(),_0x3983f7=await _0x10bd47();if(_0x38c6ce[_0x1e2877(0x235)]&&_0x38c6ce['oldId']===_0x3983f7&&_0x38c6ce[_0x1e2877(0x235)]!==_0x38c6ce[_0x1e2877(0x164)]){const _0x579910=confirm(_0x1e2877(0x1b3));if(_0x579910)_0x5aec60(_0x1e2877(0x1de)+_0x38c6ce[_0x1e2877(0x235)],'warn'),await purgeStorage(_0x38c6ce[_0x1e2877(0x235)]),_0x5aec60(_0x1e2877(0x221),_0x1e2877(0x1c0));else return _0x5aec60('[翰林院-迁移]\x20用户取消了迁移操作。','info'),toastr['info'](_0x1e2877(0x1be)),{'success':![],'error':_0x1e2877(0x168)};}let _0x146e48,_0x196bfb;const _0x188acc=new Date()['toLocaleString'](_0x1e2877(0x23f),{'hour12':![]}),_0x36f6d6=getCharacterName()||_0x1e2877(0x1df);switch(_0xafb920){case'chat_history':const _0x1ad3ed=_0xe77aaa[_0x1e2877(0x1f4)]||{},_0x26a48a=_0x1ad3ed[_0x1e2877(0x1e9)]??'?',_0x254e16=_0x1ad3ed[_0x1e2877(0x18f)]===0x0?'末':_0x1ad3ed['end']??'?';_0x146e48=_0x36f6d6+':\x20'+_0x26a48a+'楼-'+_0x254e16+'楼';break;case _0x1e2877(0x209):const _0x1ec3ea=_0xe77aaa['bookName']||'未分类世界书',_0xc3d390=_0xe77aaa[_0x1e2877(0x211)]||_0x1e2877(0x1bf);_0x146e48=_0x1ec3ea+':\x20'+_0xc3d390;break;case _0x1e2877(0x1f3):_0x146e48=_0x1e2877(0x216)+(_0xe77aaa[_0x1e2877(0x1e3)]||_0x1e2877(0x231));break;case _0x1e2877(0x19c):default:_0x146e48=_0x1e2877(0x1d9)+_0x188acc;break;}const _0x173776=Object[_0x1e2877(0x1dd)](getKnowledgeBases()),_0x5a33e7=_0x173776[_0x1e2877(0x21f)](_0xcf0658=>_0xcf0658[_0x1e2877(0x218)]===_0x146e48);if(_0x5a33e7)_0x196bfb=_0x5a33e7['id'],_0x5aec60('[翰林院-核心]\x20检测到同名知识库\x20\x22'+_0x146e48+_0x1e2877(0x172),_0x1e2877(0x20e));else{_0x5aec60(_0x1e2877(0x1e6)+_0x146e48+_0x1e2877(0x1e1),'info');const _0x1e997a=addKnowledgeBase(_0x146e48);_0x196bfb=_0x1e997a['id'];}const _0x1fed2c=getCharacterStableId(),_0x2d1f29=_0x1fed2c+'_'+_0x196bfb;_0x5aec60('[翰林院-核心]\x20已创建并锁定知识库:\x20'+_0x146e48+_0x1e2877(0x1f9)+_0x2d1f29+')',_0x1e2877(0x1c0)),_0x5aec60('[翰林院-核心]\x20已锁定忆识宝库ID:\x20'+_0x2d1f29,_0x1e2877(0x20e)),_0x1f81b0({'message':'正在智能分块...','processed':0x0,'total':0x1});const _0x55aabf=splitIntoChunks(_0x13c196,_0xafb920,_0xe77aaa),_0x53f4d9=_0x55aabf['length'];if(_0x1ce4a9?.[_0x1e2877(0x1d2)])throw new Error(_0x1e2877(0x200));_0x5aec60(_0x1e2877(0x16c)+_0x146e48+_0x1e2877(0x1c5)+_0x53f4d9+_0x1e2877(0x1e4),'info');if(_0x53f4d9===0x0)return{'success':!![],'count':0x0};const _0x33e8ba=settings['retrieval']['batchSize']||0x5;let _0x4311f4=_0x5d8fca;for(let _0x197b41=_0x5d8fca;_0x197b41<_0x53f4d9;_0x197b41+=_0x33e8ba){if(_0x1ce4a9?.['aborted'])throw new Error('AbortError');const _0x5f3540=_0x55aabf[_0x1e2877(0x206)](_0x197b41,_0x197b41+_0x33e8ba);_0x1f81b0({'message':_0x1e2877(0x232)+(_0x197b41+0x1)+'-'+(_0x197b41+_0x5f3540[_0x1e2877(0x1fb)])+'\x20块','processed':_0x197b41,'total':_0x53f4d9});const _0x347f13=_0x5f3540[_0x1e2877(0x18d)](_0x79d61a=>_0x79d61a['text']),_0xeab248=await getEmbeddings(_0x347f13,_0x1ce4a9);if(_0x1ce4a9?.[_0x1e2877(0x1d2)])throw new Error(_0x1e2877(0x200));if(_0x5f3540[_0x1e2877(0x1fb)]!==_0xeab248['length'])throw new Error(_0x1e2877(0x1d5));const _0x4e4c4e=_0x5f3540[_0x1e2877(0x18d)]((_0x4b35fb,_0x237ba4)=>({..._0x4b35fb,'vector':_0xeab248[_0x237ba4]}));await insertVectors(_0x4e4c4e,_0x1ce4a9,_0x2d1f29),_0x4311f4+=_0x5f3540['length'],_0x5f4ffe&&_0x55731b['saveProgress'](_0x5f4ffe,_0x4311f4,_0x53f4d9),_0x424ca0();}return _0x5f4ffe&&_0x55731b[_0x1e2877(0x193)](_0x5f4ffe),_0x5aec60(_0x1e2877(0x1d3)+_0x4311f4+'\x20个向量条目。',_0x1e2877(0x1c0)),{'success':!![],'count':_0x4311f4};}catch(_0x4f8584){if(_0x4f8584[_0x1e2877(0x218)]==='AbortError'){_0x5aec60(_0x1e2877(0x1cd),'warn');throw _0x4f8584;}return console[_0x1e2877(0x186)](_0x1e2877(0x1a6),_0x4f8584),_0x5aec60(_0x1e2877(0x1f7)+_0x4f8584['message'],_0x1e2877(0x186)),{'success':![],'error':_0x4f8584[_0x1e2877(0x233)]};}}function getSettings(){const _0x575b85=_0x1cd2d7;if(!context||!context[_0x575b85(0x167)])return structuredClone(_0x24e517);let _0x635ada=context['extensionSettings'][MODULE_NAME];!_0x635ada&&(_0x635ada={},context[_0x575b85(0x167)][MODULE_NAME]=_0x635ada);_0x635ada[_0x575b85(0x1ee)]===undefined&&(_0x635ada[_0x575b85(0x1ee)]={});_0x635ada[_0x575b85(0x1ec)]===undefined&&(_0x635ada[_0x575b85(0x1ec)]={});for(const _0xa8e2c in _0x24e517){if(_0x635ada[_0xa8e2c]===undefined)_0x635ada[_0xa8e2c]=structuredClone(_0x24e517[_0xa8e2c]);else{if(typeof _0x24e517[_0xa8e2c]===_0x575b85(0x1a2)&&!Array[_0x575b85(0x223)](_0x24e517[_0xa8e2c])&&_0x24e517[_0xa8e2c]!==null)for(const _0x41624c in _0x24e517[_0xa8e2c]){_0x635ada[_0xa8e2c][_0x41624c]===undefined&&(_0x635ada[_0xa8e2c][_0x41624c]=_0x24e517[_0xa8e2c][_0x41624c]);}}}return _0x635ada;}function saveSettings(){const _0x335b69=_0x1cd2d7;if(context)context[_0x335b69(0x225)]();}function resetSettings(){const _0x2d8481=_0x1cd2d7;context&&(context[_0x2d8481(0x167)][MODULE_NAME]=structuredClone(_0x24e517),saveSettings());}function showNotification(_0x2c5299,_0x27ecfc=_0x1cd2d7(0x20e)){toastr[_0x27ecfc](_0x2c5299);}function getTagForSource(_0x1bdf27){const _0x27333c=_0x1cd2d7;switch(_0x1bdf27){case'chat_history':return _0x27333c(0x220);case'lorebook':return _0x27333c(0x1cc);case _0x27333c(0x19c):return _0x27333c(0x16a);case'novel':return _0x27333c(0x1ef);default:return'资料';}}function splitIntoChunks(_0xe44590,_0x3dbc7e,_0x1da515={}){const _0x3e1618=_0x1cd2d7;switch(_0x3dbc7e){case _0x3e1618(0x1f3):return _chunkForNovel(_0xe44590,_0x1da515);case _0x3e1618(0x16d):return _chunkForChatHistory(_0xe44590,_0x1da515);case'lorebook':return _chunkForLorebook(_0xe44590,_0x1da515);case _0x3e1618(0x19c):return _chunkForManual(_0xe44590,_0x1da515);default:console[_0x3e1618(0x22a)](_0x3e1618(0x1a1)+_0x3dbc7e+'\x27,使用通用分块逻辑。');return _chunkForManual(_0xe44590,{..._0x1da515,'sourceName':_0x1da515[_0x3e1618(0x1e3)]||_0x3e1618(0x22b)});}}function _chunkForNovel(_0x5e9d06,_0x3306be){const _0x3dd368=_0x1cd2d7,{chunkSize:_0x561e8b,overlap:_0x458acb}=settings[_0x3dd368(0x197)],{sourceName:sourceName='小说'}=_0x3306be,_0x3711d0=[];if(!_0x5e9d06||_0x561e8b<=0x0)return _0x3711d0;const _0x3cbfd3=/(第\s*[一二三四五六七八九十百千万零\d]+\s*卷)/gim,_0x32b49b=/(第\s*[一二三四五六七八九十百千万零\d]+\s*[章回节部])|^(Chapter\s+\d+)/gim;let _0x4019d6=0x0;const _0x19a95b=_0x5e9d06[_0x3dd368(0x1ca)]('\x0a');let _0x605e03=_0x3dd368(0x174),_0x3ff47d=_0x3dd368(0x19e),_0x1da6ed=[];function _0x1fc5bb(){const _0x3703f2=_0x3dd368;if(_0x1da6ed[_0x3703f2(0x1fb)]===0x0)return;const _0x4bfe8d=_0x1da6ed[_0x3703f2(0x238)]('\x0a');let _0x3bf8bb=0x0,_0x366ce6=0x1;while(_0x3bf8bb<_0x4bfe8d[_0x3703f2(0x1fb)]){const _0x268353=Math[_0x3703f2(0x1fc)](_0x3bf8bb+_0x561e8b,_0x4bfe8d[_0x3703f2(0x1fb)]),_0x53ecce=_0x4bfe8d['substring'](_0x3bf8bb,_0x268353);if(_0x53ecce[_0x3703f2(0x190)]()[_0x3703f2(0x1fb)]>0x0){const _0x52c7de={'source':'novel','sourceName':sourceName,'timestamp':new Date()[_0x3703f2(0x1bd)](),'globalIndex':_0x4019d6++,'volume':_0x605e03,'chapter':_0x3ff47d,'section':_0x366ce6},_0x4afeff=getTagForSource(_0x3703f2(0x1f3)),_0x4d6e8c=_0x3703f2(0x23a)+sourceName+',\x20'+_0x605e03+',\x20'+_0x3ff47d+_0x3703f2(0x1e7)+_0x366ce6+'节]',_0x4ca8be='<'+_0x4afeff+'>\x0a'+_0x4d6e8c+'\x0a'+_0x53ecce+_0x3703f2(0x21d)+_0x4afeff+'>';_0x3711d0[_0x3703f2(0x179)]({'text':_0x4ca8be,'metadata':_0x52c7de}),_0x366ce6++;}_0x3bf8bb+=_0x561e8b-_0x458acb;if(_0x3bf8bb>=_0x4bfe8d[_0x3703f2(0x1fb)])break;}_0x1da6ed=[];}for(const _0x474a17 of _0x19a95b){const _0x509314=_0x474a17['trim']();if(_0x3cbfd3[_0x3dd368(0x1ba)](_0x509314))_0x1fc5bb(),_0x605e03=_0x509314,_0x3ff47d='第1章';else _0x32b49b[_0x3dd368(0x1ba)](_0x509314)?(_0x1fc5bb(),_0x3ff47d=_0x509314):_0x1da6ed['push'](_0x474a17);}_0x1fc5bb();if(_0x3711d0[_0x3dd368(0x1fb)]===0x0&&_0x5e9d06[_0x3dd368(0x1fb)]>0x0){let _0x1332c4=0x0,_0x15ba3a=0x1;while(_0x1332c4<_0x5e9d06[_0x3dd368(0x1fb)]){const _0x4fa2b4=Math[_0x3dd368(0x1fc)](_0x1332c4+_0x561e8b,_0x5e9d06[_0x3dd368(0x1fb)]),_0x1e0f85=_0x5e9d06[_0x3dd368(0x23e)](_0x1332c4,_0x4fa2b4),_0x536ad3={'source':_0x3dd368(0x1f3),'sourceName':sourceName,'timestamp':new Date()[_0x3dd368(0x1bd)](),'globalIndex':_0x3711d0[_0x3dd368(0x1fb)],'volume':_0x3dd368(0x174),'chapter':_0x3dd368(0x19e),'section':_0x15ba3a},_0x445a5a=getTagForSource('novel'),_0x38626b=_0x3dd368(0x23a)+sourceName+_0x3dd368(0x202)+_0x15ba3a+'节]',_0x46e4a='<'+_0x445a5a+'>\x0a'+_0x38626b+'\x0a'+_0x1e0f85+'\x0a';_0x3711d0['push']({'text':_0x46e4a,'metadata':_0x536ad3}),_0x15ba3a++,_0x1332c4+=_0x561e8b-_0x458acb;}}return _0x3711d0;}function _chunkForChatHistory(_0x404d0b,_0x40f426){const _0x5f39a6=_0x1cd2d7,{chunkSize:_0x9c0b7f,overlap:_0x164bfa}=settings[_0x5f39a6(0x197)],{floor:_0x34faca,is_user:_0x160a22,timestamp:_0x530b15}=_0x40f426,_0x53c9f5=[];if(!_0x404d0b||_0x9c0b7f<=0x0)return _0x53c9f5;let _0x537626=0x1,_0x27ce3c=0x0;while(_0x27ce3c<_0x404d0b[_0x5f39a6(0x1fb)]){const _0x528859=Math[_0x5f39a6(0x1fc)](_0x27ce3c+_0x9c0b7f,_0x404d0b[_0x5f39a6(0x1fb)]),_0x4fc114=_0x404d0b[_0x5f39a6(0x23e)](_0x27ce3c,_0x528859),_0x371649=_0x5f39a6(0x21e)+_0x34faca+',\x20第'+_0x537626+_0x5f39a6(0x1db),_0x1a5e4d=getTagForSource(_0x5f39a6(0x16d)),_0x5d0f7e='<'+_0x1a5e4d+'>\x0a'+_0x371649+'\x0a'+_0x4fc114+_0x5f39a6(0x21d)+_0x1a5e4d+'>';_0x53c9f5[_0x5f39a6(0x179)]({'text':_0x5d0f7e,'metadata':{'source':_0x5f39a6(0x16d),'sourceName':'聊天记录\x20#'+_0x34faca,'floor':_0x34faca,'part':_0x537626,'is_user':_0x160a22,'timestamp':_0x530b15}}),_0x537626++,_0x27ce3c+=_0x9c0b7f-_0x164bfa;if(_0x27ce3c>=_0x404d0b[_0x5f39a6(0x1fb)])break;}return _0x53c9f5;}function _0xe42b(_0x9ce9fe,_0x1dd6e2){const _0x2d0ab6=_0x2d0a();return _0xe42b=function(_0xe42b9b,_0xbaa28b){_0xe42b9b=_0xe42b9b-0x163;let _0x1d3824=_0x2d0ab6[_0xe42b9b];return _0x1d3824;},_0xe42b(_0x9ce9fe,_0x1dd6e2);}function _chunkForLorebook(_0x47894d,_0x41919c){const _0x7c55b6=_0x1cd2d7,{chunkSize:_0x3e4a47,overlap:_0x4675fd}=settings[_0x7c55b6(0x197)],{sourceName:sourceName=_0x7c55b6(0x244)}=_0x41919c,_0x52f79f=[];if(!_0x47894d||_0x3e4a47<=0x0)return _0x52f79f;let _0x4b6772=0x1,_0x1d0837=0x0;while(_0x1d0837<_0x47894d[_0x7c55b6(0x1fb)]){const _0x11fcd3=Math[_0x7c55b6(0x1fc)](_0x1d0837+_0x3e4a47,_0x47894d[_0x7c55b6(0x1fb)]),_0x5960c8=_0x47894d[_0x7c55b6(0x23e)](_0x1d0837,_0x11fcd3),_0x5789d3=_0x7c55b6(0x1c4)+sourceName+_0x7c55b6(0x1e7)+_0x4b6772+_0x7c55b6(0x1db),_0x35720f=getTagForSource(_0x7c55b6(0x209)),_0x31dc0d='<'+_0x35720f+'>\x0a'+_0x5789d3+'\x0a'+_0x5960c8+_0x7c55b6(0x21d)+_0x35720f+'>';_0x52f79f[_0x7c55b6(0x179)]({'text':_0x31dc0d,'metadata':{'source':_0x7c55b6(0x209),'sourceName':sourceName,'part':_0x4b6772,'timestamp':new Date()['toISOString']()}}),_0x4b6772++,_0x1d0837+=_0x3e4a47-_0x4675fd;if(_0x1d0837>=_0x47894d[_0x7c55b6(0x1fb)])break;}return _0x52f79f;}function _chunkForManual(_0x58890c,_0x47553d){const _0x456c9b=_0x1cd2d7,{chunkSize:_0x35840b,overlap:_0x25462a}=settings['advanced'],{sourceName:sourceName=_0x456c9b(0x16a)}=_0x47553d,_0x224924=[];if(!_0x58890c||_0x35840b<=0x0)return _0x224924;const _0x32a348=new Date(),_0x40a8da=_0x32a348[_0x456c9b(0x214)](_0x456c9b(0x23f));let _0xde0d7=0x1,_0x51b3f8=0x0;while(_0x51b3f8<_0x58890c[_0x456c9b(0x1fb)]){const _0x4d3bea=Math[_0x456c9b(0x1fc)](_0x51b3f8+_0x35840b,_0x58890c[_0x456c9b(0x1fb)]),_0x509810=_0x58890c[_0x456c9b(0x23e)](_0x51b3f8,_0x4d3bea),_0xa98a6a=_0x456c9b(0x23a)+sourceName+_0x456c9b(0x236)+_0x40a8da+_0x456c9b(0x1e7)+_0xde0d7+_0x456c9b(0x1db),_0xa71f7c=getTagForSource('manual'),_0x544476='<'+_0xa71f7c+'>\x0a'+_0xa98a6a+'\x0a'+_0x509810+'\x0a';_0x224924[_0x456c9b(0x179)]({'text':_0x544476,'metadata':{'source':_0x456c9b(0x19c),'sourceName':sourceName,'part':_0xde0d7,'timestamp':_0x32a348[_0x456c9b(0x1bd)]()}}),_0xde0d7++,_0x51b3f8+=_0x35840b-_0x25462a;if(_0x51b3f8>=_0x58890c[_0x456c9b(0x1fb)])break;}return _0x224924;}import{getCollectionId as _0x10bd47,getCharacterName}from'./utils/context-utils.js';async function getCollectionId(){return lockedCollectionId||await _0x10bd47();}async function toggleSessionLock(){return lockedCollectionId?(lockedCollectionId=null,![]):(lockedCollectionId=await _0x10bd47(),!![]);}function isSessionLocked(){return lockedCollectionId!==null;}function getLockedSessionInfo(){const _0x10fbc1=_0x1cd2d7;if(!lockedCollectionId)return null;return{'id':lockedCollectionId,'name':_0x10fbc1(0x219)+lockedCollectionId['substring'](0x0,0x8)+_0x10fbc1(0x1ea)};}function getKnowledgeBases(){const _0x4dcc6f=_0x1cd2d7,_0x49833e=getCharacterStableId();return!settings[_0x4dcc6f(0x1ec)][_0x49833e]&&(settings['knowledgeBases'][_0x49833e]={}),settings[_0x4dcc6f(0x1ec)][_0x49833e];}function addKnowledgeBase(_0x4955af){const _0x4639de=_0x1cd2d7;if(!_0x4955af||!_0x4955af['trim']())throw new Error(_0x4639de(0x213));const _0x55900e=getCharacterStableId(),_0x3e7f53=getKnowledgeBases(),_0x3aaa95=_0x4639de(0x242)+Date[_0x4639de(0x1ce)]()+'_'+Math[_0x4639de(0x1e5)]()[_0x4639de(0x23c)](0x24)[_0x4639de(0x23e)](0x2,0x9),_0x48175c={'id':_0x3aaa95,'name':_0x4955af['trim'](),'enabled':!![],'createdAt':new Date()[_0x4639de(0x1bd)]()};return _0x3e7f53[_0x3aaa95]=_0x48175c,saveSettings(),console[_0x4639de(0x189)](_0x4639de(0x21c)+_0x55900e+_0x4639de(0x22e)+_0x4955af+_0x4639de(0x1b2)+_0x3aaa95+')'),_0x48175c;}async function removeKnowledgeBase(_0x2b3bc0){const _0x2d08ba=_0x1cd2d7,_0x27e4cb=getCharacterStableId(),_0x12f5e7=getKnowledgeBases(),_0x353559=_0x12f5e7[_0x2b3bc0]?.[_0x2d08ba(0x218)]||_0x2b3bc0;if(!_0x12f5e7[_0x2b3bc0]){console[_0x2d08ba(0x22a)](_0x2d08ba(0x243)+_0x2b3bc0);return;}const _0x468707=_0x27e4cb+'_'+_0x2b3bc0;console['log'](_0x2d08ba(0x1bc)+_0x2b3bc0+_0x2d08ba(0x1fe)+_0x468707);const _0x3a0589=await purgeStorage(_0x468707);_0x3a0589?(delete _0x12f5e7[_0x2b3bc0],saveSettings(),console[_0x2d08ba(0x189)](_0x2d08ba(0x19f)+_0x2b3bc0+_0x2d08ba(0x215)),toastr['success'](_0x2d08ba(0x180)+_0x353559+_0x2d08ba(0x18a))):(console[_0x2d08ba(0x186)]('[翰林院-核心]\x20清空向量集合\x20'+_0x468707+_0x2d08ba(0x20d)),toastr[_0x2d08ba(0x186)]('删除知识库失败,未能清空后端数据。'));}function toggleKnowledgeBase(_0x5bcfb3){const _0x47620e=_0x1cd2d7,_0x103e85=getKnowledgeBases();_0x103e85[_0x5bcfb3]&&(_0x103e85[_0x5bcfb3]['enabled']=!_0x103e85[_0x5bcfb3][_0x47620e(0x227)],saveSettings(),console[_0x47620e(0x189)](_0x47620e(0x1d7)+_0x5bcfb3+_0x47620e(0x245)+(_0x103e85[_0x5bcfb3]['enabled']?'启用':'禁用')));}function generateHash(_0x8a08ce){const _0x3520af=_0x1cd2d7;let _0x5ed9af=0x0;for(let _0x4cc712=0x0;_0x4cc712<_0x8a08ce['length'];_0x4cc712++){const _0xd81aab=_0x8a08ce['charCodeAt'](_0x4cc712);_0x5ed9af=(_0x5ed9af<<0x5)-_0x5ed9af+_0xd81aab,_0x5ed9af=_0x5ed9af&_0x5ed9af;}return Math[_0x3520af(0x17f)](_0x5ed9af)[_0x3520af(0x23c)](0x24);}async function queryVectors(_0xf2cffa){const _0x32c3ff=_0x1cd2d7;console[_0x32c3ff(0x189)](_0x32c3ff(0x19d));const _0x5ca1d5=getCharacterStableId(),_0x2a3e98=getKnowledgeBases(),_0x50c9fa=Object[_0x32c3ff(0x1dd)](_0x2a3e98)[_0x32c3ff(0x165)](_0x177301=>_0x177301[_0x32c3ff(0x227)]);if(_0x50c9fa['length']===0x0){console['log']('[翰林院-日志]\x20没有启用的新知识库,尝试查询旧版单体宝库...');const _0x5e21e8=await _0x10bd47();if(!_0x5e21e8)return[];_0x50c9fa[_0x32c3ff(0x179)]({'id':null,'name':_0x32c3ff(0x22f)});}const _0x4ba417=(await getEmbeddings([_0xf2cffa]))[0x0];let _0x1edaca=[];const _0x37a55b=_0x50c9fa['map'](_0x5d8f7d=>{const _0x23f5ed=_0x32c3ff,_0x1abc20=_0x5d8f7d['id']===null?_0x10bd47():Promise[_0x23f5ed(0x178)](_0x5ca1d5+'_'+_0x5d8f7d['id']);return _0x1abc20[_0x23f5ed(0x23d)](_0xca9154=>{const _0x9288ca=_0x23f5ed;if(!_0xca9154)return[];console[_0x9288ca(0x189)](_0x9288ca(0x1d6)+_0x5d8f7d[_0x9288ca(0x218)]+_0x9288ca(0x1b2)+_0xca9154+')');const _0x347999={'collectionId':_0xca9154,'searchText':_0xf2cffa,'topK':settings[_0x9288ca(0x197)][_0x9288ca(0x21a)],'threshold':settings[_0x9288ca(0x197)][_0x9288ca(0x1b8)],'source':_0x9288ca(0x192),'embeddings':{[_0xf2cffa]:_0x4ba417}};return fetch('/api/vector/query',{'method':'POST','headers':context[_0x9288ca(0x182)](),'body':JSON[_0x9288ca(0x1b5)](_0x347999)})[_0x9288ca(0x23d)](async _0x4a75b3=>{const _0x13df1d=_0x9288ca;if(!_0x4a75b3['ok']){const _0x366352=await _0x4a75b3[_0x13df1d(0x18b)]();return console[_0x13df1d(0x186)]('[翰林院-日志]\x20查询知识库\x20'+_0xca9154+_0x13df1d(0x16e),_0x366352),[];}const _0x39f567=await _0x4a75b3['json'](),_0x49f45e=_0x39f567[_0x13df1d(0x1ae)]||_0x39f567[_0x13df1d(0x1d4)]||_0x39f567[_0x13df1d(0x1ff)]||[];return console[_0x13df1d(0x189)](_0x13df1d(0x204)+_0x5d8f7d[_0x13df1d(0x218)]+'\x20返回\x20'+_0x49f45e[_0x13df1d(0x1fb)]+_0x13df1d(0x237)),_0x49f45e;})['catch'](_0x1c4de8=>{const _0x5c0238=_0x9288ca;return console[_0x5c0238(0x186)](_0x5c0238(0x20c)+_0xca9154+_0x5c0238(0x1dc),_0x1c4de8),[];});});}),_0x5e9e55=await Promise[_0x32c3ff(0x18e)](_0x37a55b);_0x1edaca=_0x5e9e55['flat'](),console['log'](_0x32c3ff(0x203)+_0x1edaca[_0x32c3ff(0x1fb)]+_0x32c3ff(0x222));const _0x12a38b=[],_0x18090e=new Set();for(const _0x311584 of _0x1edaca){_0x311584&&_0x311584[_0x32c3ff(0x18b)]&&!_0x18090e[_0x32c3ff(0x234)](_0x311584[_0x32c3ff(0x18b)])&&(_0x18090e[_0x32c3ff(0x207)](_0x311584[_0x32c3ff(0x18b)]),_0x12a38b[_0x32c3ff(0x179)](_0x311584));}return console['log']('[翰林院-日志]\x20去重后剩余\x20'+_0x12a38b[_0x32c3ff(0x1fb)]+_0x32c3ff(0x237)),_0x12a38b['sort']((_0x3b4d23,_0x342a65)=>(_0x342a65[_0x32c3ff(0x210)]||0x0)-(_0x3b4d23[_0x32c3ff(0x210)]||0x0)),_0x12a38b;}async function insertVectors(_0x47c0d3,_0x19a0e1=null,_0x3beb22){const _0x4785c8=_0x1cd2d7;if(!_0x3beb22)throw new Error(_0x4785c8(0x22c));if(_0x47c0d3[_0x4785c8(0x1fb)]===0x0)return{'success':!![],'count':0x0};const _0x5dc6a2=_0x47c0d3['map']((_0x1706bf,_0x222095)=>({'hash':generateHash(_0x1706bf[_0x4785c8(0x18b)]+Date[_0x4785c8(0x1ce)]()+_0x222095),'text':_0x1706bf['text'],'metadata':_0x1706bf[_0x4785c8(0x1ae)]||{'source':_0x4785c8(0x1a7),'timestamp':new Date()[_0x4785c8(0x1bd)]()}})),_0x4747a6=_0x5dc6a2[_0x4785c8(0x17c)]((_0x4fae0a,_0xdac317,_0x320028)=>{const _0x3e0bc4=_0x4785c8;return _0x4fae0a[_0xdac317['text']]=_0x47c0d3[_0x320028][_0x3e0bc4(0x1a0)],_0x4fae0a;},{}),_0x525ff0={'collectionId':_0x3beb22,'items':_0x5dc6a2,'source':'webllm','embeddings':_0x4747a6},_0x9e9451=await fetch(_0x4785c8(0x1a3),{'method':_0x4785c8(0x1a5),'headers':context[_0x4785c8(0x182)](),'body':JSON[_0x4785c8(0x1b5)](_0x525ff0),'signal':_0x19a0e1});if(!_0x9e9451['ok']){const _0x271ce1=await _0x9e9451['text']();console[_0x4785c8(0x186)](_0x4785c8(0x217),_0x271ce1);throw new Error(_0x4785c8(0x188)+_0x9e9451[_0x4785c8(0x17d)]+':\x20'+_0x271ce1);}return{'success':!![],'count':_0x5dc6a2[_0x4785c8(0x1fb)]};}function _0x2d0a(){const _0x2df405=['score','entryName','[翰林院-核心]\x20已将\x20','知识库名称不能为空','toLocaleString','\x20及其向量数据。','小说:\x20','[翰林院-日志]\x20忆识存入API错误:','name','(已锁定:\x20','maxResults','max','[翰林院-核心]\x20已为角色\x20','\x0a{const _0x281220=_0x208488+'_'+_0x344642['id'];return countVectorsInCollection(_0x281220);}),_0x45ee16=await _0x10bd47();_0x5c4e2e[_0x1b171a(0x179)](countVectorsInCollection(_0x45ee16));const _0x4f5fa1=await Promise[_0x1b171a(0x18e)](_0x5c4e2e),_0x3fbdea=_0x4f5fa1[_0x1b171a(0x17c)]((_0x3feaf1,_0x516240)=>_0x3feaf1+_0x516240,0x0);return console[_0x1b171a(0x189)](_0x1b171a(0x17e)+_0x3fbdea),_0x3fbdea;}}async function countVectorsInCollection(_0x4fe12f){const _0x2f5ec7=_0x1cd2d7;if(!_0x4fe12f)return 0x0;console[_0x2f5ec7(0x189)](_0x2f5ec7(0x1e8)+_0x4fe12f);const _0x3d64bb={'collectionId':_0x4fe12f,'source':'webllm','embeddings':{}};try{const _0x564c2d=await fetch(_0x2f5ec7(0x1af),{'method':_0x2f5ec7(0x1a5),'headers':context['getRequestHeaders'](),'body':JSON[_0x2f5ec7(0x1b5)](_0x3d64bb)});if(!_0x564c2d['ok']){if(_0x564c2d['status']===0x194)console[_0x2f5ec7(0x189)](_0x2f5ec7(0x1c8)+_0x4fe12f+'\x20不存在,计为\x200。');else{const _0x49143=await _0x564c2d[_0x2f5ec7(0x18b)]();console[_0x2f5ec7(0x22a)](_0x2f5ec7(0x1b4)+_0x4fe12f+_0x2f5ec7(0x16f)+_0x564c2d['status']+'):',_0x49143);}return 0x0;}const _0x37edf7=await _0x564c2d[_0x2f5ec7(0x20b)]();let _0x1643c9=0x0;if(Array['isArray'](_0x37edf7))_0x1643c9=_0x37edf7['length'];else _0x37edf7&&_0x37edf7[_0x2f5ec7(0x16b)]&&(_0x1643c9=_0x37edf7[_0x2f5ec7(0x16b)][_0x2f5ec7(0x1fb)]);return _0x1643c9;}catch(_0x3e3096){return console[_0x2f5ec7(0x186)](_0x2f5ec7(0x177)+_0x4fe12f+_0x2f5ec7(0x1dc),_0x3e3096),0x0;}}async function purgeStorage(_0x341cb7=null){const _0x237803=_0x1cd2d7;console[_0x237803(0x189)]('[翰林院-日志]\x20开始清空宝库...');const _0x507332=_0x341cb7||await getCollectionId();if(!_0x507332)return console[_0x237803(0x186)]('[翰林院-日志]\x20无法确定要清空的目标集合ID。'),toastr[_0x237803(0x186)](_0x237803(0x226)),![];console[_0x237803(0x189)]('[翰林院-日志]\x20清空目标集合ID:\x20'+_0x507332);const _0x1f6b40={'collectionId':_0x507332};console[_0x237803(0x189)]('[翰林院-日志]\x20发送到\x20/api/vector/purge\x20的请求体:',JSON[_0x237803(0x1b5)](_0x1f6b40,null,0x2));const _0x1a8c81=await fetch(_0x237803(0x1aa),{'method':_0x237803(0x1a5),'headers':context['getRequestHeaders'](),'body':JSON[_0x237803(0x1b5)](_0x1f6b40)});console[_0x237803(0x189)]('[翰林院-日志]\x20/api/vector/purge\x20响应状态:\x20'+_0x1a8c81[_0x237803(0x17d)]);if(!_0x1a8c81['ok']){const _0x2faab6=await _0x1a8c81[_0x237803(0x18b)]();console[_0x237803(0x186)](_0x237803(0x1c6),_0x2faab6);}else console[_0x237803(0x189)](_0x237803(0x19b));return _0x1a8c81['ok'];}function getMessagesForCondensation(_0x5e0637=null){const _0x31a997=_0x1cd2d7;if(!settings[_0x31a997(0x1fd)][_0x31a997(0x227)])return showNotification(_0x31a997(0x240),_0x31a997(0x1b0)),[];const {layerStart:_0x53c5a3,layerEnd:_0x4d5568}=settings[_0x31a997(0x1fd)],_0x564199=_0x5e0637||settings[_0x31a997(0x1fd)][_0x31a997(0x191)],_0x565f0a=context[_0x31a997(0x1f5)][_0x31a997(0x1fb)],_0x1a5715=Math[_0x31a997(0x21b)](0x0,_0x53c5a3-0x1),_0xa548b5=_0x4d5568===0x0||_0x4d5568>_0x565f0a?_0x565f0a:Math['min'](_0x565f0a,_0x4d5568),_0x3fb365=context['chat'][_0x31a997(0x206)](_0x1a5715,_0xa548b5);return _0x3fb365[_0x31a997(0x165)](_0x495f4b=>{const _0xe92d82=_0x31a997,_0x3c5e44=_0x495f4b[_0xe92d82(0x1fa)]===!![],_0x53c878=_0x495f4b['is_user']===![];if(!_0x495f4b[_0xe92d82(0x1bb)]||!_0x495f4b[_0xe92d82(0x1bb)]['trim']())return![];return _0x564199[_0xe92d82(0x208)]&&_0x3c5e44||_0x564199['ai']&&_0x53c878;});}async function processCondensation(_0x43094a,_0x7078cb=()=>{},_0x465b65=null){const _0x34f96e=_0x1cd2d7;if(!_0x43094a||_0x43094a[_0x34f96e(0x1fb)]===0x0)return{'success':![],'error':_0x34f96e(0x185)};try{let _0x1c9cda=await getCollectionId();const _0x17b7bc=getCollectionIdInfo();if(_0x17b7bc[_0x34f96e(0x235)]&&_0x17b7bc[_0x34f96e(0x235)]===_0x1c9cda&&_0x17b7bc[_0x34f96e(0x235)]!==_0x17b7bc[_0x34f96e(0x164)]){const _0x2a2f3a=confirm(_0x34f96e(0x1ed));if(_0x2a2f3a)_0x7078cb(_0x34f96e(0x1f6)+_0x17b7bc[_0x34f96e(0x235)],'warn'),await purgeStorage(_0x17b7bc[_0x34f96e(0x235)]),_0x1c9cda=_0x17b7bc[_0x34f96e(0x164)],_0x7078cb(_0x34f96e(0x184)+_0x1c9cda,_0x34f96e(0x1c0));else return _0x7078cb(_0x34f96e(0x228),'info'),toastr['info'](_0x34f96e(0x1be)),{'success':![],'error':_0x34f96e(0x168)};}if(!_0x1c9cda)throw new Error('无法确定当前忆识宝库的ID,请确认角色已正确加载。');_0x7078cb(_0x34f96e(0x205)+_0x1c9cda,_0x34f96e(0x20e));const _0x32fe23=[],_0x2ea4f7=context['chat'];for(const _0x148b12 of _0x43094a){const _0x2a879d=(_0x148b12[_0x34f96e(0x1bb)]||'')[_0x34f96e(0x173)](/<[^>]*>/g,'')[_0x34f96e(0x190)]();if(_0x2a879d['length']===0x0)continue;let _0x294a41;if(_0x148b12['floor']!==undefined&&_0x148b12[_0x34f96e(0x187)]!==null)_0x294a41=_0x148b12[_0x34f96e(0x187)];else{const _0x3bdd79=_0x2ea4f7[_0x34f96e(0x196)](_0x1e83a4=>_0x1e83a4===_0x148b12);_0x294a41=_0x3bdd79!==-0x1?_0x3bdd79+0x1:-0x1;}const _0x59698f=new Date(_0x148b12[_0x34f96e(0x1b7)]),_0x2b58ea=isNaN(_0x59698f[_0x34f96e(0x23b)]())?new Date()['toISOString']():_0x59698f[_0x34f96e(0x1bd)](),_0x2cdf38=splitIntoChunks(_0x2a879d,'chat_history',{'floor':_0x294a41,'is_user':_0x148b12['is_user'],'timestamp':_0x2b58ea});_0x32fe23['push'](..._0x2cdf38);}if(_0x32fe23[_0x34f96e(0x1fb)]===0x0)return{'success':!![],'count':0x0};_0x7078cb(_0x34f96e(0x212)+_0x43094a[_0x34f96e(0x1fb)]+_0x34f96e(0x1eb)+_0x32fe23['length']+_0x34f96e(0x170),_0x34f96e(0x20e));const _0xdadc2f=settings['retrieval'][_0x34f96e(0x1a9)]||0x5;let _0x9d5173=0x0;for(let _0x4332c6=0x0;_0x4332c6<_0x32fe23[_0x34f96e(0x1fb)];_0x4332c6+=_0xdadc2f){const _0x19ab6f=_0x32fe23['slice'](_0x4332c6,_0x4332c6+_0xdadc2f),_0x4b7a0a=_0x19ab6f[_0x34f96e(0x18d)](_0x412603=>_0x412603[_0x34f96e(0x18b)]),_0x2cb943=await getEmbeddings(_0x4b7a0a);if(_0x19ab6f[_0x34f96e(0x1fb)]!==_0x2cb943[_0x34f96e(0x1fb)])throw new Error(_0x34f96e(0x1d5));const _0x8d3a2d=_0x19ab6f[_0x34f96e(0x18d)]((_0x3f3e45,_0xb7945)=>({..._0x3f3e45,'vector':_0x2cb943[_0xb7945]}));await insertVectors(_0x8d3a2d,null,_0x1c9cda),_0x9d5173+=_0x19ab6f[_0x34f96e(0x1fb)];}if(_0x465b65){const _0x1d3e0d=_0x465b65[_0x34f96e(0x18f)]===0x0?context[_0x34f96e(0x1f5)][_0x34f96e(0x1fb)]:_0x465b65[_0x34f96e(0x18f)];settings[_0x34f96e(0x1ee)][_0x1c9cda]={'start':_0x465b65['start'],'end':_0x1d3e0d,'timestamp':new Date()['toISOString']()},saveSettings(),_0x7078cb('[翰林院-核心]\x20已为宝库\x20'+_0x1c9cda+'\x20记录凝识范围:\x20'+_0x465b65['start']+'-'+_0x1d3e0d,'info');}_0x7078cb(_0x34f96e(0x1ad)+_0x9d5173+_0x34f96e(0x18c),_0x34f96e(0x1c0));const _0x5ac0f5=_0x43094a['map'](_0x10c218=>{const _0x4ab48d=_0x34f96e,_0x5be428=_0x2ea4f7[_0x4ab48d(0x196)](_0x180678=>_0x180678===_0x10c218),_0x24a4ca=_0x5be428!==-0x1?_0x5be428+0x1:-0x1,_0x465e83=_0x10c218['is_user']?'用户':getCharacterName()||'AI';return'['+_0x465e83+'\x20-\x20楼层\x20#'+_0x24a4ca+_0x4ab48d(0x201);});return{'success':!![],'count':_0x9d5173,'messages':_0x5ac0f5};}catch(_0x35cc8e){return console['error'](_0x34f96e(0x169),_0x35cc8e),_0x7078cb(_0x34f96e(0x1b6)+_0x35cc8e[_0x34f96e(0x233)],_0x34f96e(0x186)),{'success':![],'error':_0x35cc8e[_0x34f96e(0x233)]};}}async function rerankResults(_0x2554b4,_0x4268da,_0x5c732e){const _0x59349f=_0x1cd2d7;let _0x2f7038=_0x2554b4;if(_0x5c732e[_0x59349f(0x194)][_0x59349f(0x227)]&&_0x2554b4[_0x59349f(0x1fb)]>0x0){console[_0x59349f(0x189)]('[翰林院-Rerank]\x20开始外部API重排序...');try{const _0x462b7d=_0x2554b4[_0x59349f(0x18d)](_0x3a2734=>_0x3a2734[_0x59349f(0x18b)]),_0x45e35f=await executeRerank(_0x4268da,_0x462b7d,_0x5c732e[_0x59349f(0x194)]),_0x246dc2=_0x2554b4['map']((_0x5cc7c8,_0x558107)=>({..._0x5cc7c8,'original_index':_0x558107}));_0x2f7038=_0x246dc2['map'](_0x1745ad=>{const _0x52020d=_0x59349f,_0x4a05d1=_0x45e35f['results'][_0x52020d(0x21f)](_0x5cad77=>_0x5cad77['index']===_0x1745ad[_0x52020d(0x1c3)]),_0x465164=_0x4a05d1?_0x4a05d1[_0x52020d(0x20a)]:0x0;return{..._0x1745ad,'rerank_score':_0x465164};});if(_0x5c732e[_0x59349f(0x194)][_0x59349f(0x1d1)])showNotification(_0x59349f(0x1c7),'success');}catch(_0x1a191a){console[_0x59349f(0x186)]('[翰林院-Rerank]\x20外部Rerank失败,将仅使用内部加权。',_0x1a191a);if(_0x5c732e[_0x59349f(0x194)][_0x59349f(0x1d1)])showNotification(_0x59349f(0x1c9)+_0x1a191a[_0x59349f(0x233)],_0x59349f(0x186));_0x2f7038[_0x59349f(0x1c1)](_0x5a5894=>_0x5a5894[_0x59349f(0x181)]=0x0);}}else _0x2f7038[_0x59349f(0x1c1)](_0x4208e7=>_0x4208e7[_0x59349f(0x181)]=0x0);console[_0x59349f(0x189)](_0x59349f(0x1cb));const _0x207fb0=context[_0x59349f(0x1f5)][_0x59349f(0x1fb)],_0x4c9976=_0x5c732e[_0x59349f(0x194)][_0x59349f(0x198)],_0x5326ab=_0x2f7038[_0x59349f(0x18d)](_0x273ae6=>{const _0x2207eb=_0x59349f;let _0xf342cf=0x1;const _0x2f89c2=_0x273ae6[_0x2207eb(0x1ae)]||{};switch(_0x2f89c2['source']){case _0x2207eb(0x209):_0xf342cf*=1.2;break;case'manual':_0xf342cf*=1.1;break;case _0x2207eb(0x16d):if(_0x2f89c2['floor']&&_0x207fb0>0x0){const _0x3a657e=_0x2f89c2['floor']/_0x207fb0;_0xf342cf*=0x1+_0x3a657e;}break;}const _0x460a88=_0x273ae6[_0x2207eb(0x181)]*_0x4c9976+(_0x273ae6[_0x2207eb(0x210)]||0x0)*(0x1-_0x4c9976),_0x1bc6b8=_0x460a88*_0xf342cf;return{..._0x273ae6,'final_score':_0x1bc6b8};});return _0x5326ab[_0x59349f(0x1f0)]((_0x408119,_0x57e1cb)=>(_0x57e1cb[_0x59349f(0x1ac)]||0x0)-(_0x408119[_0x59349f(0x1ac)]||0x0)),console[_0x59349f(0x189)](_0x59349f(0x20f)),_0x5326ab['slice'](0x0,_0x5c732e[_0x59349f(0x194)][_0x59349f(0x1cf)]);}async function rearrangeChat(_0x17d5c1,_0x3daa7c,_0x2be9ae,_0x57dcf5){const _0x507016=_0x1cd2d7;setExtensionPrompt(_0x507016(0x17a),'',settings['injection'][_0x507016(0x22d)],settings[_0x507016(0x1da)][_0x507016(0x1e2)],![],settings['injection'][_0x507016(0x171)]);if(_0x57dcf5===_0x507016(0x1ab)||!settings[_0x507016(0x1a4)][_0x507016(0x227)])return;const _0x1488eb=_0x17d5c1['slice'](-settings[_0x507016(0x197)][_0x507016(0x1d8)]);if(_0x1488eb[_0x507016(0x1fb)]===0x0)return;const _0x230ee2=_0x1488eb[_0x507016(0x18d)](_0x40ac66=>_0x40ac66['mes'])['join']('\x20')[_0x507016(0x173)](/<[^>]*>/g,'')['trim']();if(!_0x230ee2)return;try{const _0x4ac066=await queryVectors(_0x230ee2);if(_0x4ac066[_0x507016(0x1fb)]===0x0)return;const _0x2e159b=await rerankResults(_0x4ac066,_0x230ee2,settings);if(_0x2e159b['length']===0x0)return;const _0x5a9f79=_0x2e159b[_0x507016(0x18d)](_0x41b003=>_0x41b003[_0x507016(0x18b)])[_0x507016(0x238)]('\x0a\x0a');let _0x5c3fe1=settings[_0x507016(0x1da)][_0x507016(0x163)][_0x507016(0x173)](_0x507016(0x1b9),_0x5a9f79);_0x5c3fe1[_0x507016(0x190)]()&&(_0x5c3fe1='%%HANLINYUAN_RAG_INJECTION%%'+_0x5c3fe1),setExtensionPrompt(_0x507016(0x17a),_0x5c3fe1,settings[_0x507016(0x1da)][_0x507016(0x22d)],settings['injection'][_0x507016(0x1e2)],![],settings[_0x507016(0x1da)]['depth_role']);}catch(_0x5bed2a){console[_0x507016(0x186)](_0x507016(0x17b),_0x5bed2a);if(settings[_0x507016(0x1a4)][_0x507016(0x1d1)])showNotification(_0x507016(0x1f2)+_0x5bed2a[_0x507016(0x233)],_0x507016(0x186));}} +'use strict';const _0x28ef4d=_0x51ca;(function(_0x3d7616,_0x435243){const _0x5563bc=_0x51ca,_0x5334e2=_0x3d7616();while(!![]){try{const _0xc11a6b=-parseInt(_0x5563bc(0x12a))/0x1+-parseInt(_0x5563bc(0x143))/0x2*(parseInt(_0x5563bc(0x125))/0x3)+parseInt(_0x5563bc(0xef))/0x4+parseInt(_0x5563bc(0xba))/0x5*(parseInt(_0x5563bc(0xb6))/0x6)+parseInt(_0x5563bc(0x14e))/0x7*(-parseInt(_0x5563bc(0x179))/0x8)+parseInt(_0x5563bc(0xad))/0x9*(parseInt(_0x5563bc(0x146))/0xa)+parseInt(_0x5563bc(0x115))/0xb;if(_0xc11a6b===_0x435243)break;else _0x5334e2['push'](_0x5334e2['shift']());}catch(_0x3c96d3){_0x5334e2['push'](_0x5334e2['shift']());}}}(_0x289c,0x35c3f));import{extension_prompt_roles,setExtensionPrompt}from'/script.js';function _0x289c(){const _0xb7cdd8=['[翰林院-日志]\x20无法确定要清空的目标集合ID。','object','[翰林院-Rerank]\x20外部Rerank失败,将仅使用内部加权。','initialized','[翰林院-日志]\x20开始获取所有知识库的向量总数...','[翰林院-日志]\x20获取集合\x20','toISOString','getTime','小说录入','[翰林院]\x20未能获取SillyTavern上下文,初始化失败。','[来源:\x20','[翰林院-核心]\x20已创建并锁定知识库:\x20','未分类世界书','[来源:\x20世界书,\x20条目:\x20','未知小说','lorebook','hanlinyuanRagProcessor','[翰林院-核心]\x20准备为任务\x20\x22','sort','status','is_user','aborted','\x20返回\x20','[翰林院-核心]\x20聊天记录凝识完成,成功插入\x20','values','max','matchThreshold','sourceName','[来源:\x20聊天记录,\x20楼层:\x20#','error','\x20条初步结果。','min','\x20失败,删除操作中止。','all','24StchJm','reduce','entryName','info','clearJob','floor','\x27的文本分割成\x20','[翰林院-核心]\x20成功删除知识库\x20','task_','检测到旧版数据。此操作将把旧数据迁移到新格式,过程不可逆,是否继续?','\x20失败:','{{text}}','%%HANLINYUAN_RAG_INJECTION%%','oldId','depth','\x20添加新知识库:\x20','世界书条目','[翰林院-核心]\x20聊天记录凝识失败:\x20','now','\x20个条目。','depth_role','hashes','catch','835929KkvSzp','[翰林院-核心]\x20processCondensation\x20失败:','[翰林院-核心]\x20ingestTextToHanlinyuan\x20失败:','\x20(集合ID:\x20','[翰林院-日志]\x20清空宝库API错误:','\x20个向量条目。','send_date','push','知识库名称不能为空','84IqwAVH','[翰林院-核心]\x20尝试删除一个不存在的知识库:\x20','webllm','rerank','52695piNoVd','[翰林院-日志]\x20所有知识库查询完毕,共获得\x20','\x20不存在,计为\x200。','\x0a{},_0x54788a=null,_0x507397=()=>{},_0x1ab400=()=>{},_0x186322=null,_0x5567d8=0x0){const _0x533b7e=_0x28ef4d;if(!_0x442205||!_0x442205[_0x533b7e(0xdc)]())return{'success':![],'error':'输入文本为空'};if(!settings)return{'success':![],'error':_0x533b7e(0x107)};try{const _0x1d8c8e=getCollectionIdInfo(),_0x30cfe6=await _0x2e9745();if(_0x1d8c8e[_0x533b7e(0xa3)]&&_0x1d8c8e[_0x533b7e(0xa3)]===_0x30cfe6&&_0x1d8c8e[_0x533b7e(0xa3)]!==_0x1d8c8e[_0x533b7e(0xe5)]){const _0x4d9281=confirm(_0x533b7e(0x9f));if(_0x4d9281)_0x507397(_0x533b7e(0x109)+_0x1d8c8e[_0x533b7e(0xa3)],'warn'),await purgeStorage(_0x1d8c8e[_0x533b7e(0xa3)]),_0x507397(_0x533b7e(0xf0),_0x533b7e(0x11e));else return _0x507397(_0x533b7e(0xf4),'info'),toastr[_0x533b7e(0x17c)](_0x533b7e(0x151)),{'success':![],'error':'用户取消了迁移操作'};}let _0x3bf83a,_0x50db11;const _0x402714=new Date()[_0x533b7e(0x10c)](_0x533b7e(0x128),{'hour12':![]}),_0x2b1ce5=getCharacterName()||_0x533b7e(0xd9);switch(_0x430d22){case _0x533b7e(0x126):const _0x5d8202=_0x433292['range']||{},_0x15c9e8=_0x5d8202[_0x533b7e(0xc5)]??'?',_0x39a5a4=_0x5d8202['end']===0x0?'末':_0x5d8202['end']??'?';_0x3bf83a=_0x2b1ce5+':\x20'+_0x15c9e8+'楼-'+_0x39a5a4+'楼';break;case _0x533b7e(0x166):const _0x5446d8=_0x433292[_0x533b7e(0xf2)]||_0x533b7e(0x163),_0x5d1215=_0x433292[_0x533b7e(0x17b)]||'未知条目';_0x3bf83a=_0x5446d8+':\x20'+_0x5d1215;break;case _0x533b7e(0xc0):_0x3bf83a=_0x533b7e(0x11f)+(_0x433292[_0x533b7e(0x172)]||_0x533b7e(0x165));break;case'manual':default:_0x3bf83a='手动录入:\x20'+_0x402714;break;}const _0x306904=Object[_0x533b7e(0x16f)](getKnowledgeBases()),_0x290263=_0x306904[_0x533b7e(0xd1)](_0x472c4b=>_0x472c4b['name']===_0x3bf83a);if(_0x290263)_0x50db11=_0x290263['id'],_0x507397(_0x533b7e(0xcb)+_0x3bf83a+_0x533b7e(0xff),_0x533b7e(0x17c));else{_0x507397(_0x533b7e(0x168)+_0x3bf83a+'\x22\x20创建专属知识库...',_0x533b7e(0x17c));const _0x54e852=addKnowledgeBase(_0x3bf83a);_0x50db11=_0x54e852['id'];}const _0xfc5d6b=getCharacterStableId(),_0x3504d1=_0xfc5d6b+'_'+_0x50db11;_0x507397(_0x533b7e(0x162)+_0x3bf83a+'\x20(集合ID:\x20'+_0x3504d1+')','success'),_0x507397(_0x533b7e(0xea)+_0x3504d1,'info'),_0x3e92ca({'message':_0x533b7e(0x117),'processed':0x0,'total':0x1});const _0x4adf95=splitIntoChunks(_0x442205,_0x430d22,_0x433292),_0x59c62a=_0x4adf95['length'];if(_0x54788a?.[_0x533b7e(0x16c)])throw new Error(_0x533b7e(0x134));_0x507397(_0x533b7e(0x133)+_0x3bf83a+_0x533b7e(0x17f)+_0x59c62a+'\x20个块。',_0x533b7e(0x17c));if(_0x59c62a===0x0)return{'success':!![],'count':0x0};const _0x12bf80=settings[_0x533b7e(0x121)]['batchSize']||0x5;let _0x2bc7fe=_0x5567d8;for(let _0x514cdd=_0x5567d8;_0x514cdd<_0x59c62a;_0x514cdd+=_0x12bf80){if(_0x54788a?.['aborted'])throw new Error(_0x533b7e(0x134));const _0x380cf5=_0x4adf95[_0x533b7e(0x13c)](_0x514cdd,_0x514cdd+_0x12bf80);_0x3e92ca({'message':_0x533b7e(0x13f)+(_0x514cdd+0x1)+'-'+(_0x514cdd+_0x380cf5[_0x533b7e(0x12f)])+'\x20块','processed':_0x514cdd,'total':_0x59c62a});const _0x1d094d=_0x380cf5[_0x533b7e(0xf9)](_0x2c7558=>_0x2c7558[_0x533b7e(0xfe)]),_0x2fb620=await getEmbeddings(_0x1d094d,_0x54788a);if(_0x54788a?.[_0x533b7e(0x16c)])throw new Error(_0x533b7e(0x134));if(_0x380cf5[_0x533b7e(0x12f)]!==_0x2fb620[_0x533b7e(0x12f)])throw new Error(_0x533b7e(0x13e));const _0x411746=_0x380cf5[_0x533b7e(0xf9)]((_0x390b11,_0xa88b8e)=>({..._0x390b11,'vector':_0x2fb620[_0xa88b8e]}));await insertVectors(_0x411746,_0x54788a,_0x3504d1),_0x2bc7fe+=_0x380cf5['length'],_0x186322&&_0x42de43[_0x533b7e(0x13a)](_0x186322,_0x2bc7fe,_0x59c62a),_0x1ab400();}return _0x186322&&_0x42de43[_0x533b7e(0x17d)](_0x186322),_0x507397(_0x533b7e(0x129)+_0x2bc7fe+_0x533b7e(0xb2),'success'),{'success':!![],'count':_0x2bc7fe};}catch(_0x3589d3){if(_0x3589d3['name']===_0x533b7e(0x134)){_0x507397(_0x533b7e(0x14c),_0x533b7e(0xe7));throw _0x3589d3;}return console[_0x533b7e(0x174)](_0x533b7e(0xaf),_0x3589d3),_0x507397(_0x533b7e(0x10b)+_0x3589d3[_0x533b7e(0xf6)],_0x533b7e(0x174)),{'success':![],'error':_0x3589d3[_0x533b7e(0xf6)]};}}function getSettings(){const _0x21e094=_0x28ef4d;if(!context||!context['extensionSettings'])return structuredClone(_0x6967c0);let _0x5e5afd=context[_0x21e094(0x113)][MODULE_NAME];!_0x5e5afd&&(_0x5e5afd={},context[_0x21e094(0x113)][MODULE_NAME]=_0x5e5afd);_0x5e5afd['condensationHistory']===undefined&&(_0x5e5afd[_0x21e094(0xd7)]={});_0x5e5afd[_0x21e094(0xe4)]===undefined&&(_0x5e5afd['knowledgeBases']={});for(const _0x4eaaed in _0x6967c0){if(_0x5e5afd[_0x4eaaed]===undefined)_0x5e5afd[_0x4eaaed]=structuredClone(_0x6967c0[_0x4eaaed]);else{if(typeof _0x6967c0[_0x4eaaed]===_0x21e094(0x158)&&!Array[_0x21e094(0x137)](_0x6967c0[_0x4eaaed])&&_0x6967c0[_0x4eaaed]!==null)for(const _0x2dd8ed in _0x6967c0[_0x4eaaed]){_0x5e5afd[_0x4eaaed][_0x2dd8ed]===undefined&&(_0x5e5afd[_0x4eaaed][_0x2dd8ed]=_0x6967c0[_0x4eaaed][_0x2dd8ed]);}}}return _0x5e5afd;}function saveSettings(){const _0x470606=_0x28ef4d;if(context)context[_0x470606(0xc4)]();}function resetSettings(){const _0x4110bc=_0x28ef4d;context&&(context[_0x4110bc(0x113)][MODULE_NAME]=structuredClone(_0x6967c0),saveSettings());}function showNotification(_0x38cb46,_0x5690e7=_0x28ef4d(0x17c)){toastr[_0x5690e7](_0x38cb46);}function getTagForSource(_0xd9e58a){const _0x95fc6b=_0x28ef4d;switch(_0xd9e58a){case _0x95fc6b(0x126):return _0x95fc6b(0x13b);case _0x95fc6b(0x166):return _0x95fc6b(0xcd);case'manual':return _0x95fc6b(0xf3);case _0x95fc6b(0xc0):return _0x95fc6b(0x15f);default:return'资料';}}function splitIntoChunks(_0x3147ff,_0x207001,_0x21e57b={}){const _0x54ae53=_0x28ef4d;switch(_0x207001){case _0x54ae53(0xc0):return _chunkForNovel(_0x3147ff,_0x21e57b);case _0x54ae53(0x126):return _chunkForChatHistory(_0x3147ff,_0x21e57b);case _0x54ae53(0x166):return _chunkForLorebook(_0x3147ff,_0x21e57b);case'manual':return _chunkForManual(_0x3147ff,_0x21e57b);default:console[_0x54ae53(0xe7)]('[翰林院-分块]\x20未知的来源类型\x20\x27'+_0x207001+_0x54ae53(0x131));return _chunkForManual(_0x3147ff,{..._0x21e57b,'sourceName':_0x21e57b['sourceName']||_0x54ae53(0x100)});}}function _chunkForNovel(_0x2e8bc9,_0xdddf2d){const _0x523ded=_0x28ef4d,{chunkSize:_0x57c716,overlap:_0x26f794}=settings[_0x523ded(0x147)],{sourceName:sourceName='小说'}=_0xdddf2d,_0x1bc3b8=[];if(!_0x2e8bc9||_0x57c716<=0x0)return _0x1bc3b8;const _0xe30239=/(第\s*[一二三四五六七八九十百千万零\d]+\s*卷)/gim,_0x253ba5=/(第\s*[一二三四五六七八九十百千万零\d]+\s*[章回节部])|^(Chapter\s+\d+)/gim;let _0x3900d4=0x0;const _0x1d3a54=_0x2e8bc9['split']('\x0a');let _0x5bcfec=_0x523ded(0x152),_0x109b0e=_0x523ded(0x10a),_0x4624eb=[];function _0x54c236(){const _0x54da4a=_0x523ded;if(_0x4624eb[_0x54da4a(0x12f)]===0x0)return;const _0x553a33=_0x4624eb[_0x54da4a(0xfd)]('\x0a');let _0x4ca58e=0x0,_0x5134a9=0x1;while(_0x4ca58e<_0x553a33['length']){const _0x51fe08=Math[_0x54da4a(0x176)](_0x4ca58e+_0x57c716,_0x553a33[_0x54da4a(0x12f)]),_0x4d8731=_0x553a33[_0x54da4a(0x122)](_0x4ca58e,_0x51fe08);if(_0x4d8731[_0x54da4a(0xdc)]()[_0x54da4a(0x12f)]>0x0){const _0x9e5c21={'source':_0x54da4a(0xc0),'sourceName':sourceName,'timestamp':new Date()[_0x54da4a(0x15d)](),'globalIndex':_0x3900d4++,'volume':_0x5bcfec,'chapter':_0x109b0e,'section':_0x5134a9},_0x14ccf9=getTagForSource(_0x54da4a(0xc0)),_0x10de12=_0x54da4a(0x161)+sourceName+',\x20'+_0x5bcfec+',\x20'+_0x109b0e+',\x20第'+_0x5134a9+'节]',_0x2b7384='<'+_0x14ccf9+'>\x0a'+_0x10de12+'\x0a'+_0x4d8731+'\x0a';_0x1bc3b8[_0x54da4a(0xb4)]({'text':_0x2b7384,'metadata':_0x9e5c21}),_0x5134a9++;}_0x4ca58e+=_0x57c716-_0x26f794;if(_0x4ca58e>=_0x553a33['length'])break;}_0x4624eb=[];}for(const _0x22ffaf of _0x1d3a54){const _0x380024=_0x22ffaf[_0x523ded(0xdc)]();if(_0xe30239[_0x523ded(0x153)](_0x380024))_0x54c236(),_0x5bcfec=_0x380024,_0x109b0e=_0x523ded(0x10a);else _0x253ba5[_0x523ded(0x153)](_0x380024)?(_0x54c236(),_0x109b0e=_0x380024):_0x4624eb[_0x523ded(0xb4)](_0x22ffaf);}_0x54c236();if(_0x1bc3b8[_0x523ded(0x12f)]===0x0&&_0x2e8bc9[_0x523ded(0x12f)]>0x0){let _0x14c62d=0x0,_0x3f3270=0x1;while(_0x14c62d<_0x2e8bc9[_0x523ded(0x12f)]){const _0x65768d=Math[_0x523ded(0x176)](_0x14c62d+_0x57c716,_0x2e8bc9['length']),_0x17069f=_0x2e8bc9[_0x523ded(0x122)](_0x14c62d,_0x65768d),_0x58531a={'source':_0x523ded(0xc0),'sourceName':sourceName,'timestamp':new Date()[_0x523ded(0x15d)](),'globalIndex':_0x1bc3b8[_0x523ded(0x12f)],'volume':'第1卷','chapter':_0x523ded(0x10a),'section':_0x3f3270},_0xed89a5=getTagForSource('novel'),_0x2a5925=_0x523ded(0x161)+sourceName+',\x20第1卷,\x20第1章,\x20第'+_0x3f3270+'节]',_0x58f5df='<'+_0xed89a5+'>\x0a'+_0x2a5925+'\x0a'+_0x17069f+_0x523ded(0xbd)+_0xed89a5+'>';_0x1bc3b8['push']({'text':_0x58f5df,'metadata':_0x58531a}),_0x3f3270++,_0x14c62d+=_0x57c716-_0x26f794;}}return _0x1bc3b8;}function _chunkForChatHistory(_0xb255ec,_0x33fef0){const _0x1e7bfe=_0x28ef4d,{chunkSize:_0x5714ac,overlap:_0x5a8970}=settings[_0x1e7bfe(0x147)],{floor:_0x1fa803,is_user:_0x8d830,timestamp:_0x56781d}=_0x33fef0,_0x577e6b=[];if(!_0xb255ec||_0x5714ac<=0x0)return _0x577e6b;let _0x5e0a3d=0x1,_0x11d3af=0x0;while(_0x11d3af<_0xb255ec['length']){const _0x4b2085=Math[_0x1e7bfe(0x176)](_0x11d3af+_0x5714ac,_0xb255ec[_0x1e7bfe(0x12f)]),_0x1ea905=_0xb255ec[_0x1e7bfe(0x122)](_0x11d3af,_0x4b2085),_0x4d4baa=_0x1e7bfe(0x173)+_0x1fa803+_0x1e7bfe(0x12e)+_0x5e0a3d+_0x1e7bfe(0xe3),_0x2c4729=getTagForSource(_0x1e7bfe(0x126)),_0x288d02='<'+_0x2c4729+'>\x0a'+_0x4d4baa+'\x0a'+_0x1ea905+_0x1e7bfe(0xbd)+_0x2c4729+'>';_0x577e6b[_0x1e7bfe(0xb4)]({'text':_0x288d02,'metadata':{'source':'chat_history','sourceName':_0x1e7bfe(0xc3)+_0x1fa803,'floor':_0x1fa803,'part':_0x5e0a3d,'is_user':_0x8d830,'timestamp':_0x56781d}}),_0x5e0a3d++,_0x11d3af+=_0x5714ac-_0x5a8970;if(_0x11d3af>=_0xb255ec[_0x1e7bfe(0x12f)])break;}return _0x577e6b;}function _chunkForLorebook(_0x192597,_0xf21e6b){const _0x563481=_0x28ef4d,{chunkSize:_0x477fa4,overlap:_0x459247}=settings['advanced'],{sourceName:sourceName=_0x563481(0xa6)}=_0xf21e6b,_0x425d7d=[];if(!_0x192597||_0x477fa4<=0x0)return _0x425d7d;let _0x355343=0x1,_0x4a025e=0x0;while(_0x4a025e<_0x192597['length']){const _0x3532bd=Math[_0x563481(0x176)](_0x4a025e+_0x477fa4,_0x192597[_0x563481(0x12f)]),_0x4aabc2=_0x192597[_0x563481(0x122)](_0x4a025e,_0x3532bd),_0x4cb61b=_0x563481(0x164)+sourceName+',\x20第'+_0x355343+_0x563481(0xe3),_0x16b9eb=getTagForSource(_0x563481(0x166)),_0x590239='<'+_0x16b9eb+'>\x0a'+_0x4cb61b+'\x0a'+_0x4aabc2+'\x0a';_0x425d7d['push']({'text':_0x590239,'metadata':{'source':_0x563481(0x166),'sourceName':sourceName,'part':_0x355343,'timestamp':new Date()[_0x563481(0x15d)]()}}),_0x355343++,_0x4a025e+=_0x477fa4-_0x459247;if(_0x4a025e>=_0x192597[_0x563481(0x12f)])break;}return _0x425d7d;}function _chunkForManual(_0x3487d2,_0x25ff7d){const _0x3fca79=_0x28ef4d,{chunkSize:_0x1e2de9,overlap:_0x446d85}=settings[_0x3fca79(0x147)],{sourceName:sourceName=_0x3fca79(0xf3)}=_0x25ff7d,_0x3b17b4=[];if(!_0x3487d2||_0x1e2de9<=0x0)return _0x3b17b4;const _0x36c913=new Date(),_0x1bedfb=_0x36c913[_0x3fca79(0x10c)](_0x3fca79(0x128));let _0x1c177d=0x1,_0x59e137=0x0;while(_0x59e137<_0x3487d2['length']){const _0x4132e6=Math['min'](_0x59e137+_0x1e2de9,_0x3487d2[_0x3fca79(0x12f)]),_0x304081=_0x3487d2['substring'](_0x59e137,_0x4132e6),_0x5f5d6d=_0x3fca79(0x161)+sourceName+_0x3fca79(0x119)+_0x1bedfb+_0x3fca79(0x12e)+_0x1c177d+_0x3fca79(0xe3),_0x1e6537=getTagForSource(_0x3fca79(0x108)),_0x37daf3='<'+_0x1e6537+'>\x0a'+_0x5f5d6d+'\x0a'+_0x304081+_0x3fca79(0xbd)+_0x1e6537+'>';_0x3b17b4[_0x3fca79(0xb4)]({'text':_0x37daf3,'metadata':{'source':_0x3fca79(0x108),'sourceName':sourceName,'part':_0x1c177d,'timestamp':_0x36c913['toISOString']()}}),_0x1c177d++,_0x59e137+=_0x1e2de9-_0x446d85;if(_0x59e137>=_0x3487d2[_0x3fca79(0x12f)])break;}return _0x3b17b4;}import{getCollectionId as _0x2e9745,getCharacterName}from'./utils/context-utils.js';async function getCollectionId(){return lockedCollectionId||await _0x2e9745();}async function toggleSessionLock(){return lockedCollectionId?(lockedCollectionId=null,![]):(lockedCollectionId=await _0x2e9745(),!![]);}function isSessionLocked(){return lockedCollectionId!==null;}function getLockedSessionInfo(){const _0x15917a=_0x28ef4d;if(!lockedCollectionId)return null;return{'id':lockedCollectionId,'name':_0x15917a(0xe8)+lockedCollectionId[_0x15917a(0x122)](0x0,0x8)+'...)'};}function getKnowledgeBases(){const _0x29e78e=_0x28ef4d,_0x4f0c9f=getCharacterStableId();return!settings[_0x29e78e(0xe4)][_0x4f0c9f]&&(settings['knowledgeBases'][_0x4f0c9f]={}),settings[_0x29e78e(0xe4)][_0x4f0c9f];}function addKnowledgeBase(_0x404315){const _0xf7b8d7=_0x28ef4d;if(!_0x404315||!_0x404315['trim']())throw new Error(_0xf7b8d7(0xb5));const _0x4e6c09=getCharacterStableId(),_0x4e874b=getKnowledgeBases(),_0x468325=_0xf7b8d7(0x9e)+Date[_0xf7b8d7(0xa8)]()+'_'+Math[_0xf7b8d7(0xe2)]()[_0xf7b8d7(0xbf)](0x24)[_0xf7b8d7(0x122)](0x2,0x9),_0x28d21a={'id':_0x468325,'name':_0x404315[_0xf7b8d7(0xdc)](),'enabled':!![],'createdAt':new Date()['toISOString']()};return _0x4e874b[_0x468325]=_0x28d21a,saveSettings(),console[_0xf7b8d7(0x136)](_0xf7b8d7(0xd5)+_0x4e6c09+_0xf7b8d7(0xa5)+_0x404315+'\x20(ID:\x20'+_0x468325+')'),_0x28d21a;}async function removeKnowledgeBase(_0x45a9fb){const _0x4f072b=_0x28ef4d,_0x3f0186=getCharacterStableId(),_0x2652e6=getKnowledgeBases(),_0x585abd=_0x2652e6[_0x45a9fb]?.[_0x4f072b(0x118)]||_0x45a9fb;if(!_0x2652e6[_0x45a9fb]){console[_0x4f072b(0xe7)](_0x4f072b(0xb7)+_0x45a9fb);return;}const _0x1d3c22=_0x3f0186+'_'+_0x45a9fb;console[_0x4f072b(0x136)](_0x4f072b(0xee)+_0x45a9fb+_0x4f072b(0xde)+_0x1d3c22);const _0x30cd29=await purgeStorage(_0x1d3c22);_0x30cd29?(delete _0x2652e6[_0x45a9fb],saveSettings(),console[_0x4f072b(0x136)](_0x4f072b(0x9d)+_0x45a9fb+_0x4f072b(0xc7)),toastr['success'](_0x4f072b(0xf1)+_0x585abd+'\x22\x20已删除。')):(console[_0x4f072b(0x174)](_0x4f072b(0x138)+_0x1d3c22+_0x4f072b(0x177)),toastr['error']('删除知识库失败,未能清空后端数据。'));}function toggleKnowledgeBase(_0x5b500c){const _0x52cb4c=_0x28ef4d,_0x2b3597=getKnowledgeBases();_0x2b3597[_0x5b500c]&&(_0x2b3597[_0x5b500c][_0x52cb4c(0xd2)]=!_0x2b3597[_0x5b500c][_0x52cb4c(0xd2)],saveSettings(),console[_0x52cb4c(0x136)]('[翰林院-核心]\x20知识库\x20'+_0x5b500c+_0x52cb4c(0x135)+(_0x2b3597[_0x5b500c][_0x52cb4c(0xd2)]?'启用':'禁用')));}function generateHash(_0x358dac){const _0x5352c6=_0x28ef4d;let _0x2bb178=0x0;for(let _0x4ba7a1=0x0;_0x4ba7a1<_0x358dac['length'];_0x4ba7a1++){const _0x4f8e12=_0x358dac[_0x5352c6(0x10d)](_0x4ba7a1);_0x2bb178=(_0x2bb178<<0x5)-_0x2bb178+_0x4f8e12,_0x2bb178=_0x2bb178&_0x2bb178;}return Math['abs'](_0x2bb178)[_0x5352c6(0xbf)](0x24);}async function queryVectors(_0x23c78c){const _0x70320a=_0x28ef4d;console['log']('[翰林院-日志]\x20开始多知识库向量查询...');const _0x2a47ee=getCharacterStableId(),_0x2a33c6=getKnowledgeBases(),_0x3342db=Object[_0x70320a(0x16f)](_0x2a33c6)['filter'](_0x37e950=>_0x37e950['enabled']);if(_0x3342db[_0x70320a(0x12f)]===0x0){console[_0x70320a(0x136)]('[翰林院-日志]\x20没有启用的新知识库,尝试查询旧版单体宝库...');const _0x1c03d6=await _0x2e9745();if(!_0x1c03d6)return[];_0x3342db[_0x70320a(0xb4)]({'id':null,'name':'旧版宝库\x20(Legacy)'});}const _0xf584e4=(await getEmbeddings([_0x23c78c]))[0x0];let _0x4fad9f=[];const _0x490ce1=_0x3342db[_0x70320a(0xf9)](_0x1f592f=>{const _0x34b89f=_0x70320a,_0x47d86c=_0x1f592f['id']===null?_0x2e9745():Promise['resolve'](_0x2a47ee+'_'+_0x1f592f['id']);return _0x47d86c[_0x34b89f(0xe1)](_0x59c08e=>{const _0x3c93b9=_0x34b89f;if(!_0x59c08e)return[];console[_0x3c93b9(0x136)]('[翰林院-日志]\x20正在查询知识库:\x20'+_0x1f592f[_0x3c93b9(0x118)]+_0x3c93b9(0x140)+_0x59c08e+')');const _0x20df3a={'collectionId':_0x59c08e,'searchText':_0x23c78c,'topK':settings[_0x3c93b9(0x147)][_0x3c93b9(0x11d)],'threshold':settings['advanced'][_0x3c93b9(0x171)],'source':_0x3c93b9(0xb8),'embeddings':{[_0x23c78c]:_0xf584e4}};return fetch(_0x3c93b9(0x139),{'method':'POST','headers':context[_0x3c93b9(0x145)](),'body':JSON[_0x3c93b9(0x13d)](_0x20df3a)})['then'](async _0x546811=>{const _0x258e15=_0x3c93b9;if(!_0x546811['ok']){const _0x5139a5=await _0x546811[_0x258e15(0xfe)]();return console[_0x258e15(0x174)]('[翰林院-日志]\x20查询知识库\x20'+_0x59c08e+_0x258e15(0xa0),_0x5139a5),[];}const _0x3c30cb=await _0x546811[_0x258e15(0x120)](),_0x127d4f=_0x3c30cb[_0x258e15(0xfa)]||_0x3c30cb['results']||_0x3c30cb[_0x258e15(0xfb)]||[];return console[_0x258e15(0x136)]('[翰林院-日志]\x20知识库\x20'+_0x1f592f[_0x258e15(0x118)]+_0x258e15(0x16d)+_0x127d4f['length']+'\x20条结果。'),_0x127d4f;})[_0x3c93b9(0xac)](_0x1eb4ec=>{const _0x5c75c3=_0x3c93b9;return console['error'](_0x5c75c3(0x123)+_0x59c08e+_0x5c75c3(0xda),_0x1eb4ec),[];});});}),_0x3f1ad=await Promise[_0x70320a(0x178)](_0x490ce1);_0x4fad9f=_0x3f1ad[_0x70320a(0x144)](),console[_0x70320a(0x136)](_0x70320a(0xbb)+_0x4fad9f[_0x70320a(0x12f)]+_0x70320a(0x175));const _0x477daf=[],_0x3b5e8b=new Set();for(const _0x30507e of _0x4fad9f){_0x30507e&&_0x30507e[_0x70320a(0xfe)]&&!_0x3b5e8b[_0x70320a(0xbe)](_0x30507e['text'])&&(_0x3b5e8b['add'](_0x30507e['text']),_0x477daf['push'](_0x30507e));}return console[_0x70320a(0x136)](_0x70320a(0x112)+_0x477daf['length']+'\x20条结果。'),_0x477daf[_0x70320a(0x169)]((_0x3ef0ee,_0x24727e)=>(_0x24727e[_0x70320a(0x110)]||0x0)-(_0x3ef0ee[_0x70320a(0x110)]||0x0)),_0x477daf;}async function insertVectors(_0x3604d8,_0x435070=null,_0x21e8fc){const _0x470761=_0x28ef4d;if(!_0x21e8fc)throw new Error(_0x470761(0xd3));if(_0x3604d8['length']===0x0)return{'success':!![],'count':0x0};const _0x2f29a9=_0x3604d8[_0x470761(0xf9)]((_0x74299,_0x412418)=>({'hash':generateHash(_0x74299['text']+Date[_0x470761(0xa8)]()+_0x412418),'text':_0x74299[_0x470761(0xfe)],'metadata':_0x74299[_0x470761(0xfa)]||{'source':_0x470761(0x103),'timestamp':new Date()['toISOString']()}})),_0x4f24fa=_0x2f29a9[_0x470761(0x17a)]((_0xb78f40,_0x50e973,_0x58097e)=>{const _0x163372=_0x470761;return _0xb78f40[_0x50e973[_0x163372(0xfe)]]=_0x3604d8[_0x58097e][_0x163372(0xf5)],_0xb78f40;},{}),_0x34380b={'collectionId':_0x21e8fc,'items':_0x2f29a9,'source':'webllm','embeddings':_0x4f24fa},_0x260d1c=await fetch('/api/vector/insert',{'method':_0x470761(0x124),'headers':context[_0x470761(0x145)](),'body':JSON['stringify'](_0x34380b),'signal':_0x435070});if(!_0x260d1c['ok']){const _0x15d4ab=await _0x260d1c[_0x470761(0xfe)]();console['error'](_0x470761(0x12b),_0x15d4ab);throw new Error(_0x470761(0xf7)+_0x260d1c[_0x470761(0x16a)]+':\x20'+_0x15d4ab);}return{'success':!![],'count':_0x2f29a9['length']};}async function getVectorCount(_0x22fc15=null){const _0x190552=_0x28ef4d,_0x1383b6=getCharacterStableId();if(_0x22fc15){const _0x4a462c=_0x1383b6+'_'+_0x22fc15;return await countVectorsInCollection(_0x4a462c);}else{console[_0x190552(0x136)](_0x190552(0x15b));const _0x4d5db0=getKnowledgeBases(),_0x515e0c=Object[_0x190552(0x16f)](_0x4d5db0),_0x592879=_0x515e0c[_0x190552(0xf9)](_0x2b8859=>{const _0x5d1507=_0x1383b6+'_'+_0x2b8859['id'];return countVectorsInCollection(_0x5d1507);}),_0x194292=await _0x2e9745();_0x592879[_0x190552(0xb4)](countVectorsInCollection(_0x194292));const _0x5d8df8=await Promise[_0x190552(0x178)](_0x592879),_0x378f2a=_0x5d8df8[_0x190552(0x17a)]((_0x3889d5,_0x22f3cd)=>_0x3889d5+_0x22f3cd,0x0);return console[_0x190552(0x136)](_0x190552(0x104)+_0x378f2a),_0x378f2a;}}async function countVectorsInCollection(_0x4a4f43){const _0x46b0f6=_0x28ef4d;if(!_0x4a4f43)return 0x0;console[_0x46b0f6(0x136)]('[翰林院-日志]\x20统计目标集合ID:\x20'+_0x4a4f43);const _0x922444={'collectionId':_0x4a4f43,'source':'webllm','embeddings':{}};try{const _0x3710ab=await fetch(_0x46b0f6(0xc6),{'method':_0x46b0f6(0x124),'headers':context['getRequestHeaders'](),'body':JSON[_0x46b0f6(0x13d)](_0x922444)});if(!_0x3710ab['ok']){if(_0x3710ab[_0x46b0f6(0x16a)]===0x194)console[_0x46b0f6(0x136)](_0x46b0f6(0x154)+_0x4a4f43+_0x46b0f6(0xbc));else{const _0x4d20fb=await _0x3710ab[_0x46b0f6(0xfe)]();console[_0x46b0f6(0xe7)](_0x46b0f6(0x15c)+_0x4a4f43+_0x46b0f6(0x141)+_0x3710ab[_0x46b0f6(0x16a)]+'):',_0x4d20fb);}return 0x0;}const _0x234ded=await _0x3710ab[_0x46b0f6(0x120)]();let _0x221877=0x0;if(Array[_0x46b0f6(0x137)](_0x234ded))_0x221877=_0x234ded[_0x46b0f6(0x12f)];else _0x234ded&&_0x234ded[_0x46b0f6(0xab)]&&(_0x221877=_0x234ded[_0x46b0f6(0xab)][_0x46b0f6(0x12f)]);return _0x221877;}catch(_0x20ede5){return console[_0x46b0f6(0x174)]('[翰林院-日志]\x20统计集合\x20'+_0x4a4f43+_0x46b0f6(0xda),_0x20ede5),0x0;}}async function purgeStorage(_0x5798aa=null){const _0x117eb2=_0x28ef4d;console[_0x117eb2(0x136)](_0x117eb2(0x156));const _0x32c207=_0x5798aa||await getCollectionId();if(!_0x32c207)return console['error'](_0x117eb2(0x157)),toastr[_0x117eb2(0x174)](_0x117eb2(0x155)),![];console[_0x117eb2(0x136)](_0x117eb2(0xd0)+_0x32c207);const _0x2fdb46={'collectionId':_0x32c207};console[_0x117eb2(0x136)]('[翰林院-日志]\x20发送到\x20/api/vector/purge\x20的请求体:',JSON['stringify'](_0x2fdb46,null,0x2));const _0xc68b44=await fetch(_0x117eb2(0x14b),{'method':_0x117eb2(0x124),'headers':context['getRequestHeaders'](),'body':JSON[_0x117eb2(0x13d)](_0x2fdb46)});console['log']('[翰林院-日志]\x20/api/vector/purge\x20响应状态:\x20'+_0xc68b44[_0x117eb2(0x16a)]);if(!_0xc68b44['ok']){const _0x20a507=await _0xc68b44[_0x117eb2(0xfe)]();console[_0x117eb2(0x174)](_0x117eb2(0xb1),_0x20a507);}else console['log'](_0x117eb2(0x102));return _0xc68b44['ok'];}function getMessagesForCondensation(_0x5727b2=null){const _0x144ea8=_0x28ef4d;if(!settings[_0x144ea8(0x149)][_0x144ea8(0xd2)])return showNotification(_0x144ea8(0xe9),_0x144ea8(0x116)),[];const {layerStart:_0x1cc466,layerEnd:_0x21d8b3}=settings[_0x144ea8(0x149)],_0x420864=_0x5727b2||settings['condensation'][_0x144ea8(0x111)],_0x54082d=context['chat'][_0x144ea8(0x12f)],_0x4318fe=Math[_0x144ea8(0x170)](0x0,_0x1cc466-0x1),_0x402cbb=_0x21d8b3===0x0||_0x21d8b3>_0x54082d?_0x54082d:Math[_0x144ea8(0x176)](_0x54082d,_0x21d8b3),_0x13c652=context[_0x144ea8(0xfc)][_0x144ea8(0x13c)](_0x4318fe,_0x402cbb);return _0x13c652[_0x144ea8(0xdb)](_0xebd84e=>{const _0x261c98=_0x144ea8,_0x5d7431=_0xebd84e[_0x261c98(0x16b)]===!![],_0x215fa0=_0xebd84e[_0x261c98(0x16b)]===![];if(!_0xebd84e['mes']||!_0xebd84e[_0x261c98(0x10e)]['trim']())return![];return _0x420864[_0x261c98(0x101)]&&_0x5d7431||_0x420864['ai']&&_0x215fa0;});}function _0x51ca(_0xc67db3,_0x2b0b23){const _0x289c2a=_0x289c();return _0x51ca=function(_0x51caaa,_0x43c92d){_0x51caaa=_0x51caaa-0x9d;let _0x1847f0=_0x289c2a[_0x51caaa];return _0x1847f0;},_0x51ca(_0xc67db3,_0x2b0b23);}async function processCondensation(_0x24bcb6,_0x425ebf=()=>{},_0x56ea1d=null){const _0x4cc69a=_0x28ef4d;if(!_0x24bcb6||_0x24bcb6[_0x4cc69a(0x12f)]===0x0)return{'success':![],'error':'No\x20messages\x20to\x20process.'};try{let _0x565b53,_0x3b0c3c;const _0x3aa936=getCharacterName()||_0x4cc69a(0xd9);if(_0x56ea1d){const _0x101ace=_0x56ea1d['start']??'?',_0x5c46ee=_0x56ea1d[_0x4cc69a(0xc8)]===0x0?'末':_0x56ea1d[_0x4cc69a(0xc8)]??'?';_0x565b53=_0x3aa936+':\x20'+_0x101ace+'楼-'+_0x5c46ee+'楼';}else{const _0x1c77dd=new Date()['toLocaleString'](_0x4cc69a(0x128),{'hour12':![]});_0x565b53=_0x4cc69a(0x105)+_0x1c77dd;}const _0xe6b1e8=Object[_0x4cc69a(0x16f)](getKnowledgeBases()),_0x5dee9f=_0xe6b1e8[_0x4cc69a(0xd1)](_0x20044f=>_0x20044f[_0x4cc69a(0x118)]===_0x565b53);if(_0x5dee9f)_0x3b0c3c=_0x5dee9f['id'],_0x425ebf(_0x4cc69a(0xcb)+_0x565b53+_0x4cc69a(0xff),_0x4cc69a(0x17c));else{_0x425ebf(_0x4cc69a(0x168)+_0x565b53+_0x4cc69a(0x12d),'info');const _0x34d9b9=addKnowledgeBase(_0x565b53);_0x3b0c3c=_0x34d9b9['id'];}const _0x498507=getCharacterStableId(),_0x15a4a7=_0x498507+'_'+_0x3b0c3c;_0x425ebf(_0x4cc69a(0x142)+_0x565b53+_0x4cc69a(0xb0)+_0x15a4a7+')','success');const _0x4fd0dd=[],_0x14921c=context[_0x4cc69a(0xfc)];for(const _0x44c2ea of _0x24bcb6){const _0x20371a=(_0x44c2ea[_0x4cc69a(0x10e)]||'')[_0x4cc69a(0x14a)](/<[^>]*>/g,'')[_0x4cc69a(0xdc)]();if(_0x20371a[_0x4cc69a(0x12f)]===0x0)continue;let _0xf5a09d;if(_0x44c2ea['floor']!==undefined&&_0x44c2ea[_0x4cc69a(0x17e)]!==null)_0xf5a09d=_0x44c2ea[_0x4cc69a(0x17e)];else{const _0x28ecf4=_0x14921c[_0x4cc69a(0xd6)](_0xcee2fc=>_0xcee2fc===_0x44c2ea);_0xf5a09d=_0x28ecf4!==-0x1?_0x28ecf4+0x1:-0x1;}const _0x12a829=new Date(_0x44c2ea[_0x4cc69a(0xb3)]),_0x58cee7=isNaN(_0x12a829[_0x4cc69a(0x15e)]())?new Date()[_0x4cc69a(0x15d)]():_0x12a829[_0x4cc69a(0x15d)](),_0x23ee6f=splitIntoChunks(_0x20371a,'chat_history',{'floor':_0xf5a09d,'is_user':_0x44c2ea[_0x4cc69a(0x16b)],'timestamp':_0x58cee7});_0x4fd0dd['push'](..._0x23ee6f);}if(_0x4fd0dd[_0x4cc69a(0x12f)]===0x0)return{'success':!![],'count':0x0};_0x425ebf(_0x4cc69a(0x148)+_0x24bcb6[_0x4cc69a(0x12f)]+_0x4cc69a(0xe6)+_0x4fd0dd[_0x4cc69a(0x12f)]+_0x4cc69a(0xec),_0x4cc69a(0x17c));const _0x161a92=settings[_0x4cc69a(0x121)][_0x4cc69a(0x11c)]||0x5;let _0x72df64=0x0;for(let _0x5d30b2=0x0;_0x5d30b2<_0x4fd0dd[_0x4cc69a(0x12f)];_0x5d30b2+=_0x161a92){const _0x5209b2=_0x4fd0dd[_0x4cc69a(0x13c)](_0x5d30b2,_0x5d30b2+_0x161a92),_0x470c50=_0x5209b2[_0x4cc69a(0xf9)](_0x353b79=>_0x353b79[_0x4cc69a(0xfe)]),_0x286bb7=await getEmbeddings(_0x470c50);if(_0x5209b2[_0x4cc69a(0x12f)]!==_0x286bb7[_0x4cc69a(0x12f)])throw new Error(_0x4cc69a(0x13e));const _0x5f5716=_0x5209b2[_0x4cc69a(0xf9)]((_0x52ffc1,_0x3576c0)=>({..._0x52ffc1,'vector':_0x286bb7[_0x3576c0]}));await insertVectors(_0x5f5716,null,_0x15a4a7),_0x72df64+=_0x5209b2[_0x4cc69a(0x12f)];}if(_0x56ea1d){const _0x1e0acf=_0x56ea1d['end']===0x0?context[_0x4cc69a(0xfc)]['length']:_0x56ea1d['end'];settings[_0x4cc69a(0xd7)][_0x15a4a7]={'start':_0x56ea1d[_0x4cc69a(0xc5)],'end':_0x1e0acf,'timestamp':new Date()[_0x4cc69a(0x15d)]()},saveSettings(),_0x425ebf(_0x4cc69a(0x14f)+_0x15a4a7+_0x4cc69a(0xf8)+_0x56ea1d[_0x4cc69a(0xc5)]+'-'+_0x1e0acf,_0x4cc69a(0x17c));}_0x425ebf(_0x4cc69a(0x16e)+_0x72df64+_0x4cc69a(0xa9),_0x4cc69a(0x11e));const _0x54c833=_0x24bcb6[_0x4cc69a(0xf9)](_0x1121e9=>{const _0x860ea=_0x4cc69a,_0x3dd5d4=_0x14921c['findIndex'](_0x95b7ee=>_0x95b7ee===_0x1121e9),_0x1bbf7c=_0x3dd5d4!==-0x1?_0x3dd5d4+0x1:-0x1,_0xf0e740=_0x1121e9[_0x860ea(0x16b)]?'用户':getCharacterName()||'AI';return'['+_0xf0e740+_0x860ea(0x12c)+_0x1bbf7c+_0x860ea(0x14d);});return{'success':!![],'count':_0x72df64,'messages':_0x54c833};}catch(_0x52788e){return console[_0x4cc69a(0x174)](_0x4cc69a(0xae),_0x52788e),_0x425ebf(_0x4cc69a(0xa7)+_0x52788e[_0x4cc69a(0xf6)],'error'),{'success':![],'error':_0x52788e[_0x4cc69a(0xf6)]};}}async function rerankResults(_0x4fa906,_0x1516e,_0x9333c6){const _0x39a86f=_0x28ef4d;let _0x4148a7=_0x4fa906;if(_0x9333c6[_0x39a86f(0xb9)][_0x39a86f(0xd2)]&&_0x4fa906[_0x39a86f(0x12f)]>0x0){console[_0x39a86f(0x136)](_0x39a86f(0x106));try{const _0x33b067=_0x4fa906[_0x39a86f(0xf9)](_0x461639=>_0x461639[_0x39a86f(0xfe)]),_0x5e8b07=await executeRerank(_0x1516e,_0x33b067,_0x9333c6[_0x39a86f(0xb9)]),_0x5a7f66=_0x4fa906[_0x39a86f(0xf9)]((_0x2502cd,_0x54f92f)=>({..._0x2502cd,'original_index':_0x54f92f}));_0x4148a7=_0x5a7f66[_0x39a86f(0xf9)](_0x553048=>{const _0x178b48=_0x39a86f,_0x4c6b39=_0x5e8b07[_0x178b48(0xe0)][_0x178b48(0xd1)](_0x146f7d=>_0x146f7d[_0x178b48(0xed)]===_0x553048[_0x178b48(0xca)]),_0x168e73=_0x4c6b39?_0x4c6b39[_0x178b48(0xdf)]:0x0;return{..._0x553048,'rerank_score':_0x168e73};});if(_0x9333c6[_0x39a86f(0xb9)][_0x39a86f(0x114)])showNotification('外部Rerank完成',_0x39a86f(0x11e));}catch(_0x55d05f){console[_0x39a86f(0x174)](_0x39a86f(0x159),_0x55d05f);if(_0x9333c6[_0x39a86f(0xb9)][_0x39a86f(0x114)])showNotification('Rerank失败:\x20'+_0x55d05f['message'],_0x39a86f(0x174));_0x4148a7[_0x39a86f(0x132)](_0x1e4d85=>_0x1e4d85['rerank_score']=0x0);}}else _0x4148a7['forEach'](_0x59d69b=>_0x59d69b['rerank_score']=0x0);console['log']('[翰林院-Rerank]\x20开始元数据加权最终排序...');const _0x119337=context[_0x39a86f(0xfc)][_0x39a86f(0x12f)],_0x5de5a7=_0x9333c6[_0x39a86f(0xb9)][_0x39a86f(0xc1)],_0x2aff47=_0x4148a7[_0x39a86f(0xf9)](_0x2fac32=>{const _0x5e42c1=_0x39a86f;let _0x4fa804=0x1;const _0x4f38bb=_0x2fac32[_0x5e42c1(0xfa)]||{};switch(_0x4f38bb[_0x5e42c1(0x127)]){case'lorebook':_0x4fa804*=1.2;break;case _0x5e42c1(0x108):_0x4fa804*=1.1;break;case'chat_history':if(_0x4f38bb[_0x5e42c1(0x17e)]&&_0x119337>0x0){const _0x13c03c=_0x4f38bb[_0x5e42c1(0x17e)]/_0x119337;_0x4fa804*=0x1+_0x13c03c;}break;}const _0x228e1a=_0x2fac32[_0x5e42c1(0xdd)]*_0x5de5a7+(_0x2fac32[_0x5e42c1(0x110)]||0x0)*(0x1-_0x5de5a7),_0x4367b5=_0x228e1a*_0x4fa804;return{..._0x2fac32,'final_score':_0x4367b5};});return _0x2aff47[_0x39a86f(0x169)]((_0x15f084,_0x554aac)=>(_0x554aac['final_score']||0x0)-(_0x15f084[_0x39a86f(0xd4)]||0x0)),console[_0x39a86f(0x136)](_0x39a86f(0xc2)),_0x2aff47[_0x39a86f(0x13c)](0x0,_0x9333c6[_0x39a86f(0xb9)][_0x39a86f(0xd8)]);}async function rearrangeChat(_0x716269,_0x294f05,_0x1a8de4,_0x550c33){const _0x1efbbb=_0x28ef4d;setExtensionPrompt(_0x1efbbb(0x10f),'',settings['injection'][_0x1efbbb(0x150)],settings[_0x1efbbb(0xeb)][_0x1efbbb(0xa4)],![],settings['injection'][_0x1efbbb(0xaa)]);if(_0x550c33==='quiet'||!settings[_0x1efbbb(0x121)]['enabled'])return;const _0x31e17d=_0x716269['slice'](-settings['advanced'][_0x1efbbb(0xc9)]);if(_0x31e17d['length']===0x0)return;const _0x466f90=_0x31e17d[_0x1efbbb(0xf9)](_0x48d475=>_0x48d475[_0x1efbbb(0x10e)])[_0x1efbbb(0xfd)]('\x20')['replace'](/<[^>]*>/g,'')[_0x1efbbb(0xdc)]();if(!_0x466f90)return;try{const _0x31233b=await queryVectors(_0x466f90);if(_0x31233b[_0x1efbbb(0x12f)]===0x0)return;const _0x5182f2=await rerankResults(_0x31233b,_0x466f90,settings);if(_0x5182f2['length']===0x0)return;const _0x1c9e09=_0x5182f2[_0x1efbbb(0xf9)](_0x4da507=>_0x4da507['text'])[_0x1efbbb(0xfd)]('\x0a\x0a');let _0x10fa26=settings[_0x1efbbb(0xeb)]['template'][_0x1efbbb(0x14a)](_0x1efbbb(0xa1),_0x1c9e09);_0x10fa26['trim']()&&(_0x10fa26=_0x1efbbb(0xa2)+_0x10fa26),setExtensionPrompt(_0x1efbbb(0x10f),_0x10fa26,settings[_0x1efbbb(0xeb)][_0x1efbbb(0x150)],settings['injection']['depth'],![],settings[_0x1efbbb(0xeb)][_0x1efbbb(0xaa)]);}catch(_0x3756c9){console[_0x1efbbb(0x174)]('[翰林院]\x20检索或注入时发生错误:',_0x3756c9);if(settings['retrieval'][_0x1efbbb(0x114)])showNotification(_0x1efbbb(0xcc)+_0x3756c9[_0x1efbbb(0xf6)],_0x1efbbb(0x174));}}