diff --git a/core/rag-processor.js b/core/rag-processor.js index 21d61ab..f66b36e 100644 --- a/core/rag-processor.js +++ b/core/rag-processor.js @@ -1 +1 @@ -'use strict';const _0x15e62c=_0x34fe;(function(_0x53f245,_0x17ffe5){const _0x64772=_0x34fe,_0x2a8240=_0x53f245();while(!![]){try{const _0x1b4257=-parseInt(_0x64772(0x1f3))/0x1+parseInt(_0x64772(0x24a))/0x2*(-parseInt(_0x64772(0x287))/0x3)+parseInt(_0x64772(0x215))/0x4+parseInt(_0x64772(0x256))/0x5+parseInt(_0x64772(0x21a))/0x6*(parseInt(_0x64772(0x289))/0x7)+parseInt(_0x64772(0x23a))/0x8+parseInt(_0x64772(0x206))/0x9*(parseInt(_0x64772(0x247))/0xa);if(_0x1b4257===_0x17ffe5)break;else _0x2a8240['push'](_0x2a8240['shift']());}catch(_0x2bfe5d){_0x2a8240['push'](_0x2a8240['shift']());}}}(_0x54fb,0xddd86));function _0x34fe(_0x2ba62a,_0x2182de){const _0x54fb88=_0x54fb();return _0x34fe=function(_0x34fe84,_0x22a28a){_0x34fe84=_0x34fe84-0x1c8;let _0x55718c=_0x54fb88[_0x34fe84];return _0x55718c;},_0x34fe(_0x2ba62a,_0x2182de);}import{extension_prompt_roles,setExtensionPrompt}from'/script.js';import*as _0x9e3022 from'./utils/context-utils.js';import{getCollectionIdInfo}from'./utils/context-utils.js';import{defaultSettings as _0x3bdfc7}from'./rag-settings.js';import*as _0xd6a0a7 from'./ingestion-manager.js';const MODULE_NAME=_0x15e62c(0x246),OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME='vectors_rearrangeChat';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 _0x2ee6a0=_0x15e62c;context=SillyTavern['getContext']();if(!context){console[_0x2ee6a0(0x1db)](_0x2ee6a0(0x20d));return;}settings=getSettings();const _0x186fb3=window[OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME];typeof _0x186fb3==='function'?(window[OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME]=async function(..._0x373527){await rearrangeChat(..._0x373527),await _0x186fb3(..._0x373527);},console[_0x2ee6a0(0x1fb)](_0x2ee6a0(0x1d1)+OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME)):(window[OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME]=rearrangeChat,console[_0x2ee6a0(0x1fb)](_0x2ee6a0(0x26e)+OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME));}async function ingestTextToHanlinyuan(_0x1e2a9e,_0x2e6f35='manual',_0x3936ce='',_0x789001=()=>{},_0x288dff=null,_0x122101=()=>{},_0x141d48=()=>{},_0x108b51=null,_0x3ae753=0x0,_0x3c6299=null){const _0x2cf0fc=_0x15e62c;if(!_0x1e2a9e||!_0x1e2a9e[_0x2cf0fc(0x255)]())return{'success':![],'error':_0x2cf0fc(0x1e1)};if(!settings)return{'success':![],'error':'核心未初始化'};try{let _0x104ff8=await getCollectionId();const _0x42ecf4=getCollectionIdInfo();if(_0x42ecf4[_0x2cf0fc(0x234)]&&_0x42ecf4[_0x2cf0fc(0x234)]===_0x104ff8&&_0x42ecf4[_0x2cf0fc(0x234)]!==_0x42ecf4[_0x2cf0fc(0x1f5)]){const _0x38d735=confirm(_0x2cf0fc(0x23e));if(_0x38d735)_0x122101(_0x2cf0fc(0x261)+_0x42ecf4['oldId'],_0x2cf0fc(0x245)),await purgeStorage(_0x42ecf4[_0x2cf0fc(0x234)]),_0x104ff8=_0x42ecf4[_0x2cf0fc(0x1f5)],_0x122101('[翰林院-迁移]\x20旧宝库已清空,将向新宝库写入数据:\x20'+_0x104ff8,_0x2cf0fc(0x241));else return _0x122101(_0x2cf0fc(0x1e3),_0x2cf0fc(0x27a)),toastr[_0x2cf0fc(0x27a)](_0x2cf0fc(0x214)),{'success':![],'error':_0x2cf0fc(0x263)};}if(!_0x104ff8)throw new Error(_0x2cf0fc(0x231));_0x122101(_0x2cf0fc(0x290)+_0x104ff8,_0x2cf0fc(0x27a)),_0x789001({'message':'正在智能分块...','processed':0x0,'total':0x1});const _0x356e07=splitIntoChunks(_0x1e2a9e,_0x2e6f35,{'sourceName':_0x3936ce}),_0x5643c2=_0x356e07[_0x2cf0fc(0x294)];if(_0x288dff?.[_0x2cf0fc(0x26a)])throw new Error(_0x2cf0fc(0x207));_0x122101(_0x2cf0fc(0x1eb)+(_0x3936ce||_0x2e6f35)+_0x2cf0fc(0x20a)+_0x5643c2+_0x2cf0fc(0x216),'info');if(_0x5643c2===0x0)return{'success':!![],'count':0x0};const _0x381bc9=settings[_0x2cf0fc(0x27e)][_0x2cf0fc(0x251)]||0x5;let _0x202ed3=_0x3ae753;for(let _0x443ddc=_0x3ae753;_0x443ddc<_0x5643c2;_0x443ddc+=_0x381bc9){if(_0x288dff?.['aborted'])throw new Error('AbortError');const _0x2b61e8=_0x356e07[_0x2cf0fc(0x1ed)](_0x443ddc,_0x443ddc+_0x381bc9);_0x789001({'message':_0x2cf0fc(0x267)+(_0x443ddc+0x1)+'-'+(_0x443ddc+_0x2b61e8[_0x2cf0fc(0x294)])+'\x20块','processed':_0x443ddc,'total':_0x5643c2});const _0x57cb6e=_0x2b61e8[_0x2cf0fc(0x1f2)](_0x5e9dd9=>_0x5e9dd9[_0x2cf0fc(0x24b)]),_0x5ac3d9=await getEmbeddings(_0x57cb6e,_0x288dff);if(_0x288dff?.[_0x2cf0fc(0x26a)])throw new Error(_0x2cf0fc(0x207));if(_0x2b61e8[_0x2cf0fc(0x294)]!==_0x5ac3d9[_0x2cf0fc(0x294)])throw new Error(_0x2cf0fc(0x1e4));const _0x3d6e11=_0x2b61e8['map']((_0x325d88,_0x3da300)=>({..._0x325d88,'vector':_0x5ac3d9[_0x3da300]}));await insertVectors(_0x3d6e11,_0x288dff,_0x104ff8),_0x202ed3+=_0x2b61e8[_0x2cf0fc(0x294)],_0x108b51&&_0xd6a0a7[_0x2cf0fc(0x1e9)](_0x108b51,_0x202ed3,_0x5643c2),_0x141d48();}_0x108b51&&_0xd6a0a7[_0x2cf0fc(0x25a)](_0x108b51);if(_0x3c6299){const _0x3712b6=await getCollectionId(),_0x2489c6=_0x3c6299[_0x2cf0fc(0x1d4)]===0x0?context['chat']['length']:_0x3c6299[_0x2cf0fc(0x1d4)];settings[_0x2cf0fc(0x213)][_0x3712b6]={'start':_0x3c6299[_0x2cf0fc(0x260)],'end':_0x2489c6,'timestamp':new Date()[_0x2cf0fc(0x1ef)]()},saveSettings(),_0x122101(_0x2cf0fc(0x22f)+_0x3712b6+_0x2cf0fc(0x273)+_0x3c6299[_0x2cf0fc(0x260)]+'-'+_0x2489c6,'info');}return _0x122101(_0x2cf0fc(0x26c)+_0x202ed3+'\x20个向量条目。',_0x2cf0fc(0x241)),{'success':!![],'count':_0x202ed3};}catch(_0x6fed71){if(_0x6fed71['name']===_0x2cf0fc(0x207)){_0x122101(_0x2cf0fc(0x26f),_0x2cf0fc(0x245));throw _0x6fed71;}return console['error'](_0x2cf0fc(0x24d),_0x6fed71),_0x122101(_0x2cf0fc(0x258)+_0x6fed71['message'],_0x2cf0fc(0x1db)),{'success':![],'error':_0x6fed71[_0x2cf0fc(0x1da)]};}}function getSettings(){const _0x59823d=_0x15e62c;if(!context||!context['extensionSettings'])return structuredClone(_0x3bdfc7);let _0x568ae7=context[_0x59823d(0x1e8)][MODULE_NAME];!_0x568ae7&&(_0x568ae7={},context['extensionSettings'][MODULE_NAME]=_0x568ae7);_0x568ae7[_0x59823d(0x213)]===undefined&&(_0x568ae7['condensationHistory']={});for(const _0x154027 in _0x3bdfc7){if(_0x568ae7[_0x154027]===undefined)_0x568ae7[_0x154027]=structuredClone(_0x3bdfc7[_0x154027]);else{if(typeof _0x3bdfc7[_0x154027]===_0x59823d(0x271)&&!Array[_0x59823d(0x1e6)](_0x3bdfc7[_0x154027])&&_0x3bdfc7[_0x154027]!==null)for(const _0x3e2475 in _0x3bdfc7[_0x154027]){_0x568ae7[_0x154027][_0x3e2475]===undefined&&(_0x568ae7[_0x154027][_0x3e2475]=_0x3bdfc7[_0x154027][_0x3e2475]);}}}return _0x568ae7;}function saveSettings(){const _0x59c09a=_0x15e62c;if(context)context[_0x59c09a(0x25e)]();}function resetSettings(){const _0x4a550e=_0x15e62c;context&&(context[_0x4a550e(0x1e8)][MODULE_NAME]=structuredClone(_0x3bdfc7),saveSettings());}function showNotification(_0xe4c44e,_0x4d3a8a=_0x15e62c(0x27a)){toastr[_0x4d3a8a](_0xe4c44e);}function getTagForSource(_0x506730){const _0x3531d7=_0x15e62c;switch(_0x506730){case _0x3531d7(0x27d):return'聊天记录';case _0x3531d7(0x21c):return _0x3531d7(0x281);case _0x3531d7(0x1f0):return _0x3531d7(0x25c);case'novel':return'小说录入';default:return'资料';}}function splitIntoChunks(_0x3b0d22,_0xd4abc3,_0x2f2acd={}){const _0x4a6b88=_0x15e62c;switch(_0xd4abc3){case _0x4a6b88(0x242):return _chunkForNovel(_0x3b0d22,_0x2f2acd);case _0x4a6b88(0x27d):return _chunkForChatHistory(_0x3b0d22,_0x2f2acd);case _0x4a6b88(0x21c):return _chunkForLorebook(_0x3b0d22,_0x2f2acd);case _0x4a6b88(0x1f0):return _chunkForManual(_0x3b0d22,_0x2f2acd);default:console[_0x4a6b88(0x245)](_0x4a6b88(0x1d6)+_0xd4abc3+'\x27,使用通用分块逻辑。');return _chunkForManual(_0x3b0d22,{..._0x2f2acd,'sourceName':_0x2f2acd[_0x4a6b88(0x288)]||_0x4a6b88(0x278)});}}function _chunkForNovel(_0x4f49d6,_0x418831){const _0x551641=_0x15e62c,{chunkSize:_0xe6bc3b,overlap:_0x544d94}=settings[_0x551641(0x269)],{sourceName:sourceName='小说'}=_0x418831,_0x1ec14c=[];if(!_0x4f49d6||_0xe6bc3b<=0x0)return _0x1ec14c;const _0x1b4c38=/(第\s*[一二三四五六七八九十百千万零\d]+\s*卷)/gim,_0x39716e=/(第\s*[一二三四五六七八九十百千万零\d]+\s*[章回节部])|^(Chapter\s+\d+)/gim;let _0x5110a9=0x0;const _0x1df4d7=_0x4f49d6[_0x551641(0x262)]('\x0a');let _0x2f62f4=_0x551641(0x1f1),_0x5191d9=_0x551641(0x274),_0x4672e7=[];function _0x20ad86(){const _0x484600=_0x551641;if(_0x4672e7['length']===0x0)return;const _0x21e839=_0x4672e7[_0x484600(0x275)]('\x0a');let _0x2ff49d=0x0,_0x47a873=0x1;while(_0x2ff49d<_0x21e839[_0x484600(0x294)]){const _0x2258ef=Math[_0x484600(0x202)](_0x2ff49d+_0xe6bc3b,_0x21e839[_0x484600(0x294)]),_0x596344=_0x21e839[_0x484600(0x264)](_0x2ff49d,_0x2258ef);if(_0x596344['trim']()[_0x484600(0x294)]>0x0){const _0x1f6c1a={'source':_0x484600(0x242),'sourceName':sourceName,'timestamp':new Date()[_0x484600(0x1ef)](),'globalIndex':_0x5110a9++,'volume':_0x2f62f4,'chapter':_0x5191d9,'section':_0x47a873},_0x39135f=getTagForSource(_0x484600(0x242)),_0x19e3f0=_0x484600(0x20e)+sourceName+',\x20'+_0x2f62f4+',\x20'+_0x5191d9+_0x484600(0x224)+_0x47a873+'节]',_0x47df27='<'+_0x39135f+'>\x0a'+_0x19e3f0+'\x0a'+_0x596344+_0x484600(0x257)+_0x39135f+'>';_0x1ec14c[_0x484600(0x210)]({'text':_0x47df27,'metadata':_0x1f6c1a}),_0x47a873++;}_0x2ff49d+=_0xe6bc3b-_0x544d94;if(_0x2ff49d>=_0x21e839[_0x484600(0x294)])break;}_0x4672e7=[];}for(const _0x5734f1 of _0x1df4d7){const _0x2eb958=_0x5734f1['trim']();if(_0x1b4c38[_0x551641(0x1dc)](_0x2eb958))_0x20ad86(),_0x2f62f4=_0x2eb958,_0x5191d9='第1章';else _0x39716e[_0x551641(0x1dc)](_0x2eb958)?(_0x20ad86(),_0x5191d9=_0x2eb958):_0x4672e7[_0x551641(0x210)](_0x5734f1);}_0x20ad86();if(_0x1ec14c[_0x551641(0x294)]===0x0&&_0x4f49d6[_0x551641(0x294)]>0x0){let _0x19f8a1=0x0,_0x11f28c=0x1;while(_0x19f8a1<_0x4f49d6['length']){const _0x56b1b1=Math[_0x551641(0x202)](_0x19f8a1+_0xe6bc3b,_0x4f49d6[_0x551641(0x294)]),_0x2e8158=_0x4f49d6['substring'](_0x19f8a1,_0x56b1b1),_0x4dbfd7={'source':'novel','sourceName':sourceName,'timestamp':new Date()[_0x551641(0x1ef)](),'globalIndex':_0x1ec14c['length'],'volume':_0x551641(0x1f1),'chapter':_0x551641(0x274),'section':_0x11f28c},_0x5960b1=getTagForSource('novel'),_0x43cdda=_0x551641(0x20e)+sourceName+_0x551641(0x208)+_0x11f28c+'节]',_0x230a9a='<'+_0x5960b1+'>\x0a'+_0x43cdda+'\x0a'+_0x2e8158+_0x551641(0x257)+_0x5960b1+'>';_0x1ec14c['push']({'text':_0x230a9a,'metadata':_0x4dbfd7}),_0x11f28c++,_0x19f8a1+=_0xe6bc3b-_0x544d94;}}return _0x1ec14c;}function _chunkForChatHistory(_0x394318,_0x119e58){const _0x14169e=_0x15e62c,{chunkSize:_0x2e7f00,overlap:_0x55219d}=settings[_0x14169e(0x269)],{floor:_0x51910e,is_user:_0x4b6b8e,timestamp:_0x3f0e54}=_0x119e58,_0x32f286=[];if(!_0x394318||_0x2e7f00<=0x0)return _0x32f286;let _0x10e476=0x1,_0x3725b9=0x0;while(_0x3725b9<_0x394318[_0x14169e(0x294)]){const _0x2f43fc=Math[_0x14169e(0x202)](_0x3725b9+_0x2e7f00,_0x394318['length']),_0x2af09d=_0x394318[_0x14169e(0x264)](_0x3725b9,_0x2f43fc),_0x13323d=_0x14169e(0x25d)+_0x51910e+',\x20第'+_0x10e476+_0x14169e(0x23b),_0x239a4e=getTagForSource(_0x14169e(0x27d)),_0x47f274='<'+_0x239a4e+'>\x0a'+_0x13323d+'\x0a'+_0x2af09d+_0x14169e(0x257)+_0x239a4e+'>';_0x32f286[_0x14169e(0x210)]({'text':_0x47f274,'metadata':{'source':_0x14169e(0x27d),'sourceName':_0x14169e(0x1d3)+_0x51910e,'floor':_0x51910e,'part':_0x10e476,'is_user':_0x4b6b8e,'timestamp':_0x3f0e54}}),_0x10e476++,_0x3725b9+=_0x2e7f00-_0x55219d;if(_0x3725b9>=_0x394318[_0x14169e(0x294)])break;}return _0x32f286;}function _chunkForLorebook(_0x4bc8a7,_0x15b01a){const _0x1b917c=_0x15e62c,{chunkSize:_0x3863ce,overlap:_0x2de683}=settings[_0x1b917c(0x269)],{sourceName:sourceName=_0x1b917c(0x222)}=_0x15b01a,_0x2d988a=[];if(!_0x4bc8a7||_0x3863ce<=0x0)return _0x2d988a;let _0x3643cb=0x1,_0x381b98=0x0;while(_0x381b98<_0x4bc8a7[_0x1b917c(0x294)]){const _0x4aed32=Math[_0x1b917c(0x202)](_0x381b98+_0x3863ce,_0x4bc8a7[_0x1b917c(0x294)]),_0x4428b0=_0x4bc8a7[_0x1b917c(0x264)](_0x381b98,_0x4aed32),_0x41b6fb=_0x1b917c(0x237)+sourceName+_0x1b917c(0x224)+_0x3643cb+_0x1b917c(0x23b),_0x484508=getTagForSource(_0x1b917c(0x21c)),_0x5de0e5='<'+_0x484508+'>\x0a'+_0x41b6fb+'\x0a'+_0x4428b0+_0x1b917c(0x257)+_0x484508+'>';_0x2d988a['push']({'text':_0x5de0e5,'metadata':{'source':_0x1b917c(0x21c),'sourceName':sourceName,'part':_0x3643cb,'timestamp':new Date()[_0x1b917c(0x1ef)]()}}),_0x3643cb++,_0x381b98+=_0x3863ce-_0x2de683;if(_0x381b98>=_0x4bc8a7['length'])break;}return _0x2d988a;}function _chunkForManual(_0x2575e5,_0x1ca7a1){const _0x470a79=_0x15e62c,{chunkSize:_0xacc0b4,overlap:_0x38afff}=settings[_0x470a79(0x269)],{sourceName:sourceName=_0x470a79(0x25c)}=_0x1ca7a1,_0x3bfd31=[];if(!_0x2575e5||_0xacc0b4<=0x0)return _0x3bfd31;const _0x538f00=new Date(),_0x24f63e=_0x538f00[_0x470a79(0x218)]('zh-CN');let _0x94d7a1=0x1,_0x323d4e=0x0;while(_0x323d4e<_0x2575e5[_0x470a79(0x294)]){const _0x4a9836=Math[_0x470a79(0x202)](_0x323d4e+_0xacc0b4,_0x2575e5[_0x470a79(0x294)]),_0x290aef=_0x2575e5[_0x470a79(0x264)](_0x323d4e,_0x4a9836),_0x3f182b=_0x470a79(0x20e)+sourceName+_0x470a79(0x1f8)+_0x24f63e+_0x470a79(0x224)+_0x94d7a1+_0x470a79(0x23b),_0x1e7520=getTagForSource(_0x470a79(0x1f0)),_0x4d494c='<'+_0x1e7520+'>\x0a'+_0x3f182b+'\x0a'+_0x290aef+_0x470a79(0x257)+_0x1e7520+'>';_0x3bfd31['push']({'text':_0x4d494c,'metadata':{'source':'manual','sourceName':sourceName,'part':_0x94d7a1,'timestamp':_0x538f00['toISOString']()}}),_0x94d7a1++,_0x323d4e+=_0xacc0b4-_0x38afff;if(_0x323d4e>=_0x2575e5[_0x470a79(0x294)])break;}return _0x3bfd31;}import{getCollectionId as _0x318e67,getCharacterName}from'./utils/context-utils.js';async function getCollectionId(){return lockedCollectionId||await _0x318e67();}async function toggleSessionLock(){return lockedCollectionId?(lockedCollectionId=null,![]):(lockedCollectionId=await _0x318e67(),!![]);}function isSessionLocked(){return lockedCollectionId!==null;}function getLockedSessionInfo(){const _0x2ffe3c=_0x15e62c;if(!lockedCollectionId)return null;return{'id':lockedCollectionId,'name':'(已锁定:\x20'+lockedCollectionId[_0x2ffe3c(0x264)](0x0,0x8)+_0x2ffe3c(0x1d5)};}function generateHash(_0x31ee95){const _0x56008a=_0x15e62c;let _0x102d59=0x0;for(let _0x1fac9c=0x0;_0x1fac9c<_0x31ee95[_0x56008a(0x294)];_0x1fac9c++){const _0x252ac2=_0x31ee95['charCodeAt'](_0x1fac9c);_0x102d59=(_0x102d59<<0x5)-_0x102d59+_0x252ac2,_0x102d59=_0x102d59&_0x102d59;}return Math[_0x56008a(0x27b)](_0x102d59)['toString'](0x24);}function getSanitizedBaseUrl(_0x15a32c){const _0x5ab6f5=_0x15e62c;let _0x44e389=_0x15a32c['trim']();return _0x44e389[_0x5ab6f5(0x1f4)]('/')&&(_0x44e389=_0x44e389['slice'](0x0,-0x1)),_0x44e389[_0x5ab6f5(0x1f4)](_0x5ab6f5(0x276))&&(_0x44e389=_0x44e389[_0x5ab6f5(0x1ed)](0x0,-0x3)),_0x44e389[_0x5ab6f5(0x1f4)]('/embeddings')&&(_0x44e389=_0x44e389['slice'](0x0,-0xb)),_0x44e389;}async function fetchEmbeddingModels(){const _0x1c4aee=_0x15e62c,{apiKey:_0x29bd72}=settings[_0x1c4aee(0x27e)],_0x1156b9=getApiEndpointUrl(!![]);if(!_0x1156b9||!_0x29bd72)throw new Error(_0x1c4aee(0x227));const _0x389055=getSanitizedBaseUrl(_0x1156b9),_0x3e1cf0=_0x389055+_0x1c4aee(0x22a);console[_0x1c4aee(0x1fb)](_0x1c4aee(0x282)+_0x3e1cf0+_0x1c4aee(0x23c));const _0x4607cb=await fetch(_0x3e1cf0,{'method':_0x1c4aee(0x28e),'headers':getApiHeaders()});if(!_0x4607cb['ok']){const _0x3d212a=await _0x4607cb[_0x1c4aee(0x24b)]();throw new Error(_0x1c4aee(0x1e5)+_0x4607cb['status']+_0x1c4aee(0x284)+_0x3d212a);}const _0x313c84=await _0x4607cb[_0x1c4aee(0x200)]();if(!_0x313c84['data']||!Array['isArray'](_0x313c84[_0x1c4aee(0x292)]))throw new Error(_0x1c4aee(0x1cc));return _0x313c84[_0x1c4aee(0x292)]['map'](_0x114ad5=>_0x114ad5['id'])[_0x1c4aee(0x266)]();}function getRerankBaseUrl(_0x304df0){const _0x3b80ed=_0x15e62c;let _0x3b6928=_0x304df0[_0x3b80ed(0x255)]();return _0x3b6928[_0x3b80ed(0x1f4)]('/')&&(_0x3b6928=_0x3b6928[_0x3b80ed(0x1ed)](0x0,-0x1)),_0x3b6928[_0x3b80ed(0x1f4)]('/v1')&&(_0x3b6928=_0x3b6928[_0x3b80ed(0x1ed)](0x0,-0x3)),_0x3b6928['endsWith']('/rerank')&&(_0x3b6928=_0x3b6928[_0x3b80ed(0x1ed)](0x0,-0x7)),_0x3b6928;}async function fetchRerankModels(){const _0x1a16b3=_0x15e62c,{url:_0x3cbfd8,apiKey:_0xfac694}=settings[_0x1a16b3(0x235)];if(!_0x3cbfd8||!_0xfac694)throw new Error(_0x1a16b3(0x1cd));const _0x4eaaf4=getRerankBaseUrl(_0x3cbfd8),_0x13dbd3=_0x4eaaf4+_0x1a16b3(0x22a);console[_0x1a16b3(0x1fb)](_0x1a16b3(0x240)+_0x13dbd3+'\x20获取模型列表...');const _0x143618=await fetch(_0x13dbd3,{'method':_0x1a16b3(0x28e),'headers':{'Authorization':'Bearer\x20'+_0xfac694}});if(!_0x143618['ok']){const _0x290ae6=await _0x143618['text']();throw new Error('获取Rerank模型列表失败\x20('+_0x143618[_0x1a16b3(0x265)]+'):\x20'+_0x290ae6);}const _0x38582f=await _0x143618[_0x1a16b3(0x200)]();if(!_0x38582f[_0x1a16b3(0x292)]||!Array[_0x1a16b3(0x1e6)](_0x38582f['data']))throw new Error(_0x1a16b3(0x1ea));return _0x38582f[_0x1a16b3(0x292)][_0x1a16b3(0x1f2)](_0x5857ee=>_0x5857ee['id'])[_0x1a16b3(0x266)]();}function getApiEndpointUrl(_0x328ab9=![]){const _0x5de505=_0x15e62c,{apiEndpoint:_0x576868,customApiUrl:_0x5c3d2f}=settings['retrieval'];let _0x44021f;switch(_0x576868){case _0x5de505(0x1c8):_0x44021f=_0x5de505(0x204);break;case _0x5de505(0x220):case _0x5de505(0x1e0):_0x44021f=_0x5c3d2f;break;default:_0x44021f='https://api.openai.com';break;}if(_0x328ab9)return _0x44021f;return getSanitizedBaseUrl(_0x44021f)+'/v1/embeddings';}function getApiHeaders(){const _0x29db03=_0x15e62c,_0x45fe7d={'Content-Type':'application/json'},{apiKey:_0x50de96,apiEndpoint:_0x2ffec1}=settings['retrieval'];switch(_0x2ffec1){case'openai':case _0x29db03(0x1e0):_0x45fe7d[_0x29db03(0x22e)]=_0x29db03(0x232)+_0x50de96;break;case'azure':_0x45fe7d[_0x29db03(0x230)]=_0x50de96;break;}return _0x45fe7d;}function _0x54fb(){const _0x5f2455=[',\x20第1卷,\x20第1章,\x20第','matchThreshold','\x27的文本分割成\x20','filter','user','[翰林院]\x20未能获取SillyTavern上下文,初始化失败。','[来源:\x20','/api/vector/insert','push','maxResults','[翰林院-核心]\x20聊天记录凝识完成,成功插入\x20','condensationHistory','操作已取消。','3560540EFCWlg','\x20个块。','chat','toLocaleString','\x20条消息分解为\x20','7283046xrQAKQ','[翰林院-日志]\x20/api/vector/query\x20响应内容:','lorebook','[翰林院-日志]\x20/api/vector/list\x20响应状态:\x20','[翰林院-核心]\x20processCondensation\x20失败:','忆识存入API错误\x20','azure','unknown','世界书条目','[翰林院-日志]\x20忆识存入API错误:',',\x20第','[翰林院-日志]\x20无法确定要清空的目标集合ID。','template','API\x20URL\x20或\x20Key\x20未提供。','HANLINYUAN_RAG','floor','/v1/models','请先配置API\x20Key','queryMessageCount','[翰林院-日志]\x20开始向量查询\x20(采用最终API交互模式)...','Authorization','[翰林院-核心]\x20已为宝库\x20','api-key','无法确定当前忆识宝库的ID,请确认角色已正确加载。','Bearer\x20','[翰林院-日志]\x20发送到\x20/api/vector/purge\x20的请求体:','oldId','rerank','[翰林院-日志]\x20/api/vector/query\x20响应状态:\x20','[来源:\x20世界书,\x20条目:\x20','POST','is_user','3243728AlaEhs','部分]','\x20获取模型列表...','warning','此操作将清空旧版数据,并开始使用新版数据库。此过程不可逆,是否继续?','condensation','[翰林院-Rerank]\x20正在从\x20','success','novel',']\x20的消息已成功凝识。','score','warn','hanlinyuan-rag-core','90UcrTLZ','findIndex','stringify','44728hbpRzM','text','外部Rerank完成','[翰林院-核心]\x20ingestTextToHanlinyuan\x20失败:','/v1/rerank','[翰林院-核心]\x20聊天记录凝识失败:\x20','[翰林院-核心]\x20已将\x20','batchSize','Rerank失败:\x20','[翰林院-日志]\x20查询目标集合ID:\x20','rerank_score','trim','4279035ytofze','\x0a_0x3b3456['embedding'])),_0x464e1d+_0x53b01b<_0xc53ab0[_0xd1b10c(0x294)]&&await new Promise(_0x2347b2=>setTimeout(_0x2347b2,0xc8));}return _0x1f7190;}async function queryVectors(_0xf0d91b){const _0x371c18=_0x15e62c;console['log'](_0x371c18(0x22d));const _0x3e8d8c=await getCollectionId();console[_0x371c18(0x1fb)](_0x371c18(0x253)+_0x3e8d8c);const _0x4a9c2=(await getEmbeddings([_0xf0d91b]))[0x0],_0x3315e7={'collectionId':_0x3e8d8c,'searchText':_0xf0d91b,'topK':settings['advanced'][_0x371c18(0x211)],'threshold':settings[_0x371c18(0x269)][_0x371c18(0x209)],'source':_0x371c18(0x283),'embeddings':{[_0xf0d91b]:_0x4a9c2}};console[_0x371c18(0x1fb)](_0x371c18(0x286),JSON[_0x371c18(0x249)](_0x3315e7,null,0x2));const _0x373fd9=await fetch(_0x371c18(0x285),{'method':'POST','headers':context[_0x371c18(0x1fc)](),'body':JSON[_0x371c18(0x249)](_0x3315e7)});console['log'](_0x371c18(0x236)+_0x373fd9[_0x371c18(0x265)]);if(!_0x373fd9['ok']){const _0x20e9a8=await _0x373fd9[_0x371c18(0x24b)]();console[_0x371c18(0x1db)](_0x371c18(0x28c),_0x20e9a8);throw new Error('宝库查询API错误\x20'+_0x373fd9[_0x371c18(0x265)]+':\x20'+_0x20e9a8);}const _0x3f49e1=await _0x373fd9[_0x371c18(0x200)]();console[_0x371c18(0x1fb)](_0x371c18(0x21b),_0x3f49e1);const _0x501f90=_0x3f49e1[_0x371c18(0x291)]||_0x3f49e1[_0x371c18(0x28f)]||_0x3f49e1[_0x371c18(0x292)]||[];return console[_0x371c18(0x1fb)](_0x371c18(0x1dd)+_0x501f90['length']+_0x371c18(0x26b)),_0x501f90;}async function insertVectors(_0x4c5497,_0x168e8a=null,_0x5476f7){const _0x450508=_0x15e62c;if(!_0x5476f7){console[_0x450508(0x1db)]('[翰林院-核心]\x20insertVectors被调用时未提供collectionId!'),_0x5476f7=await getCollectionId();if(!_0x5476f7)throw new Error(_0x450508(0x1f9));}if(_0x4c5497[_0x450508(0x294)]===0x0)return{'success':!![],'count':0x0};const _0x544ab5=_0x4c5497[_0x450508(0x1f2)]((_0x17100b,_0x2af16d)=>({'hash':generateHash(_0x17100b['text']+Date[_0x450508(0x1de)]()+_0x2af16d),'text':_0x17100b[_0x450508(0x24b)],'metadata':_0x17100b[_0x450508(0x291)]||{'source':_0x450508(0x221),'timestamp':new Date()[_0x450508(0x1ef)]()}})),_0x4803ae=_0x544ab5[_0x450508(0x27f)]((_0x3f8a8d,_0x3e53ea,_0x58bc42)=>{const _0x51106d=_0x450508;return _0x3f8a8d[_0x3e53ea[_0x51106d(0x24b)]]=_0x4c5497[_0x58bc42][_0x51106d(0x1ce)],_0x3f8a8d;},{}),_0x3293a4={'collectionId':_0x5476f7,'items':_0x544ab5,'source':_0x450508(0x283),'embeddings':_0x4803ae},_0x41cf30=await fetch(_0x450508(0x20f),{'method':_0x450508(0x238),'headers':context['getRequestHeaders'](),'body':JSON[_0x450508(0x249)](_0x3293a4),'signal':_0x168e8a});if(!_0x41cf30['ok']){const _0x217b41=await _0x41cf30[_0x450508(0x24b)]();console[_0x450508(0x1db)](_0x450508(0x223),_0x217b41);throw new Error(_0x450508(0x21f)+_0x41cf30[_0x450508(0x265)]+':\x20'+_0x217b41);}return{'success':!![],'count':_0x544ab5['length']};}async function testApiConnection(){const _0x4b8ac8=_0x15e62c;await getEmbeddings([_0x4b8ac8(0x205)]);}async function getVectorCount(){const _0x2c5f61=_0x15e62c;console[_0x2c5f61(0x1fb)]('[翰林院-日志]\x20开始获取向量总数...');const _0x3518d3=await getCollectionId();console[_0x2c5f61(0x1fb)](_0x2c5f61(0x201)+_0x3518d3);const _0x599d9f={'collectionId':_0x3518d3,'source':'webllm','embeddings':{}};console[_0x2c5f61(0x1fb)](_0x2c5f61(0x25f),JSON[_0x2c5f61(0x249)](_0x599d9f,null,0x2));const _0x583e1f=await fetch(_0x2c5f61(0x1d9),{'method':_0x2c5f61(0x238),'headers':context[_0x2c5f61(0x1fc)](),'body':JSON[_0x2c5f61(0x249)](_0x599d9f)});console[_0x2c5f61(0x1fb)](_0x2c5f61(0x21d)+_0x583e1f[_0x2c5f61(0x265)]);if(!_0x583e1f['ok']){const _0x370f8d=await _0x583e1f['text']();return console[_0x2c5f61(0x1db)](_0x2c5f61(0x259),_0x370f8d),0x0;}const _0x2ea985=await _0x583e1f[_0x2c5f61(0x200)]();let _0x47309b=0x0;if(Array[_0x2c5f61(0x1e6)](_0x2ea985))_0x47309b=_0x2ea985[_0x2c5f61(0x294)];else _0x2ea985&&_0x2ea985[_0x2c5f61(0x1fa)]&&(_0x47309b=_0x2ea985['hashes'][_0x2c5f61(0x294)]);return console[_0x2c5f61(0x1fb)](_0x2c5f61(0x26d)+_0x47309b),_0x47309b;}async function purgeStorage(_0x3150b8=null){const _0x46d2b5=_0x15e62c;console['log']('[翰林院-日志]\x20开始清空宝库...');const _0x57c771=_0x3150b8||await getCollectionId();if(!_0x57c771)return console[_0x46d2b5(0x1db)](_0x46d2b5(0x225)),toastr['error']('无法确定要清空的目标宝库。'),![];console[_0x46d2b5(0x1fb)](_0x46d2b5(0x203)+_0x57c771);const _0x136b97={'collectionId':_0x57c771};console[_0x46d2b5(0x1fb)](_0x46d2b5(0x233),JSON[_0x46d2b5(0x249)](_0x136b97,null,0x2));const _0x1e91cb=await fetch(_0x46d2b5(0x1e7),{'method':'POST','headers':context[_0x46d2b5(0x1fc)](),'body':JSON[_0x46d2b5(0x249)](_0x136b97)});console[_0x46d2b5(0x1fb)](_0x46d2b5(0x28d)+_0x1e91cb[_0x46d2b5(0x265)]);if(!_0x1e91cb['ok']){const _0x1cb584=await _0x1e91cb[_0x46d2b5(0x24b)]();console['error'](_0x46d2b5(0x1f7),_0x1cb584);}else console[_0x46d2b5(0x1fb)](_0x46d2b5(0x1ee));return _0x1e91cb['ok'];}function getMessagesForCondensation(_0x1065a9=null){const _0x83a1f9=_0x15e62c;if(!settings[_0x83a1f9(0x23f)][_0x83a1f9(0x1ca)])return showNotification(_0x83a1f9(0x28b),_0x83a1f9(0x23d)),[];const {layerStart:_0x11c1ea,layerEnd:_0x24dedd}=settings[_0x83a1f9(0x23f)],_0x17369a=_0x1065a9||settings[_0x83a1f9(0x23f)][_0x83a1f9(0x1cb)],_0x2f0db1=context[_0x83a1f9(0x217)][_0x83a1f9(0x294)],_0x3f830e=Math[_0x83a1f9(0x1ff)](0x0,_0x11c1ea-0x1),_0x4a9a18=_0x24dedd===0x0||_0x24dedd>_0x2f0db1?_0x2f0db1:Math[_0x83a1f9(0x202)](_0x2f0db1,_0x24dedd),_0x8a10a3=context[_0x83a1f9(0x217)][_0x83a1f9(0x1ed)](_0x3f830e,_0x4a9a18);return _0x8a10a3[_0x83a1f9(0x20b)](_0x381880=>{const _0x1324fe=_0x83a1f9,_0x4ec271=_0x381880[_0x1324fe(0x239)]===!![],_0x3765a9=_0x381880['is_user']===![];if(!_0x381880['mes']||!_0x381880['mes'][_0x1324fe(0x255)]())return![];return _0x17369a[_0x1324fe(0x20c)]&&_0x4ec271||_0x17369a['ai']&&_0x3765a9;});}async function processCondensation(_0x280f4b,_0x313d4e=()=>{},_0x2e4041=null){const _0x1fd241=_0x15e62c;if(!_0x280f4b||_0x280f4b[_0x1fd241(0x294)]===0x0)return{'success':![],'error':'No\x20messages\x20to\x20process.'};try{let _0x3635e2=await getCollectionId();const _0x313aeb=getCollectionIdInfo();if(_0x313aeb[_0x1fd241(0x234)]&&_0x313aeb['oldId']===_0x3635e2&&_0x313aeb[_0x1fd241(0x234)]!==_0x313aeb[_0x1fd241(0x1f5)]){const _0x2bf618=confirm(_0x1fd241(0x23e));if(_0x2bf618)_0x313d4e(_0x1fd241(0x261)+_0x313aeb[_0x1fd241(0x234)],_0x1fd241(0x245)),await purgeStorage(_0x313aeb[_0x1fd241(0x234)]),_0x3635e2=_0x313aeb[_0x1fd241(0x1f5)],_0x313d4e('[翰林院-迁移]\x20旧宝库已清空,将向新宝库写入数据:\x20'+_0x3635e2,_0x1fd241(0x241));else return _0x313d4e(_0x1fd241(0x1e3),_0x1fd241(0x27a)),toastr[_0x1fd241(0x27a)](_0x1fd241(0x214)),{'success':![],'error':_0x1fd241(0x263)};}if(!_0x3635e2)throw new Error(_0x1fd241(0x231));_0x313d4e('[翰林院-核心]\x20凝识任务已锁定忆识宝库ID:\x20'+_0x3635e2,_0x1fd241(0x27a));const _0x3c9467=[],_0x26e110=context[_0x1fd241(0x217)];for(const _0x4327dd of _0x280f4b){const _0xbfc710=(_0x4327dd['mes']||'')[_0x1fd241(0x1e2)](/<[^>]*>/g,'')[_0x1fd241(0x255)]();if(_0xbfc710[_0x1fd241(0x294)]===0x0)continue;let _0x42acc7;if(_0x4327dd[_0x1fd241(0x229)]!==undefined&&_0x4327dd[_0x1fd241(0x229)]!==null)_0x42acc7=_0x4327dd['floor'];else{const _0x4d049b=_0x26e110[_0x1fd241(0x248)](_0x4f60b4=>_0x4f60b4===_0x4327dd);_0x42acc7=_0x4d049b!==-0x1?_0x4d049b+0x1:-0x1;}const _0x46c69a=new Date(_0x4327dd['send_date']),_0x2002b3=isNaN(_0x46c69a['getTime']())?new Date()['toISOString']():_0x46c69a[_0x1fd241(0x1ef)](),_0xaca346=splitIntoChunks(_0xbfc710,'chat_history',{'floor':_0x42acc7,'is_user':_0x4327dd[_0x1fd241(0x239)],'timestamp':_0x2002b3});_0x3c9467[_0x1fd241(0x210)](..._0xaca346);}if(_0x3c9467[_0x1fd241(0x294)]===0x0)return{'success':!![],'count':0x0};_0x313d4e(_0x1fd241(0x250)+_0x280f4b[_0x1fd241(0x294)]+_0x1fd241(0x219)+_0x3c9467[_0x1fd241(0x294)]+_0x1fd241(0x279),'info');const _0x41af19=settings['retrieval'][_0x1fd241(0x251)]||0x5;let _0x3f2109=0x0;for(let _0xebb14c=0x0;_0xebb14c<_0x3c9467['length'];_0xebb14c+=_0x41af19){const _0x3af6e0=_0x3c9467[_0x1fd241(0x1ed)](_0xebb14c,_0xebb14c+_0x41af19),_0x38a449=_0x3af6e0['map'](_0x561358=>_0x561358[_0x1fd241(0x24b)]),_0x5bc7bd=await getEmbeddings(_0x38a449);if(_0x3af6e0['length']!==_0x5bc7bd[_0x1fd241(0x294)])throw new Error(_0x1fd241(0x1e4));const _0x3afa18=_0x3af6e0[_0x1fd241(0x1f2)]((_0x3dc10a,_0x33cbff)=>({..._0x3dc10a,'vector':_0x5bc7bd[_0x33cbff]}));await insertVectors(_0x3afa18,null,_0x3635e2),_0x3f2109+=_0x3af6e0[_0x1fd241(0x294)];}if(_0x2e4041){const _0x3b4bb7=_0x2e4041['end']===0x0?context['chat'][_0x1fd241(0x294)]:_0x2e4041['end'];settings['condensationHistory'][_0x3635e2]={'start':_0x2e4041[_0x1fd241(0x260)],'end':_0x3b4bb7,'timestamp':new Date()[_0x1fd241(0x1ef)]()},saveSettings(),_0x313d4e(_0x1fd241(0x22f)+_0x3635e2+_0x1fd241(0x273)+_0x2e4041[_0x1fd241(0x260)]+'-'+_0x3b4bb7,'info');}_0x313d4e(_0x1fd241(0x212)+_0x3f2109+'\x20个条目。',_0x1fd241(0x241));const _0x46aa2d=_0x280f4b[_0x1fd241(0x1f2)](_0x316abc=>{const _0x744d10=_0x1fd241,_0x2b98af=_0x26e110[_0x744d10(0x248)](_0x5c1915=>_0x5c1915===_0x316abc),_0x53f45b=_0x2b98af!==-0x1?_0x2b98af+0x1:-0x1,_0x5f44c=_0x316abc[_0x744d10(0x239)]?'用户':getCharacterName()||'AI';return'['+_0x5f44c+'\x20-\x20楼层\x20#'+_0x53f45b+_0x744d10(0x243);});return{'success':!![],'count':_0x3f2109,'messages':_0x46aa2d};}catch(_0x3679da){return console[_0x1fd241(0x1db)](_0x1fd241(0x21e),_0x3679da),_0x313d4e(_0x1fd241(0x24f)+_0x3679da['message'],_0x1fd241(0x1db)),{'success':![],'error':_0x3679da[_0x1fd241(0x1da)]};}}async function rerankResults(_0x475350,_0x5913b2,_0x455924){const _0x47dba8=_0x15e62c;let _0x33cdf5=_0x475350;if(_0x455924[_0x47dba8(0x235)][_0x47dba8(0x1ca)]&&_0x475350[_0x47dba8(0x294)]>0x0){console[_0x47dba8(0x1fb)](_0x47dba8(0x1d7));try{const _0x77e0f0=_0x475350['map']((_0x145524,_0x428d9c)=>({'text':_0x145524['text'],'original_index':_0x428d9c})),_0x43a2eb=getRerankBaseUrl(_0x455924[_0x47dba8(0x235)]['url']),_0x278ffe=_0x43a2eb+_0x47dba8(0x24e),_0x45d557=await fetch(_0x278ffe,{'method':_0x47dba8(0x238),'headers':{'Content-Type':'application/json','Authorization':'Bearer\x20'+_0x455924[_0x47dba8(0x235)][_0x47dba8(0x1ec)]},'body':JSON[_0x47dba8(0x249)]({'query':_0x5913b2,'documents':_0x77e0f0[_0x47dba8(0x1f2)](_0x1e6067=>_0x1e6067[_0x47dba8(0x24b)]),'model':_0x455924[_0x47dba8(0x235)][_0x47dba8(0x1f6)],'top_n':_0x455924[_0x47dba8(0x235)]['top_n']})});if(!_0x45d557['ok'])throw new Error(_0x47dba8(0x27c)+_0x45d557[_0x47dba8(0x265)]+_0x47dba8(0x284)+await _0x45d557[_0x47dba8(0x24b)]());const _0x3914a7=await _0x45d557['json'](),_0x57ecc5=_0x475350[_0x47dba8(0x1f2)]((_0x598f45,_0x1eff29)=>({..._0x598f45,'original_index':_0x1eff29}));_0x33cdf5=_0x57ecc5[_0x47dba8(0x1f2)](_0x18a014=>{const _0x194936=_0x47dba8,_0x47bb2b=_0x3914a7['results'][_0x194936(0x272)](_0x59c4f0=>_0x59c4f0[_0x194936(0x293)]===_0x18a014['original_index']),_0xc44481=_0x47bb2b?_0x47bb2b[_0x194936(0x1fd)]:0x0;return{..._0x18a014,'rerank_score':_0xc44481};});if(_0x455924['rerank'][_0x47dba8(0x280)])showNotification(_0x47dba8(0x24c),_0x47dba8(0x241));}catch(_0x54cef2){console[_0x47dba8(0x1db)](_0x47dba8(0x1cf),_0x54cef2);if(_0x455924[_0x47dba8(0x235)][_0x47dba8(0x280)])showNotification(_0x47dba8(0x252)+_0x54cef2[_0x47dba8(0x1da)],_0x47dba8(0x1db));_0x33cdf5[_0x47dba8(0x1d2)](_0x2ec4a5=>_0x2ec4a5[_0x47dba8(0x254)]=0x0);}}else _0x33cdf5[_0x47dba8(0x1d2)](_0x420c4c=>_0x420c4c[_0x47dba8(0x254)]=0x0);console[_0x47dba8(0x1fb)]('[翰林院-Rerank]\x20开始元数据加权最终排序...');const _0x1b4d06=context[_0x47dba8(0x217)][_0x47dba8(0x294)],_0x56f1ba=_0x455924['rerank']['hybrid_alpha'],_0x3f428a=_0x33cdf5['map'](_0x21c053=>{const _0x22dccb=_0x47dba8;let _0x45a2cc=0x1;const _0x3609a1=_0x21c053[_0x22dccb(0x291)]||{};switch(_0x3609a1[_0x22dccb(0x1c9)]){case _0x22dccb(0x21c):_0x45a2cc*=1.2;break;case _0x22dccb(0x1f0):_0x45a2cc*=1.1;break;case _0x22dccb(0x27d):if(_0x3609a1[_0x22dccb(0x229)]&&_0x1b4d06>0x0){const _0x1f6cc2=_0x3609a1['floor']/_0x1b4d06;_0x45a2cc*=0x1+_0x1f6cc2;}break;}const _0x52ad23=_0x21c053[_0x22dccb(0x254)]*_0x56f1ba+(_0x21c053[_0x22dccb(0x244)]||0x0)*(0x1-_0x56f1ba),_0x2ea656=_0x52ad23*_0x45a2cc;return{..._0x21c053,'final_score':_0x2ea656};});return _0x3f428a[_0x47dba8(0x266)]((_0x35ceb1,_0x382faa)=>(_0x382faa['final_score']||0x0)-(_0x35ceb1[_0x47dba8(0x277)]||0x0)),console[_0x47dba8(0x1fb)]('[翰林院-Rerank]\x20元数据加权排序完成。'),_0x3f428a[_0x47dba8(0x1ed)](0x0,_0x455924[_0x47dba8(0x235)]['top_n']);}async function rearrangeChat(_0x39c1cd,_0x550b8f,_0x38a49d,_0x4a0e17){const _0x211270=_0x15e62c;setExtensionPrompt(_0x211270(0x228),'',settings['injection'][_0x211270(0x1fe)],settings[_0x211270(0x1df)][_0x211270(0x1d8)],![],settings[_0x211270(0x1df)][_0x211270(0x1d0)]);if(_0x4a0e17===_0x211270(0x270)||!settings['retrieval'][_0x211270(0x1ca)])return;const _0x297895=_0x39c1cd[_0x211270(0x1ed)](-settings[_0x211270(0x269)][_0x211270(0x22c)]);if(_0x297895['length']===0x0)return;const _0x166d76=_0x297895[_0x211270(0x1f2)](_0x78e792=>_0x78e792['mes'])['join']('\x20')[_0x211270(0x1e2)](/<[^>]*>/g,'')[_0x211270(0x255)]();if(!_0x166d76)return;try{const _0x25e20f=await queryVectors(_0x166d76);if(_0x25e20f[_0x211270(0x294)]===0x0)return;const _0x1c7e7e=await rerankResults(_0x25e20f,_0x166d76,settings);if(_0x1c7e7e[_0x211270(0x294)]===0x0)return;const _0x172d06=_0x1c7e7e[_0x211270(0x1f2)](_0x5391ab=>_0x5391ab[_0x211270(0x24b)])[_0x211270(0x275)]('\x0a\x0a'),_0x5b549b=settings[_0x211270(0x1df)][_0x211270(0x226)][_0x211270(0x1e2)](_0x211270(0x28a),_0x172d06);setExtensionPrompt(_0x211270(0x228),_0x5b549b,settings['injection'][_0x211270(0x1fe)],settings[_0x211270(0x1df)][_0x211270(0x1d8)],![],settings[_0x211270(0x1df)][_0x211270(0x1d0)]);}catch(_0x221d13){console[_0x211270(0x1db)]('[翰林院]\x20检索或注入时发生错误:',_0x221d13);if(settings[_0x211270(0x27e)][_0x211270(0x280)])showNotification('忆识检索失败:\x20'+_0x221d13[_0x211270(0x1da)],'error');}} +'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');}}