From a2fec897645862f522400ec01041e2d85aa251b0 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Wed, 3 Sep 2025 12:50:10 +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 9d5bf15..ab0ec2f 100644 --- a/core/rag-processor.js +++ b/core/rag-processor.js @@ -1 +1 @@ -'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));}} +'use strict';const _0x177034=_0x1ae4;(function(_0x4827f8,_0x21b5b0){const _0x33fa21=_0x1ae4,_0x2f5c05=_0x4827f8();while(!![]){try{const _0x54da21=parseInt(_0x33fa21(0xdc))/0x1+-parseInt(_0x33fa21(0x15d))/0x2*(parseInt(_0x33fa21(0x12b))/0x3)+-parseInt(_0x33fa21(0xcf))/0x4+parseInt(_0x33fa21(0xdb))/0x5*(-parseInt(_0x33fa21(0x145))/0x6)+-parseInt(_0x33fa21(0x177))/0x7+parseInt(_0x33fa21(0xd7))/0x8*(parseInt(_0x33fa21(0x122))/0x9)+parseInt(_0x33fa21(0x144))/0xa;if(_0x54da21===_0x21b5b0)break;else _0x2f5c05['push'](_0x2f5c05['shift']());}catch(_0x482c17){_0x2f5c05['push'](_0x2f5c05['shift']());}}}(_0x4888,0x9e406));import{extension_prompt_roles,setExtensionPrompt}from'/script.js';import*as _0x231504 from'./utils/context-utils.js';import{getCollectionIdInfo,getCharacterId,getCharacterStableId}from'./utils/context-utils.js';import{defaultSettings as _0x2ac380}from'./rag-settings.js';import*as _0x1aa8ce from'./ingestion-manager.js';import{getEmbeddings,fetchEmbeddingModels as _0x73f638,fetchRerankModels as _0x1976e4,executeRerank,testApiConnection as _0x4b51a3}from'./rag-api.js';const MODULE_NAME=_0x177034(0xea),OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME='vectors_rearrangeChat';let context=null,settings=null,lockedCollectionId=null;export{initialize,getSettings,saveSettings,resetSettings,_0x4b51a3 as testApiConnection,_0x73f638 as fetchEmbeddingModels,_0x1976e4 as fetchRerankModels,getVectorCount,purgeStorage,getMessagesForCondensation,processCondensation,ingestTextToHanlinyuan,getCollectionId,toggleSessionLock,isSessionLocked,getLockedSessionInfo,addKnowledgeBase,removeKnowledgeBase,getKnowledgeBases,toggleKnowledgeBase};function initialize(){const _0x17d8af=_0x177034;context=SillyTavern[_0x17d8af(0x163)]();if(!context){console[_0x17d8af(0xd2)](_0x17d8af(0x131));return;}settings=getSettings(),!window[_0x17d8af(0x102)]&&(window[_0x17d8af(0x102)]={}),window[_0x17d8af(0x102)]['rearrangeChat']=rearrangeChat,window['hanlinyuanRagProcessor']['initialized']=!![],console[_0x17d8af(0xc7)](_0x17d8af(0xdd));}async function ingestTextToHanlinyuan(_0xa96460,_0x1b55fa=_0x177034(0x15c),_0x37026a={},_0x2b4095=()=>{},_0x3cc889=null,_0x25b4c5=()=>{},_0x213cf6=()=>{},_0x131981=null,_0x1936ff=0x0){const _0x486915=_0x177034;if(!_0xa96460||!_0xa96460[_0x486915(0x159)]())return{'success':![],'error':_0x486915(0x154)};if(!settings)return{'success':![],'error':'核心未初始化'};try{const _0x3d9ecb=getCollectionIdInfo(),_0xf1807a=await _0x24c28a();if(_0x3d9ecb[_0x486915(0xfb)]&&_0x3d9ecb[_0x486915(0xfb)]===_0xf1807a&&_0x3d9ecb[_0x486915(0xfb)]!==_0x3d9ecb[_0x486915(0x173)]){const _0x17b1a7=confirm(_0x486915(0x16a));if(_0x17b1a7)_0x25b4c5(_0x486915(0x119)+_0x3d9ecb[_0x486915(0xfb)],_0x486915(0x186)),await purgeStorage(_0x3d9ecb[_0x486915(0xfb)]),_0x25b4c5(_0x486915(0xe7),_0x486915(0x13a));else return _0x25b4c5('[翰林院-迁移]\x20用户取消了迁移操作。',_0x486915(0xe8)),toastr[_0x486915(0xe8)](_0x486915(0x187)),{'success':![],'error':_0x486915(0x107)};}let _0x2a8a2b,_0x18131a;const _0x48c0f1=new Date()[_0x486915(0x148)](_0x486915(0x19b),{'hour12':![]}),_0x50bf5e=getCharacterName()||'未知角色';switch(_0x1b55fa){case _0x486915(0xe0):const _0x39e332=_0x37026a[_0x486915(0xee)]||{},_0x2a409f=_0x39e332[_0x486915(0x179)]??'?',_0x5e25b1=_0x39e332[_0x486915(0x15a)]===0x0?'末':_0x39e332[_0x486915(0x15a)]??'?';_0x2a8a2b=_0x50bf5e+':\x20'+_0x2a409f+'楼-'+_0x5e25b1+'楼';break;case _0x486915(0x121):const _0x3d2a4d=_0x37026a[_0x486915(0x10f)]||_0x486915(0x11a),_0x322695=_0x37026a[_0x486915(0x109)]||_0x486915(0x103);_0x2a8a2b=_0x3d2a4d+':\x20'+_0x322695;break;case _0x486915(0x120):_0x2a8a2b=_0x486915(0x188)+(_0x37026a[_0x486915(0xf1)]||'未知小说');break;case _0x486915(0x15c):default:_0x2a8a2b='手动录入:\x20'+_0x48c0f1;break;}const _0x3cdcfd=Object['values'](getKnowledgeBases()),_0x2420e7=_0x3cdcfd[_0x486915(0xf8)](_0x23e2ea=>_0x23e2ea[_0x486915(0xd4)]===_0x2a8a2b);if(_0x2420e7)_0x18131a=_0x2420e7['id'],_0x25b4c5('[翰林院-核心]\x20检测到同名知识库\x20\x22'+_0x2a8a2b+_0x486915(0x170),_0x486915(0xe8));else{_0x25b4c5(_0x486915(0xef)+_0x2a8a2b+_0x486915(0x165),'info');const _0x4c346a=addKnowledgeBase(_0x2a8a2b);_0x18131a=_0x4c346a['id'];}const _0x3a0053=getCharacterStableId(),_0x1cb555=_0x3a0053+'_'+_0x18131a;_0x25b4c5(_0x486915(0x19f)+_0x2a8a2b+_0x486915(0x184)+_0x1cb555+')',_0x486915(0x13a)),_0x25b4c5(_0x486915(0xfe)+_0x1cb555,'info'),_0x2b4095({'message':'正在智能分块...','processed':0x0,'total':0x1});const _0x3961bc=splitIntoChunks(_0xa96460,_0x1b55fa,_0x37026a),_0x107f1b=_0x3961bc[_0x486915(0x18a)];if(_0x3cc889?.[_0x486915(0x125)])throw new Error(_0x486915(0x17a));_0x25b4c5(_0x486915(0x182)+_0x2a8a2b+_0x486915(0xd9)+_0x107f1b+_0x486915(0xfc),'info');if(_0x107f1b===0x0)return{'success':!![],'count':0x0};const _0x395f31=settings[_0x486915(0x113)][_0x486915(0x106)]||0x5;let _0x392548=_0x1936ff;for(let _0x56fd7d=_0x1936ff;_0x56fd7d<_0x107f1b;_0x56fd7d+=_0x395f31){if(_0x3cc889?.['aborted'])throw new Error(_0x486915(0x17a));const _0x3ca5d3=_0x3961bc['slice'](_0x56fd7d,_0x56fd7d+_0x395f31);_0x2b4095({'message':_0x486915(0xe2)+(_0x56fd7d+0x1)+'-'+(_0x56fd7d+_0x3ca5d3[_0x486915(0x18a)])+'\x20块','processed':_0x56fd7d,'total':_0x107f1b});const _0x5dcef2=_0x3ca5d3[_0x486915(0x12a)](_0x168473=>_0x168473[_0x486915(0xf2)]),_0x2aff06=await getEmbeddings(_0x5dcef2,_0x3cc889);if(_0x3cc889?.[_0x486915(0x125)])throw new Error(_0x486915(0x17a));if(_0x3ca5d3[_0x486915(0x18a)]!==_0x2aff06[_0x486915(0x18a)])throw new Error('文本块和向量数量不匹配');const _0x44b6fb=_0x3ca5d3[_0x486915(0x12a)]((_0x4e15c1,_0x11cf1d)=>({..._0x4e15c1,'vector':_0x2aff06[_0x11cf1d]}));await insertVectors(_0x44b6fb,_0x3cc889,_0x1cb555),_0x392548+=_0x3ca5d3[_0x486915(0x18a)],_0x131981&&_0x1aa8ce[_0x486915(0x118)](_0x131981,_0x392548,_0x107f1b),await _0x213cf6();}return _0x131981&&_0x1aa8ce[_0x486915(0x16b)](_0x131981),_0x25b4c5(_0x486915(0x101)+_0x392548+_0x486915(0x13f),_0x486915(0x13a)),{'success':!![],'count':_0x392548};}catch(_0x1670e5){if(_0x1670e5[_0x486915(0xd4)]===_0x486915(0x17a)){_0x25b4c5(_0x486915(0x10b),_0x486915(0x186));throw _0x1670e5;}return console[_0x486915(0xd2)](_0x486915(0x112),_0x1670e5),_0x25b4c5(_0x486915(0x1a1)+_0x1670e5[_0x486915(0x164)],_0x486915(0xd2)),{'success':![],'error':_0x1670e5[_0x486915(0x164)]};}}function getSettings(){const _0x3fc22c=_0x177034;if(!context||!context['extensionSettings'])return structuredClone(_0x2ac380);let _0x54edf8=context['extensionSettings'][MODULE_NAME];!_0x54edf8&&(_0x54edf8={},context[_0x3fc22c(0x141)][MODULE_NAME]=_0x54edf8);_0x54edf8[_0x3fc22c(0xfa)]===undefined&&(_0x54edf8[_0x3fc22c(0xfa)]={});_0x54edf8[_0x3fc22c(0x157)]===undefined&&(_0x54edf8[_0x3fc22c(0x157)]={});for(const _0x6a982e in _0x2ac380){if(_0x54edf8[_0x6a982e]===undefined)_0x54edf8[_0x6a982e]=structuredClone(_0x2ac380[_0x6a982e]);else{if(typeof _0x2ac380[_0x6a982e]===_0x3fc22c(0x15b)&&!Array[_0x3fc22c(0x19a)](_0x2ac380[_0x6a982e])&&_0x2ac380[_0x6a982e]!==null)for(const _0x1b3ce6 in _0x2ac380[_0x6a982e]){_0x54edf8[_0x6a982e][_0x1b3ce6]===undefined&&(_0x54edf8[_0x6a982e][_0x1b3ce6]=_0x2ac380[_0x6a982e][_0x1b3ce6]);}}}return _0x54edf8;}function saveSettings(){const _0x174ae2=_0x177034;if(context)context[_0x174ae2(0xe4)]();}function resetSettings(){context&&(context['extensionSettings'][MODULE_NAME]=structuredClone(_0x2ac380),saveSettings());}function showNotification(_0x4a86fc,_0x5bcdac=_0x177034(0xe8)){toastr[_0x5bcdac](_0x4a86fc);}function getTagForSource(_0x538ec){const _0x18f60c=_0x177034;switch(_0x538ec){case _0x18f60c(0xe0):return _0x18f60c(0x199);case _0x18f60c(0x121):return _0x18f60c(0x135);case'manual':return _0x18f60c(0x18e);case'novel':return'小说录入';default:return'资料';}}function splitIntoChunks(_0x288d1a,_0x3c545c,_0x575860={}){const _0x1e7027=_0x177034;switch(_0x3c545c){case _0x1e7027(0x120):return _chunkForNovel(_0x288d1a,_0x575860);case'chat_history':return _chunkForChatHistory(_0x288d1a,_0x575860);case _0x1e7027(0x121):return _chunkForLorebook(_0x288d1a,_0x575860);case _0x1e7027(0x15c):return _chunkForManual(_0x288d1a,_0x575860);default:console[_0x1e7027(0x186)]('[翰林院-分块]\x20未知的来源类型\x20\x27'+_0x3c545c+_0x1e7027(0x100));return _chunkForManual(_0x288d1a,{..._0x575860,'sourceName':_0x575860[_0x1e7027(0xf1)]||'未知来源'});}}function _chunkForNovel(_0x2f59cb,_0x280eee){const _0x30b479=_0x177034,{chunkSize:_0x259ab8,overlap:_0x3de6c2}=settings[_0x30b479(0x19d)],{sourceName:sourceName='小说'}=_0x280eee,_0x25ed7f=[];if(!_0x2f59cb||_0x259ab8<=0x0)return _0x25ed7f;const _0xac38db=/(第\s*[一二三四五六七八九十百千万零\d]+\s*卷)/gim,_0x2874da=/(第\s*[一二三四五六七八九十百千万零\d]+\s*[章回节部])|^(Chapter\s+\d+)/gim;let _0xcbca17=0x0;const _0x5057e6=_0x2f59cb[_0x30b479(0xd1)]('\x0a');let _0x5a30a5=_0x30b479(0x189),_0x1120ff='第1章',_0x3218fd=[];function _0x4127df(){const _0x2f1d6b=_0x30b479;if(_0x3218fd[_0x2f1d6b(0x18a)]===0x0)return;const _0x43e2c9=_0x3218fd[_0x2f1d6b(0x142)]('\x0a');let _0x465e54=0x0,_0x17fd49=0x1;while(_0x465e54<_0x43e2c9[_0x2f1d6b(0x18a)]){const _0x2fb012=Math[_0x2f1d6b(0x17e)](_0x465e54+_0x259ab8,_0x43e2c9[_0x2f1d6b(0x18a)]),_0xf503aa=_0x43e2c9[_0x2f1d6b(0x152)](_0x465e54,_0x2fb012);if(_0xf503aa['trim']()[_0x2f1d6b(0x18a)]>0x0){const _0x539020={'source':_0x2f1d6b(0x120),'sourceName':sourceName,'timestamp':new Date()[_0x2f1d6b(0x158)](),'globalIndex':_0xcbca17++,'volume':_0x5a30a5,'chapter':_0x1120ff,'section':_0x17fd49},_0x5b7caf=getTagForSource('novel'),_0x5f2fa6='[来源:\x20'+sourceName+',\x20'+_0x5a30a5+',\x20'+_0x1120ff+',\x20第'+_0x17fd49+'节]',_0x5404a2='<'+_0x5b7caf+'>\x0a'+_0x5f2fa6+'\x0a'+_0xf503aa+_0x2f1d6b(0xde)+_0x5b7caf+'>';_0x25ed7f[_0x2f1d6b(0x104)]({'text':_0x5404a2,'metadata':_0x539020}),_0x17fd49++;}_0x465e54+=_0x259ab8-_0x3de6c2;if(_0x465e54>=_0x43e2c9[_0x2f1d6b(0x18a)])break;}_0x3218fd=[];}for(const _0x549ddb of _0x5057e6){const _0x363073=_0x549ddb[_0x30b479(0x159)]();if(_0xac38db['test'](_0x363073))_0x4127df(),_0x5a30a5=_0x363073,_0x1120ff=_0x30b479(0x14c);else _0x2874da[_0x30b479(0x160)](_0x363073)?(_0x4127df(),_0x1120ff=_0x363073):_0x3218fd[_0x30b479(0x104)](_0x549ddb);}_0x4127df();if(_0x25ed7f[_0x30b479(0x18a)]===0x0&&_0x2f59cb[_0x30b479(0x18a)]>0x0){let _0x2fb14b=0x0,_0xb8e8c3=0x1;while(_0x2fb14b<_0x2f59cb[_0x30b479(0x18a)]){const _0x3492ff=Math[_0x30b479(0x17e)](_0x2fb14b+_0x259ab8,_0x2f59cb[_0x30b479(0x18a)]),_0x15841f=_0x2f59cb[_0x30b479(0x152)](_0x2fb14b,_0x3492ff),_0x171ac2={'source':'novel','sourceName':sourceName,'timestamp':new Date()[_0x30b479(0x158)](),'globalIndex':_0x25ed7f['length'],'volume':_0x30b479(0x189),'chapter':_0x30b479(0x14c),'section':_0xb8e8c3},_0x41581f=getTagForSource('novel'),_0x2a59dd='[来源:\x20'+sourceName+_0x30b479(0x171)+_0xb8e8c3+'节]',_0x186c36='<'+_0x41581f+'>\x0a'+_0x2a59dd+'\x0a'+_0x15841f+_0x30b479(0xde)+_0x41581f+'>';_0x25ed7f[_0x30b479(0x104)]({'text':_0x186c36,'metadata':_0x171ac2}),_0xb8e8c3++,_0x2fb14b+=_0x259ab8-_0x3de6c2;}}return _0x25ed7f;}function _chunkForChatHistory(_0x5c34cf,_0x32a2ed){const _0xd3ecd0=_0x177034,{chunkSize:_0x2f0648,overlap:_0xb0afd8}=settings[_0xd3ecd0(0x19d)],{floor:_0x424bf0,is_user:_0x52f864,timestamp:_0x5c6a1e}=_0x32a2ed,_0x31168f=[];if(!_0x5c34cf||_0x2f0648<=0x0)return _0x31168f;let _0x26cb5e=0x1,_0xa1b582=0x0;while(_0xa1b582<_0x5c34cf[_0xd3ecd0(0x18a)]){const _0xdaacb3=Math['min'](_0xa1b582+_0x2f0648,_0x5c34cf['length']),_0x252076=_0x5c34cf[_0xd3ecd0(0x152)](_0xa1b582,_0xdaacb3),_0x294139=_0xd3ecd0(0x18b)+_0x424bf0+_0xd3ecd0(0x13e)+_0x26cb5e+'部分]',_0x492b86=getTagForSource(_0xd3ecd0(0xe0)),_0x1c440c='<'+_0x492b86+'>\x0a'+_0x294139+'\x0a'+_0x252076+_0xd3ecd0(0xde)+_0x492b86+'>';_0x31168f['push']({'text':_0x1c440c,'metadata':{'source':_0xd3ecd0(0xe0),'sourceName':'聊天记录\x20#'+_0x424bf0,'floor':_0x424bf0,'part':_0x26cb5e,'is_user':_0x52f864,'timestamp':_0x5c6a1e}}),_0x26cb5e++,_0xa1b582+=_0x2f0648-_0xb0afd8;if(_0xa1b582>=_0x5c34cf[_0xd3ecd0(0x18a)])break;}return _0x31168f;}function _0x1ae4(_0x1b1db8,_0xe47df9){const _0x4888c9=_0x4888();return _0x1ae4=function(_0x1ae4d7,_0x163d9a){_0x1ae4d7=_0x1ae4d7-0xc4;let _0x2a484f=_0x4888c9[_0x1ae4d7];return _0x2a484f;},_0x1ae4(_0x1b1db8,_0xe47df9);}function _chunkForLorebook(_0x50fd01,_0x1380db){const _0x5f343c=_0x177034,{chunkSize:_0xaa7cab,overlap:_0xd0cb0b}=settings[_0x5f343c(0x19d)],{sourceName:sourceName=_0x5f343c(0xd0)}=_0x1380db,_0x59ac92=[];if(!_0x50fd01||_0xaa7cab<=0x0)return _0x59ac92;let _0x1e9ae3=0x1,_0x12b4b5=0x0;while(_0x12b4b5<_0x50fd01['length']){const _0x217e68=Math[_0x5f343c(0x17e)](_0x12b4b5+_0xaa7cab,_0x50fd01[_0x5f343c(0x18a)]),_0x15ecc8=_0x50fd01[_0x5f343c(0x152)](_0x12b4b5,_0x217e68),_0x25be5f=_0x5f343c(0xfd)+sourceName+_0x5f343c(0x13e)+_0x1e9ae3+_0x5f343c(0xca),_0x44d275=getTagForSource(_0x5f343c(0x121)),_0x4a1a1f='<'+_0x44d275+'>\x0a'+_0x25be5f+'\x0a'+_0x15ecc8+_0x5f343c(0xde)+_0x44d275+'>';_0x59ac92['push']({'text':_0x4a1a1f,'metadata':{'source':_0x5f343c(0x121),'sourceName':sourceName,'part':_0x1e9ae3,'timestamp':new Date()[_0x5f343c(0x158)]()}}),_0x1e9ae3++,_0x12b4b5+=_0xaa7cab-_0xd0cb0b;if(_0x12b4b5>=_0x50fd01[_0x5f343c(0x18a)])break;}return _0x59ac92;}function _chunkForManual(_0x487b44,_0x1ef584){const _0x1d5865=_0x177034,{chunkSize:_0x14f8c3,overlap:_0x278e59}=settings[_0x1d5865(0x19d)],{sourceName:sourceName='手动录入'}=_0x1ef584,_0x399619=[];if(!_0x487b44||_0x14f8c3<=0x0)return _0x399619;const _0x5b82e6=new Date(),_0x38fa5c=_0x5b82e6[_0x1d5865(0x148)](_0x1d5865(0x19b));let _0x51249b=0x1,_0x3d7964=0x0;while(_0x3d7964<_0x487b44[_0x1d5865(0x18a)]){const _0x2bca43=Math[_0x1d5865(0x17e)](_0x3d7964+_0x14f8c3,_0x487b44[_0x1d5865(0x18a)]),_0x30e585=_0x487b44[_0x1d5865(0x152)](_0x3d7964,_0x2bca43),_0x5ad08a=_0x1d5865(0x151)+sourceName+_0x1d5865(0x16d)+_0x38fa5c+',\x20第'+_0x51249b+_0x1d5865(0xca),_0x4833e3=getTagForSource(_0x1d5865(0x15c)),_0x576305='<'+_0x4833e3+'>\x0a'+_0x5ad08a+'\x0a'+_0x30e585+_0x1d5865(0xde)+_0x4833e3+'>';_0x399619[_0x1d5865(0x104)]({'text':_0x576305,'metadata':{'source':_0x1d5865(0x15c),'sourceName':sourceName,'part':_0x51249b,'timestamp':_0x5b82e6[_0x1d5865(0x158)]()}}),_0x51249b++,_0x3d7964+=_0x14f8c3-_0x278e59;if(_0x3d7964>=_0x487b44['length'])break;}return _0x399619;}import{getCollectionId as _0x24c28a,getCharacterName}from'./utils/context-utils.js';async function getCollectionId(){return lockedCollectionId||await _0x24c28a();}async function toggleSessionLock(){return lockedCollectionId?(lockedCollectionId=null,![]):(lockedCollectionId=await _0x24c28a(),!![]);}function isSessionLocked(){return lockedCollectionId!==null;}function getLockedSessionInfo(){const _0x2b72bf=_0x177034;if(!lockedCollectionId)return null;return{'id':lockedCollectionId,'name':'(已锁定:\x20'+lockedCollectionId[_0x2b72bf(0x152)](0x0,0x8)+_0x2b72bf(0x147)};}function getKnowledgeBases(){const _0x6c58ad=_0x177034,_0x214303=getCharacterStableId();return!settings['knowledgeBases'][_0x214303]&&(settings[_0x6c58ad(0x157)][_0x214303]={}),settings[_0x6c58ad(0x157)][_0x214303];}function addKnowledgeBase(_0x23a4d1){const _0x3b70b7=_0x177034;if(!_0x23a4d1||!_0x23a4d1[_0x3b70b7(0x159)]())throw new Error(_0x3b70b7(0x17d));const _0x1b5e2d=getCharacterStableId(),_0x346078=getKnowledgeBases(),_0x306535=_0x3b70b7(0x111)+Date['now']()+'_'+Math['random']()[_0x3b70b7(0xc4)](0x24)['substring'](0x2,0x9),_0x3e4290={'id':_0x306535,'name':_0x23a4d1[_0x3b70b7(0x159)](),'enabled':!![],'createdAt':new Date()[_0x3b70b7(0x158)]()};return _0x346078[_0x306535]=_0x3e4290,saveSettings(),console[_0x3b70b7(0xc7)](_0x3b70b7(0x13b)+_0x1b5e2d+_0x3b70b7(0xc6)+_0x23a4d1+_0x3b70b7(0x117)+_0x306535+')'),_0x3e4290;}async function removeKnowledgeBase(_0x396c2c){const _0x979a75=_0x177034,_0xf54c8a=getCharacterStableId(),_0x48b749=getKnowledgeBases(),_0x25e128=_0x48b749[_0x396c2c]?.['name']||_0x396c2c;if(!_0x48b749[_0x396c2c]){console[_0x979a75(0x186)](_0x979a75(0x18f)+_0x396c2c);return;}const _0x10d5d0=_0xf54c8a+'_'+_0x396c2c;console[_0x979a75(0xc7)](_0x979a75(0x153)+_0x396c2c+_0x979a75(0x156)+_0x10d5d0);const _0x8dd429=await purgeStorage(_0x10d5d0);_0x8dd429?(delete _0x48b749[_0x396c2c],saveSettings(),console[_0x979a75(0xc7)]('[翰林院-核心]\x20成功删除知识库\x20'+_0x396c2c+'\x20及其向量数据。'),toastr['success'](_0x979a75(0xd8)+_0x25e128+_0x979a75(0x16c))):(console[_0x979a75(0xd2)]('[翰林院-核心]\x20清空向量集合\x20'+_0x10d5d0+_0x979a75(0x110)),toastr[_0x979a75(0xd2)](_0x979a75(0xd6)));}function toggleKnowledgeBase(_0xb4d84f){const _0x34099a=_0x177034,_0x23ea1f=getKnowledgeBases();_0x23ea1f[_0xb4d84f]&&(_0x23ea1f[_0xb4d84f]['enabled']=!_0x23ea1f[_0xb4d84f][_0x34099a(0x129)],saveSettings(),console[_0x34099a(0xc7)](_0x34099a(0xcb)+_0xb4d84f+_0x34099a(0x132)+(_0x23ea1f[_0xb4d84f]['enabled']?'启用':'禁用')));}function generateHash(_0x4f4097){const _0x477797=_0x177034;let _0x12669e=0x0;for(let _0x3fead5=0x0;_0x3fead5<_0x4f4097['length'];_0x3fead5++){const _0x2663bf=_0x4f4097['charCodeAt'](_0x3fead5);_0x12669e=(_0x12669e<<0x5)-_0x12669e+_0x2663bf,_0x12669e=_0x12669e&_0x12669e;}return Math[_0x477797(0x11e)](_0x12669e)[_0x477797(0xc4)](0x24);}async function queryVectors(_0xca17e4){const _0x5e42a2=_0x177034;console[_0x5e42a2(0xc7)](_0x5e42a2(0x150));const _0x488a12=getCharacterStableId(),_0x229f5c=getKnowledgeBases(),_0x2926d9=Object[_0x5e42a2(0xf5)](_0x229f5c)[_0x5e42a2(0x11d)](_0x28aae8=>_0x28aae8['enabled']);if(_0x2926d9[_0x5e42a2(0x18a)]===0x0){console[_0x5e42a2(0xc7)](_0x5e42a2(0xf4));const _0x2bc4e8=await _0x24c28a();if(!_0x2bc4e8)return[];_0x2926d9[_0x5e42a2(0x104)]({'id':null,'name':_0x5e42a2(0x14f)});}const _0x16726c=(await getEmbeddings([_0xca17e4]))[0x0];let _0x58b10b=[];const _0x3c5f7f=_0x2926d9[_0x5e42a2(0x12a)](_0xc894e6=>{const _0x2f60a6=_0x5e42a2,_0x42d0d0=_0xc894e6['id']===null?_0x24c28a():Promise[_0x2f60a6(0xe5)](_0x488a12+'_'+_0xc894e6['id']);return _0x42d0d0[_0x2f60a6(0x198)](_0x15594c=>{const _0x46f2d2=_0x2f60a6;if(!_0x15594c)return[];console[_0x46f2d2(0xc7)](_0x46f2d2(0x11f)+_0xc894e6[_0x46f2d2(0xd4)]+_0x46f2d2(0x117)+_0x15594c+')');const _0x26d363={'collectionId':_0x15594c,'searchText':_0xca17e4,'topK':settings[_0x46f2d2(0x19d)][_0x46f2d2(0x168)],'threshold':settings['advanced'][_0x46f2d2(0x196)],'source':_0x46f2d2(0x190),'embeddings':{[_0xca17e4]:_0x16726c}};return fetch('/api/vector/query',{'method':'POST','headers':context[_0x46f2d2(0xda)](),'body':JSON['stringify'](_0x26d363)})[_0x46f2d2(0x198)](async _0x19268b=>{const _0x3fdf5c=_0x46f2d2;if(!_0x19268b['ok']){const _0x1d15e3=await _0x19268b[_0x3fdf5c(0xf2)]();return console[_0x3fdf5c(0xd2)](_0x3fdf5c(0xec)+_0x15594c+_0x3fdf5c(0x10e),_0x1d15e3),[];}const _0x1257df=await _0x19268b[_0x3fdf5c(0xce)](),_0x26cee1=_0x1257df[_0x3fdf5c(0x14a)]||_0x1257df[_0x3fdf5c(0xf9)]||_0x1257df[_0x3fdf5c(0xcc)]||[];return console[_0x3fdf5c(0xc7)](_0x3fdf5c(0x19c)+_0xc894e6[_0x3fdf5c(0xd4)]+_0x3fdf5c(0x14e)+_0x26cee1[_0x3fdf5c(0x18a)]+_0x3fdf5c(0x13d)),_0x26cee1;})[_0x46f2d2(0x13c)](_0x53275d=>{const _0x2fd7eb=_0x46f2d2;return console[_0x2fd7eb(0xd2)](_0x2fd7eb(0xec)+_0x15594c+'\x20时发生网络错误:',_0x53275d),[];});});}),_0x4cad98=await Promise['all'](_0x3c5f7f);_0x58b10b=_0x4cad98[_0x5e42a2(0x194)](),console[_0x5e42a2(0xc7)](_0x5e42a2(0x180)+_0x58b10b[_0x5e42a2(0x18a)]+'\x20条初步结果。');const _0x2ce09e=[],_0x50a504=new Set();for(const _0x3ac708 of _0x58b10b){_0x3ac708&&_0x3ac708[_0x5e42a2(0xf2)]&&!_0x50a504['has'](_0x3ac708[_0x5e42a2(0xf2)])&&(_0x50a504[_0x5e42a2(0x12e)](_0x3ac708[_0x5e42a2(0xf2)]),_0x2ce09e[_0x5e42a2(0x104)](_0x3ac708));}return console[_0x5e42a2(0xc7)](_0x5e42a2(0x15f)+_0x2ce09e[_0x5e42a2(0x18a)]+'\x20条结果。'),_0x2ce09e[_0x5e42a2(0x192)]((_0x1d2bd5,_0x318f0f)=>(_0x318f0f[_0x5e42a2(0x143)]||0x0)-(_0x1d2bd5[_0x5e42a2(0x143)]||0x0)),_0x2ce09e;}async function insertVectors(_0x3a6fd5,_0x2dc246=null,_0x3bf812){const _0x763d71=_0x177034;if(!_0x3bf812)throw new Error(_0x763d71(0xf7));if(_0x3a6fd5[_0x763d71(0x18a)]===0x0)return{'success':!![],'count':0x0};const _0x217914=_0x3a6fd5[_0x763d71(0x12a)]((_0x3a02f3,_0x189087)=>({'hash':generateHash(_0x3a02f3['text']+Date[_0x763d71(0xeb)]()+_0x189087),'text':_0x3a02f3[_0x763d71(0xf2)],'metadata':_0x3a02f3[_0x763d71(0x14a)]||{'source':'unknown','timestamp':new Date()['toISOString']()}})),_0x1bb0a8=_0x217914['reduce']((_0xdd38db,_0x7e22bb,_0x55a0c1)=>{const _0x1a4c22=_0x763d71;return _0xdd38db[_0x7e22bb[_0x1a4c22(0xf2)]]=_0x3a6fd5[_0x55a0c1][_0x1a4c22(0x15e)],_0xdd38db;},{}),_0x3d241a={'collectionId':_0x3bf812,'items':_0x217914,'source':_0x763d71(0x190),'embeddings':_0x1bb0a8},_0x40ee5b=await fetch(_0x763d71(0x124),{'method':'POST','headers':context[_0x763d71(0xda)](),'body':JSON['stringify'](_0x3d241a),'signal':_0x2dc246});if(!_0x40ee5b['ok']){const _0x63bcf4=await _0x40ee5b[_0x763d71(0xf2)]();console[_0x763d71(0xd2)](_0x763d71(0x138),_0x63bcf4);throw new Error(_0x763d71(0xc9)+_0x40ee5b['status']+':\x20'+_0x63bcf4);}return{'success':!![],'count':_0x217914[_0x763d71(0x18a)]};}function _0x4888(){const _0x406162=['manual','1272562tVOZIH','vector','[翰林院-日志]\x20去重后剩余\x20','test','slice','getTime','getContext','message','\x22\x20创建专属知识库...','index','\x20-\x20楼层\x20#','maxResults','warning','检测到旧版数据。此操作将把旧数据迁移到新格式,过程不可逆,是否继续?','clearJob','\x22\x20已删除。',',\x20向量化录入时间:\x20','floor','[翰林院-日志]\x20开始清空宝库...','\x22,将数据合并入库。',',\x20第1卷,\x20第1章,\x20第','[翰林院-日志]\x20集合\x20','newId','final_score','quiet','HANLINYUAN_RAG','474453aviljF','[翰林院-核心]\x20聊天记录凝识完成,成功插入\x20','start','AbortError','[翰林院-核心]\x20已为宝库\x20','max','知识库名称不能为空','min','notify','[翰林院-日志]\x20所有知识库查询完毕,共获得\x20','凝识之权未开启','[翰林院-核心]\x20将来源\x27','hybrid_alpha','\x20(集合ID:\x20','hashes','warn','操作已取消。','小说:\x20','第1卷','length','[来源:\x20聊天记录,\x20楼层:\x20#','未知角色','[翰林院-日志]\x20统计集合\x20','手动录入','[翰林院-核心]\x20尝试删除一个不存在的知识库:\x20','webllm','/api/vector/purge','sort','[翰林院-日志]\x20清空宝库API错误:','flat','Rerank失败:\x20','matchThreshold','injection','then','聊天记录','isArray','zh-CN','[翰林院-日志]\x20知识库\x20','advanced','%%HANLINYUAN_RAG_INJECTION%%','[翰林院-核心]\x20已创建并锁定知识库:\x20','depth','[翰林院-核心]\x20文本录入失败:\x20','No\x20messages\x20to\x20process.','toString','relevance_score','\x20添加新知识库:\x20','log','\x20个条目。','忆识存入API错误\x20','部分]','[翰林院-核心]\x20知识库\x20','data','\x20记录凝识范围:\x20','json','3500400FnoDcL','世界书条目','split','error',']\x20的消息已成功凝识。','name','stringify','删除知识库失败,未能清空后端数据。','52552gxuMwE','知识库\x20\x22','\x27的文本分割成\x20','getRequestHeaders','355VcCfsp','825008VDYXhM','翰林院忆识核心已启动\x20(V5.2-集成版),已注册到全局\x20hanlinyuanRagProcessor\x20对象。','\x0a{const _0x11858e=_0x239781+'_'+_0x113843['id'];return countVectorsInCollection(_0x11858e);}),_0x41133c=await _0x24c28a();_0x3b8404[_0x52c4ba(0x104)](countVectorsInCollection(_0x41133c));const _0x423edb=await Promise[_0x52c4ba(0x128)](_0x3b8404),_0xc309a1=_0x423edb[_0x52c4ba(0x149)]((_0x1e46a4,_0x2cd474)=>_0x1e46a4+_0x2cd474,0x0);return console[_0x52c4ba(0xc7)](_0x52c4ba(0x126)+_0xc309a1),_0xc309a1;}}async function countVectorsInCollection(_0x14ee12){const _0x3bc488=_0x177034;if(!_0x14ee12)return 0x0;console[_0x3bc488(0xc7)]('[翰林院-日志]\x20统计目标集合ID:\x20'+_0x14ee12);const _0x36e1fc={'collectionId':_0x14ee12,'source':_0x3bc488(0x190),'embeddings':{}};try{const _0x341737=await fetch(_0x3bc488(0xf0),{'method':_0x3bc488(0x14d),'headers':context[_0x3bc488(0xda)](),'body':JSON[_0x3bc488(0xd5)](_0x36e1fc)});if(!_0x341737['ok']){if(_0x341737['status']===0x194)console[_0x3bc488(0xc7)](_0x3bc488(0x172)+_0x14ee12+_0x3bc488(0x146));else{const _0xccca9=await _0x341737[_0x3bc488(0xf2)]();console[_0x3bc488(0x186)](_0x3bc488(0xe6)+_0x14ee12+'\x20列表API时出现问题\x20(状态:\x20'+_0x341737[_0x3bc488(0x140)]+'):',_0xccca9);}return 0x0;}const _0x16361a=await _0x341737[_0x3bc488(0xce)]();let _0x5163a1=0x0;if(Array['isArray'](_0x16361a))_0x5163a1=_0x16361a[_0x3bc488(0x18a)];else _0x16361a&&_0x16361a[_0x3bc488(0x185)]&&(_0x5163a1=_0x16361a[_0x3bc488(0x185)][_0x3bc488(0x18a)]);return _0x5163a1;}catch(_0x9e3ab5){return console[_0x3bc488(0xd2)](_0x3bc488(0x18d)+_0x14ee12+_0x3bc488(0x10c),_0x9e3ab5),0x0;}}async function purgeStorage(_0x189414=null){const _0x5233ea=_0x177034;console[_0x5233ea(0xc7)](_0x5233ea(0x16f));const _0x55da70=_0x189414||await getCollectionId();if(!_0x55da70)return console[_0x5233ea(0xd2)](_0x5233ea(0x12f)),toastr[_0x5233ea(0xd2)]('无法确定要清空的目标宝库。'),![];console['log']('[翰林院-日志]\x20清空目标集合ID:\x20'+_0x55da70);const _0xf66081={'collectionId':_0x55da70};console[_0x5233ea(0xc7)]('[翰林院-日志]\x20发送到\x20/api/vector/purge\x20的请求体:',JSON[_0x5233ea(0xd5)](_0xf66081,null,0x2));const _0x4010f3=await fetch(_0x5233ea(0x191),{'method':_0x5233ea(0x14d),'headers':context[_0x5233ea(0xda)](),'body':JSON[_0x5233ea(0xd5)](_0xf66081)});console[_0x5233ea(0xc7)]('[翰林院-日志]\x20/api/vector/purge\x20响应状态:\x20'+_0x4010f3[_0x5233ea(0x140)]);if(!_0x4010f3['ok']){const _0x12f7c5=await _0x4010f3[_0x5233ea(0xf2)]();console[_0x5233ea(0xd2)](_0x5233ea(0x193),_0x12f7c5);}else console[_0x5233ea(0xc7)]('[翰林院-日志]\x20清空宝库API调用成功。');return _0x4010f3['ok'];}function getMessagesForCondensation(_0x3ae9d1=null){const _0x28e9cd=_0x177034;if(!settings['condensation'][_0x28e9cd(0x129)])return showNotification(_0x28e9cd(0x181),_0x28e9cd(0x169)),[];const {layerStart:_0x193b76,layerEnd:_0x10831f}=settings[_0x28e9cd(0x136)],_0x4c83a8=_0x3ae9d1||settings[_0x28e9cd(0x136)][_0x28e9cd(0x11b)],_0x85572b=context[_0x28e9cd(0x114)][_0x28e9cd(0x18a)],_0x5a6493=Math[_0x28e9cd(0x17c)](0x0,_0x193b76-0x1),_0x2ad999=_0x10831f===0x0||_0x10831f>_0x85572b?_0x85572b:Math[_0x28e9cd(0x17e)](_0x85572b,_0x10831f),_0x11e676=context[_0x28e9cd(0x114)][_0x28e9cd(0x161)](_0x5a6493,_0x2ad999);return _0x11e676[_0x28e9cd(0x11d)](_0x53d22e=>{const _0x41c5c9=_0x28e9cd,_0x17ae09=_0x53d22e[_0x41c5c9(0xff)]===!![],_0x300d6f=_0x53d22e['is_user']===![];if(!_0x53d22e[_0x41c5c9(0x133)]||!_0x53d22e[_0x41c5c9(0x133)][_0x41c5c9(0x159)]())return![];return _0x4c83a8['user']&&_0x17ae09||_0x4c83a8['ai']&&_0x300d6f;});}async function processCondensation(_0x117212,_0x1078d6=()=>{},_0x1553b1=null){const _0x115991=_0x177034;if(!_0x117212||_0x117212[_0x115991(0x18a)]===0x0)return{'success':![],'error':_0x115991(0x1a2)};try{let _0x4213d9,_0x12dc83;const _0x5e4cd1=getCharacterName()||_0x115991(0x18c);if(_0x1553b1){const _0x1f9810=_0x1553b1[_0x115991(0x179)]??'?',_0x201f27=_0x1553b1[_0x115991(0x15a)]===0x0?'末':_0x1553b1[_0x115991(0x15a)]??'?';_0x4213d9=_0x5e4cd1+':\x20'+_0x1f9810+'楼-'+_0x201f27+'楼';}else{const _0x2b88f3=new Date()[_0x115991(0x148)](_0x115991(0x19b),{'hour12':![]});_0x4213d9='聊天记录:\x20'+_0x2b88f3;}const _0x511fbb=Object[_0x115991(0xf5)](getKnowledgeBases()),_0x1a385a=_0x511fbb['find'](_0x51b879=>_0x51b879[_0x115991(0xd4)]===_0x4213d9);if(_0x1a385a)_0x12dc83=_0x1a385a['id'],_0x1078d6('[翰林院-核心]\x20检测到同名知识库\x20\x22'+_0x4213d9+_0x115991(0x170),'info');else{_0x1078d6(_0x115991(0xef)+_0x4213d9+_0x115991(0x165),_0x115991(0xe8));const _0x3545c9=addKnowledgeBase(_0x4213d9);_0x12dc83=_0x3545c9['id'];}const _0x125604=getCharacterStableId(),_0x4ac7de=_0x125604+'_'+_0x12dc83;_0x1078d6(_0x115991(0x10d)+_0x4213d9+_0x115991(0x184)+_0x4ac7de+')',_0x115991(0x13a));const _0x2809d0=[],_0x48b42e=context[_0x115991(0x114)];for(const _0x470803 of _0x117212){const _0x4f7a52=(_0x470803['mes']||'')[_0x115991(0xe1)](/<[^>]*>/g,'')['trim']();if(_0x4f7a52[_0x115991(0x18a)]===0x0)continue;let _0x321956;if(_0x470803[_0x115991(0x16e)]!==undefined&&_0x470803[_0x115991(0x16e)]!==null)_0x321956=_0x470803[_0x115991(0x16e)];else{const _0x2c913f=_0x48b42e['findIndex'](_0x385711=>_0x385711===_0x470803);_0x321956=_0x2c913f!==-0x1?_0x2c913f+0x1:-0x1;}const _0xbe60de=new Date(_0x470803['send_date']),_0x29c43a=isNaN(_0xbe60de[_0x115991(0x162)]())?new Date()[_0x115991(0x158)]():_0xbe60de[_0x115991(0x158)](),_0x4f5050=splitIntoChunks(_0x4f7a52,'chat_history',{'floor':_0x321956,'is_user':_0x470803[_0x115991(0xff)],'timestamp':_0x29c43a});_0x2809d0['push'](..._0x4f5050);}if(_0x2809d0[_0x115991(0x18a)]===0x0)return{'success':!![],'count':0x0};_0x1078d6('[翰林院-核心]\x20已将\x20'+_0x117212[_0x115991(0x18a)]+_0x115991(0x10a)+_0x2809d0[_0x115991(0x18a)]+_0x115991(0x155),_0x115991(0xe8));const _0x95a45e=settings['retrieval']['batchSize']||0x5;let _0x226605=0x0;for(let _0x309aa8=0x0;_0x309aa8<_0x2809d0[_0x115991(0x18a)];_0x309aa8+=_0x95a45e){const _0x58aa1e=_0x2809d0[_0x115991(0x161)](_0x309aa8,_0x309aa8+_0x95a45e),_0x1b79ec=_0x58aa1e[_0x115991(0x12a)](_0x299bba=>_0x299bba[_0x115991(0xf2)]),_0x1768ea=await getEmbeddings(_0x1b79ec);if(_0x58aa1e[_0x115991(0x18a)]!==_0x1768ea['length'])throw new Error(_0x115991(0x127));const _0x3098d=_0x58aa1e[_0x115991(0x12a)]((_0x1a8175,_0x57f9ce)=>({..._0x1a8175,'vector':_0x1768ea[_0x57f9ce]}));await insertVectors(_0x3098d,null,_0x4ac7de),_0x226605+=_0x58aa1e[_0x115991(0x18a)];}if(_0x1553b1){const _0x218764=_0x1553b1['end']===0x0?context['chat'][_0x115991(0x18a)]:_0x1553b1[_0x115991(0x15a)];settings['condensationHistory'][_0x4ac7de]={'start':_0x1553b1[_0x115991(0x179)],'end':_0x218764,'timestamp':new Date()[_0x115991(0x158)]()},saveSettings(),_0x1078d6(_0x115991(0x17b)+_0x4ac7de+_0x115991(0xcd)+_0x1553b1[_0x115991(0x179)]+'-'+_0x218764,_0x115991(0xe8));}_0x1078d6(_0x115991(0x178)+_0x226605+_0x115991(0xc8),_0x115991(0x13a));const _0x34675f=_0x117212['map'](_0x4a5ea6=>{const _0x385bc4=_0x115991,_0x4940ac=_0x48b42e[_0x385bc4(0xe3)](_0x19b949=>_0x19b949===_0x4a5ea6),_0x473547=_0x4940ac!==-0x1?_0x4940ac+0x1:-0x1,_0x146972=_0x4a5ea6['is_user']?'用户':getCharacterName()||'AI';return'['+_0x146972+_0x385bc4(0x167)+_0x473547+_0x385bc4(0xd3);});return{'success':!![],'count':_0x226605,'messages':_0x34675f};}catch(_0x320fd2){return console[_0x115991(0xd2)](_0x115991(0x12c),_0x320fd2),_0x1078d6(_0x115991(0xf3)+_0x320fd2['message'],_0x115991(0xd2)),{'success':![],'error':_0x320fd2[_0x115991(0x164)]};}}async function rerankResults(_0x1bb8f8,_0x4a8f3c,_0x367a2c){const _0x5c4ba3=_0x177034;let _0x366048=_0x1bb8f8;if(_0x367a2c[_0x5c4ba3(0x105)][_0x5c4ba3(0x129)]&&_0x1bb8f8[_0x5c4ba3(0x18a)]>0x0){console['log'](_0x5c4ba3(0x108));try{const _0x1ca0fe=_0x1bb8f8[_0x5c4ba3(0x12a)](_0x292a7a=>_0x292a7a[_0x5c4ba3(0xf2)]),_0x568f72=await executeRerank(_0x4a8f3c,_0x1ca0fe,_0x367a2c['rerank']),_0x22e22c=_0x1bb8f8[_0x5c4ba3(0x12a)]((_0x1b62d5,_0x54948d)=>({..._0x1b62d5,'original_index':_0x54948d}));_0x366048=_0x22e22c[_0x5c4ba3(0x12a)](_0xc60158=>{const _0x4e4bd1=_0x5c4ba3,_0x4394eb=_0x568f72[_0x4e4bd1(0xf9)]['find'](_0x4a3ac2=>_0x4a3ac2[_0x4e4bd1(0x166)]===_0xc60158[_0x4e4bd1(0x123)]),_0x566334=_0x4394eb?_0x4394eb[_0x4e4bd1(0xc5)]:0x0;return{..._0xc60158,'rerank_score':_0x566334};});if(_0x367a2c[_0x5c4ba3(0x105)]['notify'])showNotification(_0x5c4ba3(0xed),_0x5c4ba3(0x13a));}catch(_0x5d14cd){console[_0x5c4ba3(0xd2)]('[翰林院-Rerank]\x20外部Rerank失败,将仅使用内部加权。',_0x5d14cd);if(_0x367a2c[_0x5c4ba3(0x105)][_0x5c4ba3(0x17f)])showNotification(_0x5c4ba3(0x195)+_0x5d14cd[_0x5c4ba3(0x164)],_0x5c4ba3(0xd2));_0x366048[_0x5c4ba3(0xe9)](_0xa0a9ab=>_0xa0a9ab[_0x5c4ba3(0x134)]=0x0);}}else _0x366048[_0x5c4ba3(0xe9)](_0x56d4d8=>_0x56d4d8[_0x5c4ba3(0x134)]=0x0);console[_0x5c4ba3(0xc7)](_0x5c4ba3(0x130));const _0x12625f=context[_0x5c4ba3(0x114)][_0x5c4ba3(0x18a)],_0x2fdbd6=_0x367a2c[_0x5c4ba3(0x105)][_0x5c4ba3(0x183)],_0xdfd49f=_0x366048['map'](_0x3dd8a7=>{const _0x1e3204=_0x5c4ba3;let _0xaed473=0x1;const _0x9cf7e4=_0x3dd8a7['metadata']||{};switch(_0x9cf7e4['source']){case'lorebook':_0xaed473*=1.2;break;case _0x1e3204(0x15c):_0xaed473*=1.1;break;case _0x1e3204(0xe0):if(_0x9cf7e4[_0x1e3204(0x16e)]&&_0x12625f>0x0){const _0x227605=_0x9cf7e4[_0x1e3204(0x16e)]/_0x12625f;_0xaed473*=0x1+_0x227605;}break;}const _0x457dce=_0x3dd8a7[_0x1e3204(0x134)]*_0x2fdbd6+(_0x3dd8a7[_0x1e3204(0x143)]||0x0)*(0x1-_0x2fdbd6),_0xe34333=_0x457dce*_0xaed473;return{..._0x3dd8a7,'final_score':_0xe34333};});return _0xdfd49f[_0x5c4ba3(0x192)]((_0x53ce89,_0x4ffa61)=>(_0x4ffa61[_0x5c4ba3(0x174)]||0x0)-(_0x53ce89[_0x5c4ba3(0x174)]||0x0)),console['log'](_0x5c4ba3(0x137)),_0xdfd49f[_0x5c4ba3(0x161)](0x0,_0x367a2c[_0x5c4ba3(0x105)][_0x5c4ba3(0x11c)]);}async function rearrangeChat(_0x54b974,_0x416e8a,_0x1aa7b5,_0x125b02){const _0x2cc4f6=_0x177034;setExtensionPrompt(_0x2cc4f6(0x176),'',settings[_0x2cc4f6(0x197)][_0x2cc4f6(0x116)],settings['injection'][_0x2cc4f6(0x1a0)],![],settings[_0x2cc4f6(0x197)][_0x2cc4f6(0x14b)]);if(_0x125b02===_0x2cc4f6(0x175)||!settings[_0x2cc4f6(0x113)]['enabled'])return;const _0x58f34b=_0x54b974[_0x2cc4f6(0x161)](-settings['advanced'][_0x2cc4f6(0x12d)]);if(_0x58f34b[_0x2cc4f6(0x18a)]===0x0)return;const _0x429ead=_0x58f34b[_0x2cc4f6(0x12a)](_0x6781f9=>_0x6781f9['mes'])[_0x2cc4f6(0x142)]('\x20')['replace'](/<[^>]*>/g,'')[_0x2cc4f6(0x159)]();if(!_0x429ead)return;try{const _0x35316a=await queryVectors(_0x429ead);if(_0x35316a[_0x2cc4f6(0x18a)]===0x0)return;const _0x45deea=await rerankResults(_0x35316a,_0x429ead,settings);if(_0x45deea[_0x2cc4f6(0x18a)]===0x0)return;const _0x22a8ed=_0x45deea['map'](_0x3c9e12=>_0x3c9e12[_0x2cc4f6(0xf2)])[_0x2cc4f6(0x142)]('\x0a\x0a');let _0x4cefe5=settings[_0x2cc4f6(0x197)]['template'][_0x2cc4f6(0xe1)](_0x2cc4f6(0x139),_0x22a8ed);_0x4cefe5[_0x2cc4f6(0x159)]()&&(_0x4cefe5=_0x2cc4f6(0x19e)+_0x4cefe5),setExtensionPrompt(_0x2cc4f6(0x176),_0x4cefe5,settings[_0x2cc4f6(0x197)][_0x2cc4f6(0x116)],settings['injection'][_0x2cc4f6(0x1a0)],![],settings[_0x2cc4f6(0x197)][_0x2cc4f6(0x14b)]);}catch(_0x13c3e1){console[_0x2cc4f6(0xd2)](_0x2cc4f6(0xf6),_0x13c3e1);if(settings[_0x2cc4f6(0x113)]['notify'])showNotification(_0x2cc4f6(0xdf)+_0x13c3e1[_0x2cc4f6(0x164)],'error');}}