'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));}}