From e8046b746ccdc1c22bec5cbcb9e0e0e798d70e63 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Wed, 13 Aug 2025 09:31:06 +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 f66b36e..0481088 100644 --- a/core/rag-processor.js +++ b/core/rag-processor.js @@ -1 +1 @@ -'use strict';const _0x526041=_0x1970;(function(_0x51e69b,_0xf12783){const _0x54e13c=_0x1970,_0x1f3ffc=_0x51e69b();while(!![]){try{const _0x1783f8=-parseInt(_0x54e13c(0x1f1))/0x1+-parseInt(_0x54e13c(0x227))/0x2+parseInt(_0x54e13c(0x1d0))/0x3+-parseInt(_0x54e13c(0x1ee))/0x4*(parseInt(_0x54e13c(0x163))/0x5)+parseInt(_0x54e13c(0x1ed))/0x6+-parseInt(_0x54e13c(0x205))/0x7+-parseInt(_0x54e13c(0x1c2))/0x8*(-parseInt(_0x54e13c(0x1ae))/0x9);if(_0x1783f8===_0xf12783)break;else _0x1f3ffc['push'](_0x1f3ffc['shift']());}catch(_0x44ff37){_0x1f3ffc['push'](_0x1f3ffc['shift']());}}}(_0x4ceb,0x24596));import{extension_prompt_roles,setExtensionPrompt}from'/script.js';import*as _0x2504aa from'./utils/context-utils.js';import{getCollectionIdInfo}from'./utils/context-utils.js';import{defaultSettings as _0x5a4c82}from'./rag-settings.js';import*as _0x56d88c from'./ingestion-manager.js';const MODULE_NAME='hanlinyuan-rag-core',OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME=_0x526041(0x190);let context=null,settings=null,lockedCollectionId=null;export{initialize,getSettings,saveSettings,resetSettings,testApiConnection,fetchEmbeddingModels,fetchRerankModels,getVectorCount,purgeStorage,getMessagesForCondensation,processCondensation,ingestTextToHanlinyuan,getCollectionId,toggleSessionLock,isSessionLocked,getLockedSessionInfo};function initialize(){const _0x4c1b12=_0x526041;context=SillyTavern['getContext']();if(!context){console[_0x4c1b12(0x1cf)](_0x4c1b12(0x210));return;}settings=getSettings();const _0x274c67=window[OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME];typeof _0x274c67===_0x4c1b12(0x216)?(window[OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME]=async function(..._0x400645){await rearrangeChat(..._0x400645),await _0x274c67(..._0x400645);},console[_0x4c1b12(0x1e2)]('翰林院忆识核心已启动\x20(V5.1-和平共存版),已代理\x20'+OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME)):(window[OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME]=rearrangeChat,console[_0x4c1b12(0x1e2)]('翰林院忆识核心已启动\x20(V5.1-借壳上市版),已注册全局函数:\x20'+OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME));}async function ingestTextToHanlinyuan(_0x3f9c3e,_0x8fa57c=_0x526041(0x18c),_0x78efb4='',_0x44ec6c=()=>{},_0x39cc80=null,_0x41bf64=()=>{},_0x192890=()=>{},_0x58d5fb=null,_0x5ada64=0x0,_0x3784de=null){const _0x19e2f2=_0x526041;if(!_0x3f9c3e||!_0x3f9c3e[_0x19e2f2(0x1f6)]())return{'success':![],'error':_0x19e2f2(0x1b3)};if(!settings)return{'success':![],'error':_0x19e2f2(0x223)};try{let _0x469468=await getCollectionId();const _0x5f36a3=getCollectionIdInfo();if(_0x5f36a3['oldId']&&_0x5f36a3['oldId']===_0x469468&&_0x5f36a3['oldId']!==_0x5f36a3[_0x19e2f2(0x1bc)]){const _0x4898dc=confirm('此操作将清空旧版数据,并开始使用新版数据库。此过程不可逆,是否继续?');if(_0x4898dc)_0x41bf64(_0x19e2f2(0x1cd)+_0x5f36a3[_0x19e2f2(0x196)],_0x19e2f2(0x1ba)),await purgeStorage(_0x5f36a3[_0x19e2f2(0x196)]),_0x469468=_0x5f36a3['newId'],_0x41bf64('[翰林院-迁移]\x20旧宝库已清空,将向新宝库写入数据:\x20'+_0x469468,_0x19e2f2(0x174));else return _0x41bf64('[翰林院-迁移]\x20用户取消了迁移操作。',_0x19e2f2(0x1ab)),toastr['info'](_0x19e2f2(0x1b6)),{'success':![],'error':_0x19e2f2(0x1e3)};}if(!_0x469468)throw new Error('无法确定当前忆识宝库的ID,请确认角色已正确加载。');_0x41bf64(_0x19e2f2(0x1b0)+_0x469468,_0x19e2f2(0x1ab)),_0x44ec6c({'message':_0x19e2f2(0x209),'processed':0x0,'total':0x1});const _0x486a2d=splitIntoChunks(_0x3f9c3e,_0x8fa57c,{'sourceName':_0x78efb4}),_0x4b43e7=_0x486a2d[_0x19e2f2(0x21e)];if(_0x39cc80?.[_0x19e2f2(0x1c0)])throw new Error(_0x19e2f2(0x1a4));_0x41bf64('[翰林院-核心]\x20将来源\x27'+(_0x78efb4||_0x8fa57c)+_0x19e2f2(0x183)+_0x4b43e7+_0x19e2f2(0x21f),'info');if(_0x4b43e7===0x0)return{'success':!![],'count':0x0};const _0x44a451=settings[_0x19e2f2(0x161)][_0x19e2f2(0x1be)]||0x5;let _0x3792d6=_0x5ada64;for(let _0x2989eb=_0x5ada64;_0x2989eb<_0x4b43e7;_0x2989eb+=_0x44a451){if(_0x39cc80?.[_0x19e2f2(0x1c0)])throw new Error(_0x19e2f2(0x1a4));const _0x3cd83a=_0x486a2d[_0x19e2f2(0x212)](_0x2989eb,_0x2989eb+_0x44a451);_0x44ec6c({'message':'正在处理\x20'+(_0x2989eb+0x1)+'-'+(_0x2989eb+_0x3cd83a[_0x19e2f2(0x21e)])+'\x20块','processed':_0x2989eb,'total':_0x4b43e7});const _0x44635d=_0x3cd83a[_0x19e2f2(0x1da)](_0x45f97d=>_0x45f97d[_0x19e2f2(0x1b7)]),_0xbd2418=await getEmbeddings(_0x44635d,_0x39cc80);if(_0x39cc80?.['aborted'])throw new Error(_0x19e2f2(0x1a4));if(_0x3cd83a[_0x19e2f2(0x21e)]!==_0xbd2418[_0x19e2f2(0x21e)])throw new Error(_0x19e2f2(0x1c7));const _0x9393f1=_0x3cd83a['map']((_0x183122,_0x51f965)=>({..._0x183122,'vector':_0xbd2418[_0x51f965]}));await insertVectors(_0x9393f1,_0x39cc80,_0x469468),_0x3792d6+=_0x3cd83a[_0x19e2f2(0x21e)],_0x58d5fb&&_0x56d88c[_0x19e2f2(0x203)](_0x58d5fb,_0x3792d6,_0x4b43e7),_0x192890();}_0x58d5fb&&_0x56d88c[_0x19e2f2(0x180)](_0x58d5fb);if(_0x3784de){const _0x46caa5=await getCollectionId(),_0x3fbeff=_0x3784de[_0x19e2f2(0x201)]===0x0?context['chat']['length']:_0x3784de[_0x19e2f2(0x201)];settings[_0x19e2f2(0x1b5)][_0x46caa5]={'start':_0x3784de[_0x19e2f2(0x204)],'end':_0x3fbeff,'timestamp':new Date()['toISOString']()},saveSettings(),_0x41bf64(_0x19e2f2(0x1b2)+_0x46caa5+_0x19e2f2(0x1b4)+_0x3784de[_0x19e2f2(0x204)]+'-'+_0x3fbeff,_0x19e2f2(0x1ab));}return _0x41bf64(_0x19e2f2(0x17d)+_0x3792d6+_0x19e2f2(0x20d),_0x19e2f2(0x174)),{'success':!![],'count':_0x3792d6};}catch(_0x18429b){if(_0x18429b[_0x19e2f2(0x170)]==='AbortError'){_0x41bf64(_0x19e2f2(0x168),_0x19e2f2(0x1ba));throw _0x18429b;}return console[_0x19e2f2(0x1cf)]('[翰林院-核心]\x20ingestTextToHanlinyuan\x20失败:',_0x18429b),_0x41bf64(_0x19e2f2(0x18a)+_0x18429b[_0x19e2f2(0x167)],_0x19e2f2(0x1cf)),{'success':![],'error':_0x18429b[_0x19e2f2(0x167)]};}}function _0x1970(_0x3344f7,_0x5a0908){const _0x4ceb23=_0x4ceb();return _0x1970=function(_0x1970fd,_0x92c403){_0x1970fd=_0x1970fd-0x160;let _0x596d6a=_0x4ceb23[_0x1970fd];return _0x596d6a;},_0x1970(_0x3344f7,_0x5a0908);}function getSettings(){const _0x11b61e=_0x526041;if(!context||!context[_0x11b61e(0x1a5)])return structuredClone(_0x5a4c82);let _0x2eaaf9=context[_0x11b61e(0x1a5)][MODULE_NAME];!_0x2eaaf9&&(_0x2eaaf9={},context[_0x11b61e(0x1a5)][MODULE_NAME]=_0x2eaaf9);_0x2eaaf9[_0x11b61e(0x1b5)]===undefined&&(_0x2eaaf9[_0x11b61e(0x1b5)]={});for(const _0xd70888 in _0x5a4c82){if(_0x2eaaf9[_0xd70888]===undefined)_0x2eaaf9[_0xd70888]=structuredClone(_0x5a4c82[_0xd70888]);else{if(typeof _0x5a4c82[_0xd70888]===_0x11b61e(0x16f)&&!Array[_0x11b61e(0x1e8)](_0x5a4c82[_0xd70888])&&_0x5a4c82[_0xd70888]!==null)for(const _0x346a41 in _0x5a4c82[_0xd70888]){_0x2eaaf9[_0xd70888][_0x346a41]===undefined&&(_0x2eaaf9[_0xd70888][_0x346a41]=_0x5a4c82[_0xd70888][_0x346a41]);}}}return _0x2eaaf9;}function saveSettings(){const _0x3c31af=_0x526041;if(context)context[_0x3c31af(0x200)]();}function resetSettings(){const _0x2474d6=_0x526041;context&&(context[_0x2474d6(0x1a5)][MODULE_NAME]=structuredClone(_0x5a4c82),saveSettings());}function showNotification(_0x13fac3,_0x5791ea=_0x526041(0x1ab)){toastr[_0x5791ea](_0x13fac3);}function getTagForSource(_0xba4291){const _0x1341d1=_0x526041;switch(_0xba4291){case _0x1341d1(0x1de):return _0x1341d1(0x1a9);case _0x1341d1(0x1d3):return _0x1341d1(0x19c);case _0x1341d1(0x18c):return _0x1341d1(0x228);case _0x1341d1(0x1a1):return _0x1341d1(0x1d7);default:return'资料';}}function splitIntoChunks(_0x5ad0f2,_0x504b24,_0x3c71b1={}){const _0x30998b=_0x526041;switch(_0x504b24){case _0x30998b(0x1a1):return _chunkForNovel(_0x5ad0f2,_0x3c71b1);case _0x30998b(0x1de):return _chunkForChatHistory(_0x5ad0f2,_0x3c71b1);case _0x30998b(0x1d3):return _chunkForLorebook(_0x5ad0f2,_0x3c71b1);case _0x30998b(0x18c):return _chunkForManual(_0x5ad0f2,_0x3c71b1);default:console[_0x30998b(0x1ba)](_0x30998b(0x18e)+_0x504b24+'\x27,使用通用分块逻辑。');return _chunkForManual(_0x5ad0f2,{..._0x3c71b1,'sourceName':_0x3c71b1['sourceName']||_0x30998b(0x1bf)});}}function _chunkForNovel(_0x5b9c6c,_0x247d7b){const _0x52e2e7=_0x526041,{chunkSize:_0x52c945,overlap:_0x380466}=settings['advanced'],{sourceName:sourceName='小说'}=_0x247d7b,_0x554991=[];if(!_0x5b9c6c||_0x52c945<=0x0)return _0x554991;const _0x473ed5=/(第\s*[一二三四五六七八九十百千万零\d]+\s*卷)/gim,_0x1de209=/(第\s*[一二三四五六七八九十百千万零\d]+\s*[章回节部])|^(Chapter\s+\d+)/gim;let _0x326f7e=0x0;const _0x4e6981=_0x5b9c6c[_0x52e2e7(0x1dc)]('\x0a');let _0x145ec4=_0x52e2e7(0x1aa),_0x54d59d='第1章',_0x3bb213=[];function _0x425c4d(){const _0x26b17f=_0x52e2e7;if(_0x3bb213[_0x26b17f(0x21e)]===0x0)return;const _0x507960=_0x3bb213[_0x26b17f(0x1a7)]('\x0a');let _0x2e3a8c=0x0,_0x24e137=0x1;while(_0x2e3a8c<_0x507960[_0x26b17f(0x21e)]){const _0x26447d=Math[_0x26b17f(0x1a8)](_0x2e3a8c+_0x52c945,_0x507960['length']),_0x1d127a=_0x507960[_0x26b17f(0x21c)](_0x2e3a8c,_0x26447d);if(_0x1d127a['trim']()[_0x26b17f(0x21e)]>0x0){const _0x51ef90={'source':_0x26b17f(0x1a1),'sourceName':sourceName,'timestamp':new Date()[_0x26b17f(0x199)](),'globalIndex':_0x326f7e++,'volume':_0x145ec4,'chapter':_0x54d59d,'section':_0x24e137},_0x18766c=getTagForSource(_0x26b17f(0x1a1)),_0x36a9d8=_0x26b17f(0x213)+sourceName+',\x20'+_0x145ec4+',\x20'+_0x54d59d+_0x26b17f(0x202)+_0x24e137+'节]',_0x461c7c='<'+_0x18766c+'>\x0a'+_0x36a9d8+'\x0a'+_0x1d127a+'\x0a';_0x554991['push']({'text':_0x461c7c,'metadata':_0x51ef90}),_0x24e137++;}_0x2e3a8c+=_0x52c945-_0x380466;if(_0x2e3a8c>=_0x507960[_0x26b17f(0x21e)])break;}_0x3bb213=[];}for(const _0x576773 of _0x4e6981){const _0x547ced=_0x576773['trim']();if(_0x473ed5[_0x52e2e7(0x1bd)](_0x547ced))_0x425c4d(),_0x145ec4=_0x547ced,_0x54d59d='第1章';else _0x1de209['test'](_0x547ced)?(_0x425c4d(),_0x54d59d=_0x547ced):_0x3bb213['push'](_0x576773);}_0x425c4d();if(_0x554991['length']===0x0&&_0x5b9c6c['length']>0x0){let _0x3998f1=0x0,_0x3612df=0x1;while(_0x3998f1<_0x5b9c6c[_0x52e2e7(0x21e)]){const _0x1f5e2c=Math['min'](_0x3998f1+_0x52c945,_0x5b9c6c[_0x52e2e7(0x21e)]),_0x48025f=_0x5b9c6c[_0x52e2e7(0x21c)](_0x3998f1,_0x1f5e2c),_0x45525c={'source':'novel','sourceName':sourceName,'timestamp':new Date()[_0x52e2e7(0x199)](),'globalIndex':_0x554991[_0x52e2e7(0x21e)],'volume':_0x52e2e7(0x1aa),'chapter':_0x52e2e7(0x224),'section':_0x3612df},_0x3692d8=getTagForSource(_0x52e2e7(0x1a1)),_0x426405=_0x52e2e7(0x213)+sourceName+_0x52e2e7(0x222)+_0x3612df+'节]',_0x3da4e4='<'+_0x3692d8+'>\x0a'+_0x426405+'\x0a'+_0x48025f+'\x0a';_0x554991[_0x52e2e7(0x184)]({'text':_0x3da4e4,'metadata':_0x45525c}),_0x3612df++,_0x3998f1+=_0x52c945-_0x380466;}}return _0x554991;}function _chunkForChatHistory(_0x5369d3,_0x5e684f){const _0x3725dd=_0x526041,{chunkSize:_0xccdae5,overlap:_0x370130}=settings['advanced'],{floor:_0x56f416,is_user:_0x3f16bd,timestamp:_0x561c8a}=_0x5e684f,_0x35f679=[];if(!_0x5369d3||_0xccdae5<=0x0)return _0x35f679;let _0x37ec93=0x1,_0x4386fb=0x0;while(_0x4386fb<_0x5369d3[_0x3725dd(0x21e)]){const _0x23df3b=Math[_0x3725dd(0x1a8)](_0x4386fb+_0xccdae5,_0x5369d3['length']),_0x5d8146=_0x5369d3[_0x3725dd(0x21c)](_0x4386fb,_0x23df3b),_0x4a2073='[来源:\x20聊天记录,\x20楼层:\x20#'+_0x56f416+_0x3725dd(0x202)+_0x37ec93+_0x3725dd(0x187),_0x407282=getTagForSource(_0x3725dd(0x1de)),_0x42e979='<'+_0x407282+'>\x0a'+_0x4a2073+'\x0a'+_0x5d8146+_0x3725dd(0x20a)+_0x407282+'>';_0x35f679[_0x3725dd(0x184)]({'text':_0x42e979,'metadata':{'source':_0x3725dd(0x1de),'sourceName':_0x3725dd(0x16c)+_0x56f416,'floor':_0x56f416,'part':_0x37ec93,'is_user':_0x3f16bd,'timestamp':_0x561c8a}}),_0x37ec93++,_0x4386fb+=_0xccdae5-_0x370130;if(_0x4386fb>=_0x5369d3[_0x3725dd(0x21e)])break;}return _0x35f679;}function _chunkForLorebook(_0x4dd0d9,_0x39a4df){const _0x3bb852=_0x526041,{chunkSize:_0x334e0f,overlap:_0x28bc58}=settings[_0x3bb852(0x211)],{sourceName:sourceName='世界书条目'}=_0x39a4df,_0x32d7a2=[];if(!_0x4dd0d9||_0x334e0f<=0x0)return _0x32d7a2;let _0x2b45cd=0x1,_0x343e26=0x0;while(_0x343e26<_0x4dd0d9[_0x3bb852(0x21e)]){const _0x40d962=Math['min'](_0x343e26+_0x334e0f,_0x4dd0d9[_0x3bb852(0x21e)]),_0x47f0d8=_0x4dd0d9['substring'](_0x343e26,_0x40d962),_0x30c1c6='[来源:\x20世界书,\x20条目:\x20'+sourceName+',\x20第'+_0x2b45cd+_0x3bb852(0x187),_0x8a58c3=getTagForSource('lorebook'),_0x87dd9e='<'+_0x8a58c3+'>\x0a'+_0x30c1c6+'\x0a'+_0x47f0d8+'\x0a';_0x32d7a2[_0x3bb852(0x184)]({'text':_0x87dd9e,'metadata':{'source':_0x3bb852(0x1d3),'sourceName':sourceName,'part':_0x2b45cd,'timestamp':new Date()[_0x3bb852(0x199)]()}}),_0x2b45cd++,_0x343e26+=_0x334e0f-_0x28bc58;if(_0x343e26>=_0x4dd0d9[_0x3bb852(0x21e)])break;}return _0x32d7a2;}function _chunkForManual(_0x3657f6,_0x34301d){const _0x4c77d0=_0x526041,{chunkSize:_0x377a50,overlap:_0xb54eb7}=settings['advanced'],{sourceName:sourceName='手动录入'}=_0x34301d,_0x5767a8=[];if(!_0x3657f6||_0x377a50<=0x0)return _0x5767a8;const _0x32311a=new Date(),_0x150ea4=_0x32311a['toLocaleString']('zh-CN');let _0x148be4=0x1,_0x398a00=0x0;while(_0x398a00<_0x3657f6['length']){const _0x23b378=Math[_0x4c77d0(0x1a8)](_0x398a00+_0x377a50,_0x3657f6[_0x4c77d0(0x21e)]),_0xa0e66d=_0x3657f6[_0x4c77d0(0x21c)](_0x398a00,_0x23b378),_0x1d80a9=_0x4c77d0(0x213)+sourceName+_0x4c77d0(0x20e)+_0x150ea4+',\x20第'+_0x148be4+_0x4c77d0(0x187),_0x3fe900=getTagForSource(_0x4c77d0(0x18c)),_0x3f9fa7='<'+_0x3fe900+'>\x0a'+_0x1d80a9+'\x0a'+_0xa0e66d+'\x0a';_0x5767a8[_0x4c77d0(0x184)]({'text':_0x3f9fa7,'metadata':{'source':_0x4c77d0(0x18c),'sourceName':sourceName,'part':_0x148be4,'timestamp':_0x32311a['toISOString']()}}),_0x148be4++,_0x398a00+=_0x377a50-_0xb54eb7;if(_0x398a00>=_0x3657f6[_0x4c77d0(0x21e)])break;}return _0x5767a8;}import{getCollectionId as _0xcebab3,getCharacterName}from'./utils/context-utils.js';async function getCollectionId(){return lockedCollectionId||await _0xcebab3();}async function toggleSessionLock(){return lockedCollectionId?(lockedCollectionId=null,![]):(lockedCollectionId=await _0xcebab3(),!![]);}function isSessionLocked(){return lockedCollectionId!==null;}function getLockedSessionInfo(){const _0x55e28d=_0x526041;if(!lockedCollectionId)return null;return{'id':lockedCollectionId,'name':_0x55e28d(0x1e0)+lockedCollectionId['substring'](0x0,0x8)+_0x55e28d(0x19d)};}function generateHash(_0x26f971){const _0x5bb3aa=_0x526041;let _0x327ef7=0x0;for(let _0x19b00b=0x0;_0x19b00b<_0x26f971[_0x5bb3aa(0x21e)];_0x19b00b++){const _0x384ba7=_0x26f971['charCodeAt'](_0x19b00b);_0x327ef7=(_0x327ef7<<0x5)-_0x327ef7+_0x384ba7,_0x327ef7=_0x327ef7&_0x327ef7;}return Math['abs'](_0x327ef7)[_0x5bb3aa(0x194)](0x24);}function getSanitizedBaseUrl(_0x5dbfa4){const _0x442ae0=_0x526041;let _0x576ba4=_0x5dbfa4[_0x442ae0(0x1f6)]();return _0x576ba4[_0x442ae0(0x17a)]('/')&&(_0x576ba4=_0x576ba4[_0x442ae0(0x212)](0x0,-0x1)),_0x576ba4[_0x442ae0(0x17a)](_0x442ae0(0x188))&&(_0x576ba4=_0x576ba4[_0x442ae0(0x212)](0x0,-0x3)),_0x576ba4[_0x442ae0(0x17a)](_0x442ae0(0x208))&&(_0x576ba4=_0x576ba4['slice'](0x0,-0xb)),_0x576ba4;}function _0x4ceb(){const _0x12ef69=['oldId','model','unknown','toISOString','url','/api/vector/query','世界书','...)','getRequestHeaders','无法确定当前忆识宝库的ID,请确认角色已正确加载。','宝库查询API错误\x20','novel','[翰林院-日志]\x20统计目标集合ID:\x20','外部Rerank完成','AbortError','extensionSettings','send_date','join','min','聊天记录','第1卷','info','condensation','/api/vector/list','182961khxbms','\x20个条目。','[翰林院-核心]\x20已锁定忆识宝库ID:\x20','https://api.openai.com','[翰林院-核心]\x20已为宝库\x20','输入文本为空','\x20记录凝识范围:\x20','condensationHistory','操作已取消。','text','data','json','warn','\x20-\x20楼层\x20#','newId','test','batchSize','未知来源','aborted','application/json','232hHefGP','source','index','webllm','[翰林院-日志]\x20/api/vector/query\x20响应状态:\x20','文本块和向量数量不匹配','filter','max','[翰林院-日志]\x20/api/vector/list\x20响应状态:\x20','depth','[翰林院-日志]\x20/api/vector/purge\x20响应状态:\x20','[翰林院-迁移]\x20用户确认迁移,正在清空旧宝库:\x20','\x20条消息分解为\x20','error','440658xKQGTg','rerank','/rerank','lorebook','messageTypes','\x20条结果。','user','小说录入','[翰林院]\x20检索或注入时发生错误:','GET','map','[翰林院-核心]\x20聊天记录凝识失败:\x20','split','floor','chat_history','[翰林院-Rerank]\x20正在从\x20','(已锁定:\x20','api-key','log','用户取消了迁移操作','):\x20','API\x20URL\x20或\x20Key\x20未提供。','[翰林院-Rerank]\x20开始外部API重排序...','forEach','isArray','mes','embeddingModel','sort','now','180492iHusqV','292qSwKvJ','Rerank模型API的响应格式无效:\x20未找到\x20\x27data\x27\x20数组。','Rerank失败:\x20','139130TpovqH','[翰林院-日志]\x20查询成功,返回\x20','hashes','[翰林院-日志]\x20获取向量列表API错误:','getTime','trim','metadata','[翰林院-迁移]\x20旧宝库已清空,将向新宝库写入数据:\x20','status','神力获取失败\x20','findIndex','Rerank\x20API\x20URL\x20或\x20Key\x20未提供。','\x20获取模型列表...','replace','position','saveSettingsDebounced','end',',\x20第','saveProgress','start','960190nnFgzM','template','results','/embeddings','正在智能分块...','\x0a_0x58be67['id'])[_0x169165(0x1eb)]();}function getRerankBaseUrl(_0x431a33){const _0x55aada=_0x526041;let _0x5557df=_0x431a33['trim']();return _0x5557df[_0x55aada(0x17a)]('/')&&(_0x5557df=_0x5557df[_0x55aada(0x212)](0x0,-0x1)),_0x5557df[_0x55aada(0x17a)]('/v1')&&(_0x5557df=_0x5557df[_0x55aada(0x212)](0x0,-0x3)),_0x5557df[_0x55aada(0x17a)](_0x55aada(0x1d2))&&(_0x5557df=_0x5557df['slice'](0x0,-0x7)),_0x5557df;}async function fetchRerankModels(){const _0x5e7424=_0x526041,{url:_0x4a1725,apiKey:_0x316f5c}=settings[_0x5e7424(0x1d1)];if(!_0x4a1725||!_0x316f5c)throw new Error(_0x5e7424(0x1fc));const _0x3b930b=getRerankBaseUrl(_0x4a1725),_0x32f52c=_0x3b930b+_0x5e7424(0x191);console[_0x5e7424(0x1e2)](_0x5e7424(0x1df)+_0x32f52c+_0x5e7424(0x1fd));const _0x3fdc1b=await fetch(_0x32f52c,{'method':_0x5e7424(0x1d9),'headers':{'Authorization':_0x5e7424(0x185)+_0x316f5c}});if(!_0x3fdc1b['ok']){const _0x58fd80=await _0x3fdc1b['text']();throw new Error('获取Rerank模型列表失败\x20('+_0x3fdc1b[_0x5e7424(0x1f9)]+_0x5e7424(0x1e4)+_0x58fd80);}const _0x3c78b7=await _0x3fdc1b[_0x5e7424(0x1b9)]();if(!_0x3c78b7['data']||!Array[_0x5e7424(0x1e8)](_0x3c78b7[_0x5e7424(0x1b8)]))throw new Error(_0x5e7424(0x1ef));return _0x3c78b7[_0x5e7424(0x1b8)][_0x5e7424(0x1da)](_0x33ec3f=>_0x33ec3f['id'])[_0x5e7424(0x1eb)]();}function getApiEndpointUrl(_0x242de5=![]){const _0x24ea16=_0x526041,{apiEndpoint:_0x184717,customApiUrl:_0x89a3a1}=settings[_0x24ea16(0x161)];let _0x40b264;switch(_0x184717){case'openai':_0x40b264=_0x24ea16(0x1b1);break;case _0x24ea16(0x225):case _0x24ea16(0x165):_0x40b264=_0x89a3a1;break;default:_0x40b264='https://api.openai.com';break;}if(_0x242de5)return _0x40b264;return getSanitizedBaseUrl(_0x40b264)+_0x24ea16(0x17e);}function getApiHeaders(){const _0x509ddf=_0x526041,_0x3ad74c={'Content-Type':_0x509ddf(0x1c1)},{apiKey:_0x3b94b3,apiEndpoint:_0x4a4871}=settings[_0x509ddf(0x161)];switch(_0x4a4871){case'openai':case _0x509ddf(0x165):_0x3ad74c[_0x509ddf(0x16d)]=_0x509ddf(0x185)+_0x3b94b3;break;case _0x509ddf(0x225):_0x3ad74c[_0x509ddf(0x1e1)]=_0x3b94b3;break;}return _0x3ad74c;}async function getEmbeddings(_0xa75b90,_0x31a90a=null){const _0x390a6e=_0x526041;if(!settings[_0x390a6e(0x161)]['apiKey'])throw new Error('请先配置API\x20Key');const _0x1ce9ca=getApiEndpointUrl(),_0xf7deb8=getApiHeaders(),_0x36fa81=settings[_0x390a6e(0x161)][_0x390a6e(0x1ea)],_0x2070c8=settings['retrieval'][_0x390a6e(0x1be)]||0x5,_0x322d4c=[];for(let _0x4c35d4=0x0;_0x4c35d4<_0xa75b90[_0x390a6e(0x21e)];_0x4c35d4+=_0x2070c8){if(_0x31a90a?.[_0x390a6e(0x1c0)])throw new Error(_0x390a6e(0x1a4));const _0x39fec0=_0xa75b90[_0x390a6e(0x212)](_0x4c35d4,_0x4c35d4+_0x2070c8),_0x5b3fb7=await fetch(_0x1ce9ca,{'method':_0x390a6e(0x175),'headers':_0xf7deb8,'body':JSON[_0x390a6e(0x18f)]({'input':_0x39fec0,'model':_0x36fa81}),'signal':_0x31a90a});if(!_0x5b3fb7['ok']){const _0x20015b=await _0x5b3fb7[_0x390a6e(0x1b7)]();throw new Error(_0x390a6e(0x1fa)+_0x5b3fb7[_0x390a6e(0x1f9)]+':\x20'+_0x20015b);}const _0x43b08d=await _0x5b3fb7[_0x390a6e(0x1b9)]();_0x322d4c[_0x390a6e(0x184)](..._0x43b08d[_0x390a6e(0x1b8)][_0x390a6e(0x1da)](_0x4c394d=>_0x4c394d[_0x390a6e(0x186)])),_0x4c35d4+_0x2070c8<_0xa75b90[_0x390a6e(0x21e)]&&await new Promise(_0x2d8c41=>setTimeout(_0x2d8c41,0xc8));}return _0x322d4c;}async function queryVectors(_0x4a39e0){const _0x18fc11=_0x526041;console[_0x18fc11(0x1e2)](_0x18fc11(0x181));const _0x565c7a=await getCollectionId();console['log']('[翰林院-日志]\x20查询目标集合ID:\x20'+_0x565c7a);const _0x9f8d94=(await getEmbeddings([_0x4a39e0]))[0x0],_0x56f7ee={'collectionId':_0x565c7a,'searchText':_0x4a39e0,'topK':settings[_0x18fc11(0x211)][_0x18fc11(0x162)],'threshold':settings[_0x18fc11(0x211)][_0x18fc11(0x171)],'source':_0x18fc11(0x1c5),'embeddings':{[_0x4a39e0]:_0x9f8d94}};console[_0x18fc11(0x1e2)](_0x18fc11(0x172),JSON[_0x18fc11(0x18f)](_0x56f7ee,null,0x2));const _0x2d1366=await fetch(_0x18fc11(0x19b),{'method':_0x18fc11(0x175),'headers':context[_0x18fc11(0x19e)](),'body':JSON[_0x18fc11(0x18f)](_0x56f7ee)});console[_0x18fc11(0x1e2)](_0x18fc11(0x1c6)+_0x2d1366[_0x18fc11(0x1f9)]);if(!_0x2d1366['ok']){const _0x2d130b=await _0x2d1366['text']();console[_0x18fc11(0x1cf)](_0x18fc11(0x20c),_0x2d130b);throw new Error(_0x18fc11(0x1a0)+_0x2d1366[_0x18fc11(0x1f9)]+':\x20'+_0x2d130b);}const _0x2a20fe=await _0x2d1366[_0x18fc11(0x1b9)]();console[_0x18fc11(0x1e2)](_0x18fc11(0x179),_0x2a20fe);const _0x4402f8=_0x2a20fe['metadata']||_0x2a20fe[_0x18fc11(0x207)]||_0x2a20fe[_0x18fc11(0x1b8)]||[];return console[_0x18fc11(0x1e2)](_0x18fc11(0x1f2)+_0x4402f8[_0x18fc11(0x21e)]+_0x18fc11(0x1d5)),_0x4402f8;}async function insertVectors(_0x563d4f,_0x897d0c=null,_0x214fcb){const _0x31a3f9=_0x526041;if(!_0x214fcb){console[_0x31a3f9(0x1cf)]('[翰林院-核心]\x20insertVectors被调用时未提供collectionId!'),_0x214fcb=await getCollectionId();if(!_0x214fcb)throw new Error(_0x31a3f9(0x192));}if(_0x563d4f['length']===0x0)return{'success':!![],'count':0x0};const _0x2aabf7=_0x563d4f[_0x31a3f9(0x1da)]((_0x2ae452,_0x252eb1)=>({'hash':generateHash(_0x2ae452[_0x31a3f9(0x1b7)]+Date[_0x31a3f9(0x1ec)]()+_0x252eb1),'text':_0x2ae452['text'],'metadata':_0x2ae452[_0x31a3f9(0x1f7)]||{'source':_0x31a3f9(0x198),'timestamp':new Date()[_0x31a3f9(0x199)]()}})),_0xe76354=_0x2aabf7['reduce']((_0x5d244c,_0x49a36c,_0x5b1720)=>{return _0x5d244c[_0x49a36c['text']]=_0x563d4f[_0x5b1720]['vector'],_0x5d244c;},{}),_0xd332a0={'collectionId':_0x214fcb,'items':_0x2aabf7,'source':'webllm','embeddings':_0xe76354},_0xa6d459=await fetch(_0x31a3f9(0x189),{'method':'POST','headers':context['getRequestHeaders'](),'body':JSON[_0x31a3f9(0x18f)](_0xd332a0),'signal':_0x897d0c});if(!_0xa6d459['ok']){const _0x3fdfa9=await _0xa6d459[_0x31a3f9(0x1b7)]();console[_0x31a3f9(0x1cf)]('[翰林院-日志]\x20忆识存入API错误:',_0x3fdfa9);throw new Error('忆识存入API错误\x20'+_0xa6d459['status']+':\x20'+_0x3fdfa9);}return{'success':!![],'count':_0x2aabf7['length']};}async function testApiConnection(){await getEmbeddings(['测试连接']);}async function getVectorCount(){const _0x4eda44=_0x526041;console[_0x4eda44(0x1e2)](_0x4eda44(0x22c));const _0x60b970=await getCollectionId();console[_0x4eda44(0x1e2)](_0x4eda44(0x1a2)+_0x60b970);const _0x26de24={'collectionId':_0x60b970,'source':_0x4eda44(0x1c5),'embeddings':{}};console['log']('[翰林院-日志]\x20发送到\x20/api/vector/list\x20的请求体:',JSON[_0x4eda44(0x18f)](_0x26de24,null,0x2));const _0x4ed474=await fetch(_0x4eda44(0x1ad),{'method':_0x4eda44(0x175),'headers':context[_0x4eda44(0x19e)](),'body':JSON[_0x4eda44(0x18f)](_0x26de24)});console[_0x4eda44(0x1e2)](_0x4eda44(0x1ca)+_0x4ed474[_0x4eda44(0x1f9)]);if(!_0x4ed474['ok']){const _0x4503cc=await _0x4ed474[_0x4eda44(0x1b7)]();return console['error'](_0x4eda44(0x1f4),_0x4503cc),0x0;}const _0x102219=await _0x4ed474['json']();let _0x432c62=0x0;if(Array['isArray'](_0x102219))_0x432c62=_0x102219['length'];else _0x102219&&_0x102219[_0x4eda44(0x1f3)]&&(_0x432c62=_0x102219['hashes']['length']);return console['log']('[翰林院-日志]\x20统计成功,向量总数:\x20'+_0x432c62),_0x432c62;}async function purgeStorage(_0x7483a3=null){const _0x32ebdf=_0x526041;console[_0x32ebdf(0x1e2)](_0x32ebdf(0x169));const _0x56a002=_0x7483a3||await getCollectionId();if(!_0x56a002)return console['error']('[翰林院-日志]\x20无法确定要清空的目标集合ID。'),toastr[_0x32ebdf(0x1cf)]('无法确定要清空的目标宝库。'),![];console[_0x32ebdf(0x1e2)](_0x32ebdf(0x20f)+_0x56a002);const _0x8a7aeb={'collectionId':_0x56a002};console['log'](_0x32ebdf(0x178),JSON[_0x32ebdf(0x18f)](_0x8a7aeb,null,0x2));const _0x1e6052=await fetch(_0x32ebdf(0x221),{'method':_0x32ebdf(0x175),'headers':context[_0x32ebdf(0x19e)](),'body':JSON['stringify'](_0x8a7aeb)});console['log'](_0x32ebdf(0x1cc)+_0x1e6052['status']);if(!_0x1e6052['ok']){const _0x8ceac=await _0x1e6052[_0x32ebdf(0x1b7)]();console['error'](_0x32ebdf(0x17b),_0x8ceac);}else console[_0x32ebdf(0x1e2)](_0x32ebdf(0x215));return _0x1e6052['ok'];}function getMessagesForCondensation(_0x8dc88a=null){const _0x26575f=_0x526041;if(!settings[_0x26575f(0x1ac)]['enabled'])return showNotification(_0x26575f(0x193),_0x26575f(0x226)),[];const {layerStart:_0x15f582,layerEnd:_0x29de38}=settings[_0x26575f(0x1ac)],_0x128023=_0x8dc88a||settings[_0x26575f(0x1ac)][_0x26575f(0x1d4)],_0x3ebc6a=context[_0x26575f(0x17c)][_0x26575f(0x21e)],_0x5a1f6c=Math[_0x26575f(0x1c9)](0x0,_0x15f582-0x1),_0x48bf0f=_0x29de38===0x0||_0x29de38>_0x3ebc6a?_0x3ebc6a:Math[_0x26575f(0x1a8)](_0x3ebc6a,_0x29de38),_0x3dd6aa=context[_0x26575f(0x17c)]['slice'](_0x5a1f6c,_0x48bf0f);return _0x3dd6aa[_0x26575f(0x1c8)](_0x1cd6df=>{const _0x320d2c=_0x26575f,_0x46db71=_0x1cd6df[_0x320d2c(0x219)]===!![],_0x5a38b7=_0x1cd6df[_0x320d2c(0x219)]===![];if(!_0x1cd6df[_0x320d2c(0x1e9)]||!_0x1cd6df[_0x320d2c(0x1e9)][_0x320d2c(0x1f6)]())return![];return _0x128023[_0x320d2c(0x1d6)]&&_0x46db71||_0x128023['ai']&&_0x5a38b7;});}async function processCondensation(_0x96727d,_0x5e1d4d=()=>{},_0x25d789=null){const _0x49cc0c=_0x526041;if(!_0x96727d||_0x96727d[_0x49cc0c(0x21e)]===0x0)return{'success':![],'error':_0x49cc0c(0x22a)};try{let _0x52f561=await getCollectionId();const _0x3c8e31=getCollectionIdInfo();if(_0x3c8e31[_0x49cc0c(0x196)]&&_0x3c8e31['oldId']===_0x52f561&&_0x3c8e31['oldId']!==_0x3c8e31[_0x49cc0c(0x1bc)]){const _0x546b67=confirm(_0x49cc0c(0x229));if(_0x546b67)_0x5e1d4d(_0x49cc0c(0x1cd)+_0x3c8e31[_0x49cc0c(0x196)],_0x49cc0c(0x1ba)),await purgeStorage(_0x3c8e31[_0x49cc0c(0x196)]),_0x52f561=_0x3c8e31[_0x49cc0c(0x1bc)],_0x5e1d4d(_0x49cc0c(0x1f8)+_0x52f561,_0x49cc0c(0x174));else return _0x5e1d4d('[翰林院-迁移]\x20用户取消了迁移操作。',_0x49cc0c(0x1ab)),toastr[_0x49cc0c(0x1ab)](_0x49cc0c(0x1b6)),{'success':![],'error':_0x49cc0c(0x1e3)};}if(!_0x52f561)throw new Error(_0x49cc0c(0x19f));_0x5e1d4d('[翰林院-核心]\x20凝识任务已锁定忆识宝库ID:\x20'+_0x52f561,_0x49cc0c(0x1ab));const _0x4119a2=[],_0x399be6=context[_0x49cc0c(0x17c)];for(const _0x1efcbd of _0x96727d){const _0x5d79a9=(_0x1efcbd[_0x49cc0c(0x1e9)]||'')[_0x49cc0c(0x1fe)](/<[^>]*>/g,'')['trim']();if(_0x5d79a9[_0x49cc0c(0x21e)]===0x0)continue;let _0x1791d8;if(_0x1efcbd[_0x49cc0c(0x1dd)]!==undefined&&_0x1efcbd['floor']!==null)_0x1791d8=_0x1efcbd['floor'];else{const _0x262eaa=_0x399be6['findIndex'](_0x3f9cb3=>_0x3f9cb3===_0x1efcbd);_0x1791d8=_0x262eaa!==-0x1?_0x262eaa+0x1:-0x1;}const _0x5a717c=new Date(_0x1efcbd[_0x49cc0c(0x1a6)]),_0x348358=isNaN(_0x5a717c[_0x49cc0c(0x1f5)]())?new Date()[_0x49cc0c(0x199)]():_0x5a717c['toISOString'](),_0x2c678f=splitIntoChunks(_0x5d79a9,_0x49cc0c(0x1de),{'floor':_0x1791d8,'is_user':_0x1efcbd['is_user'],'timestamp':_0x348358});_0x4119a2[_0x49cc0c(0x184)](..._0x2c678f);}if(_0x4119a2[_0x49cc0c(0x21e)]===0x0)return{'success':!![],'count':0x0};_0x5e1d4d(_0x49cc0c(0x164)+_0x96727d[_0x49cc0c(0x21e)]+_0x49cc0c(0x1ce)+_0x4119a2[_0x49cc0c(0x21e)]+_0x49cc0c(0x16a),_0x49cc0c(0x1ab));const _0x51ef31=settings['retrieval'][_0x49cc0c(0x1be)]||0x5;let _0x84c1b1=0x0;for(let _0x47d301=0x0;_0x47d301<_0x4119a2['length'];_0x47d301+=_0x51ef31){const _0x5e5a14=_0x4119a2[_0x49cc0c(0x212)](_0x47d301,_0x47d301+_0x51ef31),_0x498b9f=_0x5e5a14[_0x49cc0c(0x1da)](_0x5a188a=>_0x5a188a[_0x49cc0c(0x1b7)]),_0x2c61e1=await getEmbeddings(_0x498b9f);if(_0x5e5a14[_0x49cc0c(0x21e)]!==_0x2c61e1[_0x49cc0c(0x21e)])throw new Error('文本块和向量数量不匹配');const _0x40b136=_0x5e5a14[_0x49cc0c(0x1da)]((_0x3add55,_0x564cdc)=>({..._0x3add55,'vector':_0x2c61e1[_0x564cdc]}));await insertVectors(_0x40b136,null,_0x52f561),_0x84c1b1+=_0x5e5a14['length'];}if(_0x25d789){const _0x44b95a=_0x25d789['end']===0x0?context['chat']['length']:_0x25d789[_0x49cc0c(0x201)];settings[_0x49cc0c(0x1b5)][_0x52f561]={'start':_0x25d789[_0x49cc0c(0x204)],'end':_0x44b95a,'timestamp':new Date()[_0x49cc0c(0x199)]()},saveSettings(),_0x5e1d4d(_0x49cc0c(0x1b2)+_0x52f561+_0x49cc0c(0x1b4)+_0x25d789[_0x49cc0c(0x204)]+'-'+_0x44b95a,_0x49cc0c(0x1ab));}_0x5e1d4d(_0x49cc0c(0x218)+_0x84c1b1+_0x49cc0c(0x1af),_0x49cc0c(0x174));const _0x23f1c6=_0x96727d[_0x49cc0c(0x1da)](_0x3fc384=>{const _0x1debb9=_0x49cc0c,_0x5e2860=_0x399be6[_0x1debb9(0x1fb)](_0x5d4600=>_0x5d4600===_0x3fc384),_0x309c7f=_0x5e2860!==-0x1?_0x5e2860+0x1:-0x1,_0x351154=_0x3fc384[_0x1debb9(0x219)]?'用户':getCharacterName()||'AI';return'['+_0x351154+_0x1debb9(0x1bb)+_0x309c7f+_0x1debb9(0x17f);});return{'success':!![],'count':_0x84c1b1,'messages':_0x23f1c6};}catch(_0xb5344e){return console[_0x49cc0c(0x1cf)](_0x49cc0c(0x21a),_0xb5344e),_0x5e1d4d(_0x49cc0c(0x1db)+_0xb5344e['message'],_0x49cc0c(0x1cf)),{'success':![],'error':_0xb5344e[_0x49cc0c(0x167)]};}}async function rerankResults(_0x380368,_0x997275,_0x54f5bc){const _0x876d01=_0x526041;let _0x2259d3=_0x380368;if(_0x54f5bc[_0x876d01(0x1d1)][_0x876d01(0x214)]&&_0x380368[_0x876d01(0x21e)]>0x0){console[_0x876d01(0x1e2)](_0x876d01(0x1e6));try{const _0x19623c=_0x380368[_0x876d01(0x1da)]((_0x1d78cc,_0x5e423b)=>({'text':_0x1d78cc['text'],'original_index':_0x5e423b})),_0x20ffa5=getRerankBaseUrl(_0x54f5bc[_0x876d01(0x1d1)][_0x876d01(0x19a)]),_0x22ba8d=_0x20ffa5+_0x876d01(0x20b),_0x3036f7=await fetch(_0x22ba8d,{'method':_0x876d01(0x175),'headers':{'Content-Type':_0x876d01(0x1c1),'Authorization':'Bearer\x20'+_0x54f5bc[_0x876d01(0x1d1)][_0x876d01(0x21b)]},'body':JSON[_0x876d01(0x18f)]({'query':_0x997275,'documents':_0x19623c[_0x876d01(0x1da)](_0x29bbaf=>_0x29bbaf['text']),'model':_0x54f5bc[_0x876d01(0x1d1)][_0x876d01(0x197)],'top_n':_0x54f5bc[_0x876d01(0x1d1)][_0x876d01(0x217)]})});if(!_0x3036f7['ok'])throw new Error(_0x876d01(0x177)+_0x3036f7[_0x876d01(0x1f9)]+_0x876d01(0x1e4)+await _0x3036f7[_0x876d01(0x1b7)]());const _0x7b13ef=await _0x3036f7[_0x876d01(0x1b9)](),_0x51d4d1=_0x380368[_0x876d01(0x1da)]((_0x459e5e,_0xf5f286)=>({..._0x459e5e,'original_index':_0xf5f286}));_0x2259d3=_0x51d4d1['map'](_0x2281d5=>{const _0x45890a=_0x876d01,_0x399dad=_0x7b13ef['results'][_0x45890a(0x18b)](_0x124c4b=>_0x124c4b[_0x45890a(0x1c4)]===_0x2281d5['original_index']),_0xbdd03e=_0x399dad?_0x399dad[_0x45890a(0x176)]:0x0;return{..._0x2281d5,'rerank_score':_0xbdd03e};});if(_0x54f5bc['rerank'][_0x876d01(0x21d)])showNotification(_0x876d01(0x1a3),_0x876d01(0x174));}catch(_0x20f827){console['error']('[翰林院-Rerank]\x20外部Rerank失败,将仅使用内部加权。',_0x20f827);if(_0x54f5bc[_0x876d01(0x1d1)][_0x876d01(0x21d)])showNotification(_0x876d01(0x1f0)+_0x20f827[_0x876d01(0x167)],_0x876d01(0x1cf));_0x2259d3[_0x876d01(0x1e7)](_0x1d64c4=>_0x1d64c4[_0x876d01(0x182)]=0x0);}}else _0x2259d3[_0x876d01(0x1e7)](_0x778ebd=>_0x778ebd['rerank_score']=0x0);console[_0x876d01(0x1e2)](_0x876d01(0x16b));const _0x19f3de=context[_0x876d01(0x17c)]['length'],_0x2e22ca=_0x54f5bc['rerank']['hybrid_alpha'],_0x313757=_0x2259d3[_0x876d01(0x1da)](_0x38de23=>{const _0x4d5734=_0x876d01;let _0x5db754=0x1;const _0x2f05b6=_0x38de23[_0x4d5734(0x1f7)]||{};switch(_0x2f05b6[_0x4d5734(0x1c3)]){case _0x4d5734(0x1d3):_0x5db754*=1.2;break;case _0x4d5734(0x18c):_0x5db754*=1.1;break;case'chat_history':if(_0x2f05b6[_0x4d5734(0x1dd)]&&_0x19f3de>0x0){const _0x32038d=_0x2f05b6[_0x4d5734(0x1dd)]/_0x19f3de;_0x5db754*=0x1+_0x32038d;}break;}const _0x5b28d6=_0x38de23['rerank_score']*_0x2e22ca+(_0x38de23[_0x4d5734(0x160)]||0x0)*(0x1-_0x2e22ca),_0x2c6ba8=_0x5b28d6*_0x5db754;return{..._0x38de23,'final_score':_0x2c6ba8};});return _0x313757[_0x876d01(0x1eb)]((_0x3fc0bc,_0x5a3f5d)=>(_0x5a3f5d['final_score']||0x0)-(_0x3fc0bc[_0x876d01(0x195)]||0x0)),console[_0x876d01(0x1e2)](_0x876d01(0x16e)),_0x313757['slice'](0x0,_0x54f5bc[_0x876d01(0x1d1)][_0x876d01(0x217)]);}async function rearrangeChat(_0xbe51da,_0x216eaa,_0x45c747,_0x22f728){const _0x394a79=_0x526041;setExtensionPrompt(_0x394a79(0x220),'',settings['injection'][_0x394a79(0x1ff)],settings[_0x394a79(0x173)][_0x394a79(0x1cb)],![],settings[_0x394a79(0x173)]['depth_role']);if(_0x22f728===_0x394a79(0x166)||!settings['retrieval'][_0x394a79(0x214)])return;const _0x476341=_0xbe51da[_0x394a79(0x212)](-settings['advanced']['queryMessageCount']);if(_0x476341[_0x394a79(0x21e)]===0x0)return;const _0x515f59=_0x476341[_0x394a79(0x1da)](_0x114ff9=>_0x114ff9[_0x394a79(0x1e9)])[_0x394a79(0x1a7)]('\x20')['replace'](/<[^>]*>/g,'')[_0x394a79(0x1f6)]();if(!_0x515f59)return;try{const _0x3d0635=await queryVectors(_0x515f59);if(_0x3d0635[_0x394a79(0x21e)]===0x0)return;const _0x4f0b23=await rerankResults(_0x3d0635,_0x515f59,settings);if(_0x4f0b23[_0x394a79(0x21e)]===0x0)return;const _0x4cc29b=_0x4f0b23[_0x394a79(0x1da)](_0x55f724=>_0x55f724[_0x394a79(0x1b7)])['join']('\x0a\x0a'),_0x485935=settings[_0x394a79(0x173)][_0x394a79(0x206)]['replace']('{{text}}',_0x4cc29b);setExtensionPrompt(_0x394a79(0x220),_0x485935,settings['injection'][_0x394a79(0x1ff)],settings[_0x394a79(0x173)][_0x394a79(0x1cb)],![],settings[_0x394a79(0x173)]['depth_role']);}catch(_0x1d58db){console[_0x394a79(0x1cf)](_0x394a79(0x1d8),_0x1d58db);if(settings[_0x394a79(0x161)][_0x394a79(0x21d)])showNotification('忆识检索失败:\x20'+_0x1d58db['message'],'error');}} +'use strict';const _0x4a685c=_0x1993;(function(_0x465453,_0x797624){const _0x266fbe=_0x1993,_0xbdd17d=_0x465453();while(!![]){try{const _0xe1473c=parseInt(_0x266fbe(0xf6))/0x1+parseInt(_0x266fbe(0xfb))/0x2+parseInt(_0x266fbe(0xb8))/0x3+-parseInt(_0x266fbe(0x12a))/0x4+-parseInt(_0x266fbe(0x11a))/0x5+parseInt(_0x266fbe(0xe9))/0x6+-parseInt(_0x266fbe(0x9e))/0x7*(parseInt(_0x266fbe(0x12b))/0x8);if(_0xe1473c===_0x797624)break;else _0xbdd17d['push'](_0xbdd17d['shift']());}catch(_0x4577f6){_0xbdd17d['push'](_0xbdd17d['shift']());}}}(_0x55f7,0x316f8));import{extension_prompt_roles,setExtensionPrompt}from'/script.js';function _0x1993(_0x3b269c,_0x4bb7cb){const _0x55f721=_0x55f7();return _0x1993=function(_0x1993e9,_0x1728e2){_0x1993e9=_0x1993e9-0x90;let _0x49c1be=_0x55f721[_0x1993e9];return _0x49c1be;},_0x1993(_0x3b269c,_0x4bb7cb);}import*as _0x2ce1b6 from'./utils/context-utils.js';import{getCollectionIdInfo}from'./utils/context-utils.js';import{defaultSettings as _0x50292a}from'./rag-settings.js';import*as _0x20bfcb from'./ingestion-manager.js';import{getSanitizedBaseUrl,fetchEmbeddingModels,getRerankBaseUrl,fetchRerankModels,executeRerank,getApiEndpointUrl,getApiHeaders,getEmbeddings,testApiConnection as _0x4cc999}from'./rag-api.js';const MODULE_NAME=_0x4a685c(0xdd),OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME=_0x4a685c(0xf0);let context=null,settings=null,lockedCollectionId=null;function _0x55f7(){const _0x3c0060=['batchSize','Rerank失败:\x20','\x20记录凝识范围:\x20','replace','message','success','floor','[翰林院-日志]\x20忆识存入API错误:','[翰林院-核心]\x20ingestTextToHanlinyuan\x20失败:','start','hashes','aborted','\x20个条目。','第1章','extensionSettings','injection','POST','hanlinyuan-rag-core','trim','[翰林院-日志]\x20查询目标集合ID:\x20','error','length','info','[翰林院-日志]\x20宝库查询API错误:','[翰林院-日志]\x20开始向量查询\x20(采用最终API交互模式)...','[翰林院-分块]\x20未知的来源类型\x20\x27','无法确定当前忆识宝库的ID,请确认角色已正确加载。','未知来源',',\x20第1卷,\x20第1章,\x20第','651186qbGpdI','[翰林院-日志]\x20发送到\x20/api/vector/query\x20的请求体:','翰林院忆识核心已启动\x20(V5.1-借壳上市版),已注册全局函数:\x20','clearJob','[翰林院-日志]\x20/api/vector/list\x20响应状态:\x20','saveSettingsDebounced','toString','vectors_rearrangeChat','depth','/api/vector/list','find','[来源:\x20','[翰林院-日志]\x20统计成功,向量总数:\x20','94480ptGPUY','messageTypes','操作已取消。','\x20-\x20楼层\x20#','小说录入','634570UVhvnL','substring','外部Rerank完成','name','聊天记录\x20#','depth_role','saveProgress','getRequestHeaders','\x20条结果。','[来源:\x20世界书,\x20条目:\x20','filter','enabled','slice','webllm','log','function','user','join','世界书','正在智能分块...','[翰林院-日志]\x20开始清空宝库...','notify','oldId','condensation','rerank','[翰林院-日志]\x20/api/vector/purge\x20响应状态:\x20','toLocaleString','(已锁定:\x20','[翰林院-核心]\x20已锁定忆识宝库ID:\x20','输入文本为空','push','21445LqJvNd','final_score','\x0a{},_0x4e9140=null,_0x41f364=()=>{},_0x3905af=()=>{},_0x18d9cc=null,_0x5606cc=0x0,_0xc20e48=null){const _0x276cb5=_0x4a685c;if(!_0x35fd35||!_0x35fd35[_0x276cb5(0xde)]())return{'success':![],'error':_0x276cb5(0x118)};if(!settings)return{'success':![],'error':_0x276cb5(0x137)};try{let _0x5ebc47=await getCollectionId();const _0x4486d2=getCollectionIdInfo();if(_0x4486d2[_0x276cb5(0x111)]&&_0x4486d2[_0x276cb5(0x111)]===_0x5ebc47&&_0x4486d2[_0x276cb5(0x111)]!==_0x4486d2[_0x276cb5(0x11f)]){const _0x43c261=confirm(_0x276cb5(0xba));if(_0x43c261)_0x41f364(_0x276cb5(0x134)+_0x4486d2[_0x276cb5(0x111)],_0x276cb5(0xc6)),await purgeStorage(_0x4486d2[_0x276cb5(0x111)]),_0x5ebc47=_0x4486d2[_0x276cb5(0x11f)],_0x41f364('[翰林院-迁移]\x20旧宝库已清空,将向新宝库写入数据:\x20'+_0x5ebc47,_0x276cb5(0xd1));else return _0x41f364(_0x276cb5(0xac),'info'),toastr[_0x276cb5(0xe2)](_0x276cb5(0xf8)),{'success':![],'error':'用户取消了迁移操作'};}if(!_0x5ebc47)throw new Error(_0x276cb5(0xe6));_0x41f364(_0x276cb5(0x117)+_0x5ebc47,_0x276cb5(0xe2)),_0x1d2fe6({'message':_0x276cb5(0x10e),'processed':0x0,'total':0x1});const _0x2b682f=splitIntoChunks(_0x35fd35,_0x5470e4,{'sourceName':_0x42d390}),_0x3bf271=_0x2b682f[_0x276cb5(0xe1)];if(_0x4e9140?.['aborted'])throw new Error(_0x276cb5(0xa4));_0x41f364(_0x276cb5(0xc7)+(_0x42d390||_0x5470e4)+_0x276cb5(0x13e)+_0x3bf271+'\x20个块。',_0x276cb5(0xe2));if(_0x3bf271===0x0)return{'success':!![],'count':0x0};const _0x1b6344=settings['retrieval']['batchSize']||0x5;let _0x9fa417=_0x5606cc;for(let _0x3fed2e=_0x5606cc;_0x3fed2e<_0x3bf271;_0x3fed2e+=_0x1b6344){if(_0x4e9140?.[_0x276cb5(0xd7)])throw new Error('AbortError');const _0x3c8909=_0x2b682f[_0x276cb5(0x107)](_0x3fed2e,_0x3fed2e+_0x1b6344);_0x1d2fe6({'message':_0x276cb5(0xad)+(_0x3fed2e+0x1)+'-'+(_0x3fed2e+_0x3c8909[_0x276cb5(0xe1)])+'\x20块','processed':_0x3fed2e,'total':_0x3bf271});const _0x5722d5=_0x3c8909['map'](_0x1ae7b1=>_0x1ae7b1[_0x276cb5(0x139)]),_0x440d22=await getEmbeddings(_0x5722d5,_0x4e9140);if(_0x4e9140?.['aborted'])throw new Error(_0x276cb5(0xa4));if(_0x3c8909[_0x276cb5(0xe1)]!==_0x440d22[_0x276cb5(0xe1)])throw new Error(_0x276cb5(0x9a));const _0x14f3a5=_0x3c8909['map']((_0x349e44,_0x105c24)=>({..._0x349e44,'vector':_0x440d22[_0x105c24]}));await insertVectors(_0x14f3a5,_0x4e9140,_0x5ebc47),_0x9fa417+=_0x3c8909[_0x276cb5(0xe1)],_0x18d9cc&&_0x20bfcb[_0x276cb5(0x101)](_0x18d9cc,_0x9fa417,_0x3bf271),_0x3905af();}_0x18d9cc&&_0x20bfcb[_0x276cb5(0xec)](_0x18d9cc);if(_0xc20e48){const _0x4cff28=await getCollectionId(),_0x17764e=_0xc20e48[_0x276cb5(0xb3)]===0x0?context[_0x276cb5(0xb0)]['length']:_0xc20e48[_0x276cb5(0xb3)];settings[_0x276cb5(0x12e)][_0x4cff28]={'start':_0xc20e48['start'],'end':_0x17764e,'timestamp':new Date()['toISOString']()},saveSettings(),_0x41f364('[翰林院-核心]\x20已为宝库\x20'+_0x4cff28+_0x276cb5(0xce)+_0xc20e48[_0x276cb5(0xd5)]+'-'+_0x17764e,_0x276cb5(0xe2));}return _0x41f364(_0x276cb5(0x13d)+_0x9fa417+'\x20个向量条目。',_0x276cb5(0xd1)),{'success':!![],'count':_0x9fa417};}catch(_0x145ef8){if(_0x145ef8[_0x276cb5(0xfe)]===_0x276cb5(0xa4)){_0x41f364(_0x276cb5(0x132),_0x276cb5(0xc6));throw _0x145ef8;}return console[_0x276cb5(0xe0)](_0x276cb5(0xd4),_0x145ef8),_0x41f364('[翰林院-核心]\x20文本录入失败:\x20'+_0x145ef8[_0x276cb5(0xd0)],_0x276cb5(0xe0)),{'success':![],'error':_0x145ef8['message']};}}function getSettings(){const _0x4adc09=_0x4a685c;if(!context||!context[_0x4adc09(0xda)])return structuredClone(_0x50292a);let _0x237086=context[_0x4adc09(0xda)][MODULE_NAME];!_0x237086&&(_0x237086={},context[_0x4adc09(0xda)][MODULE_NAME]=_0x237086);_0x237086[_0x4adc09(0x12e)]===undefined&&(_0x237086[_0x4adc09(0x12e)]={});for(const _0x2cc91d in _0x50292a){if(_0x237086[_0x2cc91d]===undefined)_0x237086[_0x2cc91d]=structuredClone(_0x50292a[_0x2cc91d]);else{if(typeof _0x50292a[_0x2cc91d]==='object'&&!Array[_0x4adc09(0xc2)](_0x50292a[_0x2cc91d])&&_0x50292a[_0x2cc91d]!==null)for(const _0x36be81 in _0x50292a[_0x2cc91d]){_0x237086[_0x2cc91d][_0x36be81]===undefined&&(_0x237086[_0x2cc91d][_0x36be81]=_0x50292a[_0x2cc91d][_0x36be81]);}}}return _0x237086;}function saveSettings(){const _0x581eb1=_0x4a685c;if(context)context[_0x581eb1(0xee)]();}function resetSettings(){const _0x2e456a=_0x4a685c;context&&(context[_0x2e456a(0xda)][MODULE_NAME]=structuredClone(_0x50292a),saveSettings());}function showNotification(_0x16cb5e,_0x14b828=_0x4a685c(0xe2)){toastr[_0x14b828](_0x16cb5e);}function getTagForSource(_0x19c253){const _0x24b56e=_0x4a685c;switch(_0x19c253){case _0x24b56e(0xc4):return _0x24b56e(0xbc);case _0x24b56e(0x120):return _0x24b56e(0x10d);case _0x24b56e(0xb9):return _0x24b56e(0xa3);case _0x24b56e(0x124):return _0x24b56e(0xfa);default:return'资料';}}function splitIntoChunks(_0x264df0,_0x35d097,_0x4331c4={}){const _0x20d2ba=_0x4a685c;switch(_0x35d097){case _0x20d2ba(0x124):return _chunkForNovel(_0x264df0,_0x4331c4);case _0x20d2ba(0xc4):return _chunkForChatHistory(_0x264df0,_0x4331c4);case'lorebook':return _chunkForLorebook(_0x264df0,_0x4331c4);case _0x20d2ba(0xb9):return _chunkForManual(_0x264df0,_0x4331c4);default:console[_0x20d2ba(0xc6)](_0x20d2ba(0xe5)+_0x35d097+_0x20d2ba(0x123));return _chunkForManual(_0x264df0,{..._0x4331c4,'sourceName':_0x4331c4[_0x20d2ba(0x11d)]||_0x20d2ba(0xe7)});}}function _chunkForNovel(_0x1b90f9,_0x290961){const _0x20022c=_0x4a685c,{chunkSize:_0x28dfad,overlap:_0x3540d6}=settings['advanced'],{sourceName:sourceName='小说'}=_0x290961,_0x4db620=[];if(!_0x1b90f9||_0x28dfad<=0x0)return _0x4db620;const _0xbb125f=/(第\s*[一二三四五六七八九十百千万零\d]+\s*卷)/gim,_0x1872e4=/(第\s*[一二三四五六七八九十百千万零\d]+\s*[章回节部])|^(Chapter\s+\d+)/gim;let _0x2157cb=0x0;const _0x21f23f=_0x1b90f9[_0x20022c(0x9b)]('\x0a');let _0x5a669c=_0x20022c(0xa2),_0x2b954b=_0x20022c(0xd9),_0x18e5a4=[];function _0x36e689(){const _0x1df18c=_0x20022c;if(_0x18e5a4[_0x1df18c(0xe1)]===0x0)return;const _0x421b82=_0x18e5a4[_0x1df18c(0x10c)]('\x0a');let _0x298d18=0x0,_0x297faa=0x1;while(_0x298d18<_0x421b82[_0x1df18c(0xe1)]){const _0x243838=Math[_0x1df18c(0xbd)](_0x298d18+_0x28dfad,_0x421b82[_0x1df18c(0xe1)]),_0x4270a4=_0x421b82[_0x1df18c(0xfc)](_0x298d18,_0x243838);if(_0x4270a4[_0x1df18c(0xde)]()[_0x1df18c(0xe1)]>0x0){const _0x36dce0={'source':_0x1df18c(0x124),'sourceName':sourceName,'timestamp':new Date()[_0x1df18c(0x91)](),'globalIndex':_0x2157cb++,'volume':_0x5a669c,'chapter':_0x2b954b,'section':_0x297faa},_0x3663b8=getTagForSource('novel'),_0x38778a=_0x1df18c(0xf4)+sourceName+',\x20'+_0x5a669c+',\x20'+_0x2b954b+_0x1df18c(0x129)+_0x297faa+'节]',_0x53ada9='<'+_0x3663b8+'>\x0a'+_0x38778a+'\x0a'+_0x4270a4+_0x1df18c(0x11c)+_0x3663b8+'>';_0x4db620[_0x1df18c(0x119)]({'text':_0x53ada9,'metadata':_0x36dce0}),_0x297faa++;}_0x298d18+=_0x28dfad-_0x3540d6;if(_0x298d18>=_0x421b82[_0x1df18c(0xe1)])break;}_0x18e5a4=[];}for(const _0xef2769 of _0x21f23f){const _0x410900=_0xef2769[_0x20022c(0xde)]();if(_0xbb125f['test'](_0x410900))_0x36e689(),_0x5a669c=_0x410900,_0x2b954b=_0x20022c(0xd9);else _0x1872e4[_0x20022c(0x98)](_0x410900)?(_0x36e689(),_0x2b954b=_0x410900):_0x18e5a4[_0x20022c(0x119)](_0xef2769);}_0x36e689();if(_0x4db620[_0x20022c(0xe1)]===0x0&&_0x1b90f9['length']>0x0){let _0x250dd3=0x0,_0xa22d9e=0x1;while(_0x250dd3<_0x1b90f9[_0x20022c(0xe1)]){const _0x302642=Math[_0x20022c(0xbd)](_0x250dd3+_0x28dfad,_0x1b90f9[_0x20022c(0xe1)]),_0x14476f=_0x1b90f9['substring'](_0x250dd3,_0x302642),_0x3a7c93={'source':_0x20022c(0x124),'sourceName':sourceName,'timestamp':new Date()[_0x20022c(0x91)](),'globalIndex':_0x4db620[_0x20022c(0xe1)],'volume':_0x20022c(0xa2),'chapter':_0x20022c(0xd9),'section':_0xa22d9e},_0x28ec3c=getTagForSource(_0x20022c(0x124)),_0x2f1303=_0x20022c(0xf4)+sourceName+_0x20022c(0xe8)+_0xa22d9e+'节]',_0x3d71ec='<'+_0x28ec3c+'>\x0a'+_0x2f1303+'\x0a'+_0x14476f+'\x0a';_0x4db620[_0x20022c(0x119)]({'text':_0x3d71ec,'metadata':_0x3a7c93}),_0xa22d9e++,_0x250dd3+=_0x28dfad-_0x3540d6;}}return _0x4db620;}function _chunkForChatHistory(_0x17a8f9,_0xc0184c){const _0x4df133=_0x4a685c,{chunkSize:_0x5589bb,overlap:_0x399ede}=settings[_0x4df133(0xa1)],{floor:_0x54a67f,is_user:_0x40df49,timestamp:_0xc668ed}=_0xc0184c,_0x27560a=[];if(!_0x17a8f9||_0x5589bb<=0x0)return _0x27560a;let _0x4e567b=0x1,_0x142ed7=0x0;while(_0x142ed7<_0x17a8f9[_0x4df133(0xe1)]){const _0x49fc92=Math[_0x4df133(0xbd)](_0x142ed7+_0x5589bb,_0x17a8f9[_0x4df133(0xe1)]),_0x188434=_0x17a8f9['substring'](_0x142ed7,_0x49fc92),_0x47a75e=_0x4df133(0x125)+_0x54a67f+_0x4df133(0x129)+_0x4e567b+_0x4df133(0x97),_0x2a7d39=getTagForSource(_0x4df133(0xc4)),_0x1cb927='<'+_0x2a7d39+'>\x0a'+_0x47a75e+'\x0a'+_0x188434+_0x4df133(0x11c)+_0x2a7d39+'>';_0x27560a['push']({'text':_0x1cb927,'metadata':{'source':'chat_history','sourceName':_0x4df133(0xff)+_0x54a67f,'floor':_0x54a67f,'part':_0x4e567b,'is_user':_0x40df49,'timestamp':_0xc668ed}}),_0x4e567b++,_0x142ed7+=_0x5589bb-_0x399ede;if(_0x142ed7>=_0x17a8f9['length'])break;}return _0x27560a;}function _chunkForLorebook(_0x18ca69,_0x55d1fc){const _0x16f789=_0x4a685c,{chunkSize:_0x1ab46b,overlap:_0x450038}=settings[_0x16f789(0xa1)],{sourceName:sourceName=_0x16f789(0x13f)}=_0x55d1fc,_0x1042c8=[];if(!_0x18ca69||_0x1ab46b<=0x0)return _0x1042c8;let _0x503702=0x1,_0x42970b=0x0;while(_0x42970b<_0x18ca69[_0x16f789(0xe1)]){const _0x36b0be=Math[_0x16f789(0xbd)](_0x42970b+_0x1ab46b,_0x18ca69[_0x16f789(0xe1)]),_0x2344f=_0x18ca69[_0x16f789(0xfc)](_0x42970b,_0x36b0be),_0x16813f=_0x16f789(0x104)+sourceName+_0x16f789(0x129)+_0x503702+_0x16f789(0x97),_0x308dc1=getTagForSource(_0x16f789(0x120)),_0x5c8a5c='<'+_0x308dc1+'>\x0a'+_0x16813f+'\x0a'+_0x2344f+_0x16f789(0x11c)+_0x308dc1+'>';_0x1042c8[_0x16f789(0x119)]({'text':_0x5c8a5c,'metadata':{'source':_0x16f789(0x120),'sourceName':sourceName,'part':_0x503702,'timestamp':new Date()['toISOString']()}}),_0x503702++,_0x42970b+=_0x1ab46b-_0x450038;if(_0x42970b>=_0x18ca69['length'])break;}return _0x1042c8;}function _chunkForManual(_0xf151b6,_0x14fc0a){const _0x1e49ab=_0x4a685c,{chunkSize:_0x456484,overlap:_0x7bc0d0}=settings[_0x1e49ab(0xa1)],{sourceName:sourceName=_0x1e49ab(0xa3)}=_0x14fc0a,_0x49485b=[];if(!_0xf151b6||_0x456484<=0x0)return _0x49485b;const _0x212e84=new Date(),_0x42b285=_0x212e84[_0x1e49ab(0x115)]('zh-CN');let _0x435499=0x1,_0x1febb4=0x0;while(_0x1febb4<_0xf151b6[_0x1e49ab(0xe1)]){const _0x52ebdf=Math['min'](_0x1febb4+_0x456484,_0xf151b6[_0x1e49ab(0xe1)]),_0x506a3b=_0xf151b6[_0x1e49ab(0xfc)](_0x1febb4,_0x52ebdf),_0x539ae0=_0x1e49ab(0xf4)+sourceName+',\x20向量化录入时间:\x20'+_0x42b285+_0x1e49ab(0x129)+_0x435499+_0x1e49ab(0x97),_0x48429f=getTagForSource(_0x1e49ab(0xb9)),_0x4eecf8='<'+_0x48429f+'>\x0a'+_0x539ae0+'\x0a'+_0x506a3b+'\x0a';_0x49485b['push']({'text':_0x4eecf8,'metadata':{'source':_0x1e49ab(0xb9),'sourceName':sourceName,'part':_0x435499,'timestamp':_0x212e84['toISOString']()}}),_0x435499++,_0x1febb4+=_0x456484-_0x7bc0d0;if(_0x1febb4>=_0xf151b6[_0x1e49ab(0xe1)])break;}return _0x49485b;}import{getCollectionId as _0x1c3d83,getCharacterName}from'./utils/context-utils.js';async function getCollectionId(){return lockedCollectionId||await _0x1c3d83();}async function toggleSessionLock(){return lockedCollectionId?(lockedCollectionId=null,![]):(lockedCollectionId=await _0x1c3d83(),!![]);}function isSessionLocked(){return lockedCollectionId!==null;}function getLockedSessionInfo(){const _0x194c9e=_0x4a685c;if(!lockedCollectionId)return null;return{'id':lockedCollectionId,'name':_0x194c9e(0x116)+lockedCollectionId[_0x194c9e(0xfc)](0x0,0x8)+'...)'};}function generateHash(_0xb8933){const _0x40d9a4=_0x4a685c;let _0x1ff27d=0x0;for(let _0x3c2fb3=0x0;_0x3c2fb3<_0xb8933[_0x40d9a4(0xe1)];_0x3c2fb3++){const _0x1b9f4c=_0xb8933['charCodeAt'](_0x3c2fb3);_0x1ff27d=(_0x1ff27d<<0x5)-_0x1ff27d+_0x1b9f4c,_0x1ff27d=_0x1ff27d&_0x1ff27d;}return Math['abs'](_0x1ff27d)[_0x40d9a4(0xef)](0x24);}async function queryVectors(_0x2e20ad){const _0x2b367a=_0x4a685c;console[_0x2b367a(0x109)](_0x2b367a(0xe4));const _0xbd790c=await getCollectionId();console[_0x2b367a(0x109)](_0x2b367a(0xdf)+_0xbd790c);const _0x12f504=(await getEmbeddings([_0x2e20ad]))[0x0],_0x3612fa={'collectionId':_0xbd790c,'searchText':_0x2e20ad,'topK':settings[_0x2b367a(0xa1)][_0x2b367a(0xb5)],'threshold':settings['advanced'][_0x2b367a(0xa7)],'source':_0x2b367a(0x108),'embeddings':{[_0x2e20ad]:_0x12f504}};console[_0x2b367a(0x109)](_0x2b367a(0xea),JSON['stringify'](_0x3612fa,null,0x2));const _0xaab904=await fetch(_0x2b367a(0x136),{'method':_0x2b367a(0xdc),'headers':context[_0x2b367a(0x102)](),'body':JSON[_0x2b367a(0xc5)](_0x3612fa)});console[_0x2b367a(0x109)]('[翰林院-日志]\x20/api/vector/query\x20响应状态:\x20'+_0xaab904[_0x2b367a(0x138)]);if(!_0xaab904['ok']){const _0x4400a4=await _0xaab904[_0x2b367a(0x139)]();console[_0x2b367a(0xe0)](_0x2b367a(0xe3),_0x4400a4);throw new Error(_0x2b367a(0x122)+_0xaab904[_0x2b367a(0x138)]+':\x20'+_0x4400a4);}const _0x282e4d=await _0xaab904[_0x2b367a(0xc8)]();console['log'](_0x2b367a(0x133),_0x282e4d);const _0x4ad4be=_0x282e4d[_0x2b367a(0x142)]||_0x282e4d['results']||_0x282e4d[_0x2b367a(0x9d)]||[];return console[_0x2b367a(0x109)](_0x2b367a(0x140)+_0x4ad4be[_0x2b367a(0xe1)]+_0x2b367a(0x103)),_0x4ad4be;}async function insertVectors(_0x39a150,_0x444d09=null,_0x1b491b){const _0x4d731b=_0x4a685c;if(!_0x1b491b){console['error']('[翰林院-核心]\x20insertVectors被调用时未提供collectionId!'),_0x1b491b=await getCollectionId();if(!_0x1b491b)throw new Error('在insertVectors内部也无法获取collectionId');}if(_0x39a150[_0x4d731b(0xe1)]===0x0)return{'success':!![],'count':0x0};const _0x56b3e5=_0x39a150[_0x4d731b(0xb7)]((_0x5f511b,_0x412fa8)=>({'hash':generateHash(_0x5f511b[_0x4d731b(0x139)]+Date[_0x4d731b(0x128)]()+_0x412fa8),'text':_0x5f511b['text'],'metadata':_0x5f511b[_0x4d731b(0x142)]||{'source':_0x4d731b(0xb1),'timestamp':new Date()['toISOString']()}})),_0x579776=_0x56b3e5[_0x4d731b(0x127)]((_0x93966b,_0x1359bb,_0x5be7f3)=>{const _0x1b3af5=_0x4d731b;return _0x93966b[_0x1359bb['text']]=_0x39a150[_0x5be7f3][_0x1b3af5(0x141)],_0x93966b;},{}),_0xbd41f6={'collectionId':_0x1b491b,'items':_0x56b3e5,'source':_0x4d731b(0x108),'embeddings':_0x579776},_0x3fe85f=await fetch('/api/vector/insert',{'method':'POST','headers':context[_0x4d731b(0x102)](),'body':JSON[_0x4d731b(0xc5)](_0xbd41f6),'signal':_0x444d09});if(!_0x3fe85f['ok']){const _0x14fefe=await _0x3fe85f['text']();console[_0x4d731b(0xe0)](_0x4d731b(0xd3),_0x14fefe);throw new Error('忆识存入API错误\x20'+_0x3fe85f[_0x4d731b(0x138)]+':\x20'+_0x14fefe);}return{'success':!![],'count':_0x56b3e5[_0x4d731b(0xe1)]};}async function getVectorCount(){const _0xfe1199=_0x4a685c;console[_0xfe1199(0x109)](_0xfe1199(0x12c));const _0x5c172b=await getCollectionId();console[_0xfe1199(0x109)]('[翰林院-日志]\x20统计目标集合ID:\x20'+_0x5c172b);const _0x5abe3b={'collectionId':_0x5c172b,'source':_0xfe1199(0x108),'embeddings':{}};console[_0xfe1199(0x109)]('[翰林院-日志]\x20发送到\x20/api/vector/list\x20的请求体:',JSON[_0xfe1199(0xc5)](_0x5abe3b,null,0x2));const _0x372f07=await fetch(_0xfe1199(0xf2),{'method':'POST','headers':context['getRequestHeaders'](),'body':JSON['stringify'](_0x5abe3b)});console[_0xfe1199(0x109)](_0xfe1199(0xed)+_0x372f07[_0xfe1199(0x138)]);if(!_0x372f07['ok']){const _0x3be915=await _0x372f07[_0xfe1199(0x139)]();return console[_0xfe1199(0xe0)]('[翰林院-日志]\x20获取向量列表API错误:',_0x3be915),0x0;}const _0x431d4e=await _0x372f07[_0xfe1199(0xc8)]();let _0x13841e=0x0;if(Array[_0xfe1199(0xc2)](_0x431d4e))_0x13841e=_0x431d4e[_0xfe1199(0xe1)];else _0x431d4e&&_0x431d4e[_0xfe1199(0xd6)]&&(_0x13841e=_0x431d4e[_0xfe1199(0xd6)]['length']);return console['log'](_0xfe1199(0xf5)+_0x13841e),_0x13841e;}async function purgeStorage(_0x315efd=null){const _0x1a8137=_0x4a685c;console[_0x1a8137(0x109)](_0x1a8137(0x10f));const _0x473b8d=_0x315efd||await getCollectionId();if(!_0x473b8d)return console[_0x1a8137(0xe0)]('[翰林院-日志]\x20无法确定要清空的目标集合ID。'),toastr[_0x1a8137(0xe0)](_0x1a8137(0x12d)),![];console['log'](_0x1a8137(0xa8)+_0x473b8d);const _0x345c77={'collectionId':_0x473b8d};console[_0x1a8137(0x109)](_0x1a8137(0xa0),JSON[_0x1a8137(0xc5)](_0x345c77,null,0x2));const _0x397c56=await fetch(_0x1a8137(0x12f),{'method':_0x1a8137(0xdc),'headers':context[_0x1a8137(0x102)](),'body':JSON['stringify'](_0x345c77)});console['log'](_0x1a8137(0x114)+_0x397c56[_0x1a8137(0x138)]);if(!_0x397c56['ok']){const _0x307975=await _0x397c56[_0x1a8137(0x139)]();console['error']('[翰林院-日志]\x20清空宝库API错误:',_0x307975);}else console[_0x1a8137(0x109)](_0x1a8137(0x90));return _0x397c56['ok'];}function getMessagesForCondensation(_0x53bf56=null){const _0x250cb8=_0x4a685c;if(!settings[_0x250cb8(0x112)][_0x250cb8(0x106)])return showNotification(_0x250cb8(0x13b),_0x250cb8(0xb6)),[];const {layerStart:_0x2ba711,layerEnd:_0x4f2cc4}=settings['condensation'],_0x53d29f=_0x53bf56||settings[_0x250cb8(0x112)][_0x250cb8(0xf7)],_0x116b94=context[_0x250cb8(0xb0)][_0x250cb8(0xe1)],_0x4016e3=Math[_0x250cb8(0x131)](0x0,_0x2ba711-0x1),_0xce9e8f=_0x4f2cc4===0x0||_0x4f2cc4>_0x116b94?_0x116b94:Math[_0x250cb8(0xbd)](_0x116b94,_0x4f2cc4),_0x5e91c6=context[_0x250cb8(0xb0)]['slice'](_0x4016e3,_0xce9e8f);return _0x5e91c6[_0x250cb8(0x105)](_0x45faff=>{const _0x24e075=_0x250cb8,_0x2d2597=_0x45faff['is_user']===!![],_0x1578a3=_0x45faff['is_user']===![];if(!_0x45faff[_0x24e075(0xab)]||!_0x45faff[_0x24e075(0xab)][_0x24e075(0xde)]())return![];return _0x53d29f[_0x24e075(0x10b)]&&_0x2d2597||_0x53d29f['ai']&&_0x1578a3;});}async function processCondensation(_0x22f33d,_0x2b8b4c=()=>{},_0x14e488=null){const _0x356b03=_0x4a685c;if(!_0x22f33d||_0x22f33d[_0x356b03(0xe1)]===0x0)return{'success':![],'error':_0x356b03(0x126)};try{let _0xd6ddbd=await getCollectionId();const _0x4a729b=getCollectionIdInfo();if(_0x4a729b[_0x356b03(0x111)]&&_0x4a729b[_0x356b03(0x111)]===_0xd6ddbd&&_0x4a729b['oldId']!==_0x4a729b[_0x356b03(0x11f)]){const _0x1ff9af=confirm(_0x356b03(0xba));if(_0x1ff9af)_0x2b8b4c('[翰林院-迁移]\x20用户确认迁移,正在清空旧宝库:\x20'+_0x4a729b[_0x356b03(0x111)],_0x356b03(0xc6)),await purgeStorage(_0x4a729b['oldId']),_0xd6ddbd=_0x4a729b['newId'],_0x2b8b4c(_0x356b03(0x94)+_0xd6ddbd,_0x356b03(0xd1));else return _0x2b8b4c(_0x356b03(0xac),_0x356b03(0xe2)),toastr[_0x356b03(0xe2)](_0x356b03(0xf8)),{'success':![],'error':_0x356b03(0xbf)};}if(!_0xd6ddbd)throw new Error(_0x356b03(0xe6));_0x2b8b4c(_0x356b03(0xaa)+_0xd6ddbd,_0x356b03(0xe2));const _0x55b35a=[],_0x27aff8=context[_0x356b03(0xb0)];for(const _0x1f3e15 of _0x22f33d){const _0x1dea84=(_0x1f3e15['mes']||'')[_0x356b03(0xcf)](/<[^>]*>/g,'')['trim']();if(_0x1dea84[_0x356b03(0xe1)]===0x0)continue;let _0x5d96cb;if(_0x1f3e15['floor']!==undefined&&_0x1f3e15[_0x356b03(0xd2)]!==null)_0x5d96cb=_0x1f3e15[_0x356b03(0xd2)];else{const _0xb70902=_0x27aff8[_0x356b03(0xbe)](_0x44b7e9=>_0x44b7e9===_0x1f3e15);_0x5d96cb=_0xb70902!==-0x1?_0xb70902+0x1:-0x1;}const _0x834f72=new Date(_0x1f3e15[_0x356b03(0xc1)]),_0x2dc978=isNaN(_0x834f72['getTime']())?new Date()[_0x356b03(0x91)]():_0x834f72['toISOString'](),_0x19b01d=splitIntoChunks(_0x1dea84,_0x356b03(0xc4),{'floor':_0x5d96cb,'is_user':_0x1f3e15[_0x356b03(0x130)],'timestamp':_0x2dc978});_0x55b35a[_0x356b03(0x119)](..._0x19b01d);}if(_0x55b35a[_0x356b03(0xe1)]===0x0)return{'success':!![],'count':0x0};_0x2b8b4c(_0x356b03(0xcb)+_0x22f33d[_0x356b03(0xe1)]+'\x20条消息分解为\x20'+_0x55b35a[_0x356b03(0xe1)]+_0x356b03(0xc0),_0x356b03(0xe2));const _0x54e353=settings['retrieval'][_0x356b03(0xcc)]||0x5;let _0x2a698f=0x0;for(let _0x45cfbd=0x0;_0x45cfbd<_0x55b35a[_0x356b03(0xe1)];_0x45cfbd+=_0x54e353){const _0x37e7d9=_0x55b35a[_0x356b03(0x107)](_0x45cfbd,_0x45cfbd+_0x54e353),_0x5641a8=_0x37e7d9['map'](_0x45b3f7=>_0x45b3f7[_0x356b03(0x139)]),_0xfc6e2e=await getEmbeddings(_0x5641a8);if(_0x37e7d9[_0x356b03(0xe1)]!==_0xfc6e2e[_0x356b03(0xe1)])throw new Error(_0x356b03(0x9a));const _0x579951=_0x37e7d9['map']((_0xa2ff,_0x1dea0d)=>({..._0xa2ff,'vector':_0xfc6e2e[_0x1dea0d]}));await insertVectors(_0x579951,null,_0xd6ddbd),_0x2a698f+=_0x37e7d9[_0x356b03(0xe1)];}if(_0x14e488){const _0x331fe0=_0x14e488[_0x356b03(0xb3)]===0x0?context[_0x356b03(0xb0)][_0x356b03(0xe1)]:_0x14e488[_0x356b03(0xb3)];settings[_0x356b03(0x12e)][_0xd6ddbd]={'start':_0x14e488['start'],'end':_0x331fe0,'timestamp':new Date()[_0x356b03(0x91)]()},saveSettings(),_0x2b8b4c('[翰林院-核心]\x20已为宝库\x20'+_0xd6ddbd+_0x356b03(0xce)+_0x14e488['start']+'-'+_0x331fe0,_0x356b03(0xe2));}_0x2b8b4c('[翰林院-核心]\x20聊天记录凝识完成,成功插入\x20'+_0x2a698f+_0x356b03(0xd8),_0x356b03(0xd1));const _0x1a2bc3=_0x22f33d[_0x356b03(0xb7)](_0x20951d=>{const _0x48825d=_0x356b03,_0x183861=_0x27aff8['findIndex'](_0x15e3f6=>_0x15e3f6===_0x20951d),_0x1bc9d5=_0x183861!==-0x1?_0x183861+0x1:-0x1,_0x536c78=_0x20951d[_0x48825d(0x130)]?'用户':getCharacterName()||'AI';return'['+_0x536c78+_0x48825d(0xf9)+_0x1bc9d5+']\x20的消息已成功凝识。';});return{'success':!![],'count':_0x2a698f,'messages':_0x1a2bc3};}catch(_0x455aa4){return console[_0x356b03(0xe0)]('[翰林院-核心]\x20processCondensation\x20失败:',_0x455aa4),_0x2b8b4c(_0x356b03(0xb2)+_0x455aa4['message'],'error'),{'success':![],'error':_0x455aa4[_0x356b03(0xd0)]};}}async function rerankResults(_0x5e074d,_0x1b25ba,_0x42f666){const _0x5b3dee=_0x4a685c;let _0x5c181e=_0x5e074d;if(_0x42f666[_0x5b3dee(0x113)][_0x5b3dee(0x106)]&&_0x5e074d[_0x5b3dee(0xe1)]>0x0){console[_0x5b3dee(0x109)]('[翰林院-Rerank]\x20开始外部API重排序...');try{const _0x431fb8=_0x5e074d[_0x5b3dee(0xb7)](_0xfb4d56=>_0xfb4d56[_0x5b3dee(0x139)]),_0x23b130=await executeRerank(_0x1b25ba,_0x431fb8,_0x42f666['rerank']),_0x388154=_0x5e074d[_0x5b3dee(0xb7)]((_0x1097ea,_0x3e05a0)=>({..._0x1097ea,'original_index':_0x3e05a0}));_0x5c181e=_0x388154[_0x5b3dee(0xb7)](_0x6a3183=>{const _0x32a263=_0x5b3dee,_0x227e2e=_0x23b130[_0x32a263(0x95)][_0x32a263(0xf3)](_0x2f0a91=>_0x2f0a91[_0x32a263(0xb4)]===_0x6a3183['original_index']),_0x52d2ab=_0x227e2e?_0x227e2e[_0x32a263(0xaf)]:0x0;return{..._0x6a3183,'rerank_score':_0x52d2ab};});if(_0x42f666[_0x5b3dee(0x113)][_0x5b3dee(0x110)])showNotification(_0x5b3dee(0xfd),_0x5b3dee(0xd1));}catch(_0x13906d){console[_0x5b3dee(0xe0)](_0x5b3dee(0x9c),_0x13906d);if(_0x42f666[_0x5b3dee(0x113)]['notify'])showNotification(_0x5b3dee(0xcd)+_0x13906d['message'],_0x5b3dee(0xe0));_0x5c181e[_0x5b3dee(0xc3)](_0x496d72=>_0x496d72[_0x5b3dee(0xae)]=0x0);}}else _0x5c181e[_0x5b3dee(0xc3)](_0xc97ea=>_0xc97ea['rerank_score']=0x0);console[_0x5b3dee(0x109)](_0x5b3dee(0x13c));const _0xb7160d=context[_0x5b3dee(0xb0)]['length'],_0x3cddaa=_0x42f666[_0x5b3dee(0x113)]['hybrid_alpha'],_0x39956b=_0x5c181e[_0x5b3dee(0xb7)](_0x2efa71=>{const _0x473219=_0x5b3dee;let _0x3c1ede=0x1;const _0x4c36ba=_0x2efa71[_0x473219(0x142)]||{};switch(_0x4c36ba[_0x473219(0x135)]){case _0x473219(0x120):_0x3c1ede*=1.2;break;case _0x473219(0xb9):_0x3c1ede*=1.1;break;case _0x473219(0xc4):if(_0x4c36ba[_0x473219(0xd2)]&&_0xb7160d>0x0){const _0x14ba91=_0x4c36ba[_0x473219(0xd2)]/_0xb7160d;_0x3c1ede*=0x1+_0x14ba91;}break;}const _0x834b14=_0x2efa71[_0x473219(0xae)]*_0x3cddaa+(_0x2efa71[_0x473219(0x93)]||0x0)*(0x1-_0x3cddaa),_0x51735d=_0x834b14*_0x3c1ede;return{..._0x2efa71,'final_score':_0x51735d};});return _0x39956b[_0x5b3dee(0x121)]((_0x3c0b60,_0x57fa75)=>(_0x57fa75[_0x5b3dee(0x11b)]||0x0)-(_0x3c0b60[_0x5b3dee(0x11b)]||0x0)),console[_0x5b3dee(0x109)](_0x5b3dee(0xa9)),_0x39956b[_0x5b3dee(0x107)](0x0,_0x42f666[_0x5b3dee(0x113)][_0x5b3dee(0x96)]);}async function rearrangeChat(_0xf724a6,_0x492ad2,_0x3a3b16,_0x1faf8b){const _0x18428b=_0x4a685c;setExtensionPrompt('HANLINYUAN_RAG','',settings[_0x18428b(0xdb)][_0x18428b(0x92)],settings[_0x18428b(0xdb)][_0x18428b(0xf1)],![],settings[_0x18428b(0xdb)]['depth_role']);if(_0x1faf8b===_0x18428b(0xca)||!settings[_0x18428b(0x11e)][_0x18428b(0x106)])return;const _0x17cd1f=_0xf724a6['slice'](-settings[_0x18428b(0xa1)]['queryMessageCount']);if(_0x17cd1f['length']===0x0)return;const _0x21f846=_0x17cd1f['map'](_0x2c4f91=>_0x2c4f91['mes'])['join']('\x20')['replace'](/<[^>]*>/g,'')[_0x18428b(0xde)]();if(!_0x21f846)return;try{const _0x261782=await queryVectors(_0x21f846);if(_0x261782['length']===0x0)return;const _0xb0ec62=await rerankResults(_0x261782,_0x21f846,settings);if(_0xb0ec62[_0x18428b(0xe1)]===0x0)return;const _0x7ecfdb=_0xb0ec62[_0x18428b(0xb7)](_0x58d706=>_0x58d706[_0x18428b(0x139)])[_0x18428b(0x10c)]('\x0a\x0a'),_0xca4d52=settings[_0x18428b(0xdb)][_0x18428b(0x99)][_0x18428b(0xcf)](_0x18428b(0xbb),_0x7ecfdb);setExtensionPrompt(_0x18428b(0x13a),_0xca4d52,settings[_0x18428b(0xdb)][_0x18428b(0x92)],settings[_0x18428b(0xdb)]['depth'],![],settings['injection'][_0x18428b(0x100)]);}catch(_0x2c9546){console['error'](_0x18428b(0xa6),_0x2c9546);if(settings[_0x18428b(0x11e)][_0x18428b(0x110)])showNotification(_0x18428b(0xa5)+_0x2c9546[_0x18428b(0xd0)],_0x18428b(0xe0));}}