From 1669bb667af5751d84b3c658edaab561d42e2f6c Mon Sep 17 00:00:00 2001
From: Wx-2025 <351320169@qq.com>
Date: Sun, 28 Sep 2025 17:32:18 +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 f8efbc9..41e6889 100644
--- a/core/rag-processor.js
+++ b/core/rag-processor.js
@@ -1 +1 @@
-'use strict';const _0x54d6e8=_0x2723;function _0x2723(_0x365403,_0x34c11d){const _0xef8892=_0xef88();return _0x2723=function(_0x2723ee,_0x1e27bd){_0x2723ee=_0x2723ee-0x1d2;let _0x5240ea=_0xef8892[_0x2723ee];return _0x5240ea;},_0x2723(_0x365403,_0x34c11d);}(function(_0x26278a,_0x505b6d){const _0x32edcb=_0x2723,_0x128734=_0x26278a();while(!![]){try{const _0x5f4d12=-parseInt(_0x32edcb(0x237))/0x1+-parseInt(_0x32edcb(0x207))/0x2*(-parseInt(_0x32edcb(0x271))/0x3)+parseInt(_0x32edcb(0x1ef))/0x4*(parseInt(_0x32edcb(0x272))/0x5)+-parseInt(_0x32edcb(0x204))/0x6+-parseInt(_0x32edcb(0x268))/0x7*(parseInt(_0x32edcb(0x1d3))/0x8)+-parseInt(_0x32edcb(0x2b2))/0x9+parseInt(_0x32edcb(0x29b))/0xa*(parseInt(_0x32edcb(0x2c0))/0xb);if(_0x5f4d12===_0x505b6d)break;else _0x128734['push'](_0x128734['shift']());}catch(_0x5a3b7f){_0x128734['push'](_0x128734['shift']());}}}(_0xef88,0x41c0d));import{extension_prompt_roles,setExtensionPrompt}from'/script.js';import*as _0x3831fa from'./utils/context-utils.js';import{getCollectionIdInfo,getCharacterId,getCharacterStableId}from'./utils/context-utils.js';import{defaultSettings as _0x547a57}from'./rag-settings.js';import*as _0x4cea90 from'./ingestion-manager.js';import{getEmbeddings,fetchEmbeddingModels as _0x4895f3,fetchRerankModels as _0x121473,executeRerank,testApiConnection as _0x4c225a}from'./rag-api.js';const MODULE_NAME='hanlinyuan-rag-core',OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME='vectors_rearrangeChat',GLOBAL_SCOPE_ID=_0x54d6e8(0x291);let context=null,settings=null,lockedCollectionId=null;function filterWorldbooks(_0x4b4f89,_0x33e06a){const _0xbbfba=_0x54d6e8;if(!_0x4b4f89||!_0x4b4f89[_0xbbfba(0x1f3)]())return _0x33e06a;const _0x3e7eab=_0x4b4f89[_0xbbfba(0x20f)]()[_0xbbfba(0x1f3)]();return _0x33e06a['filter'](_0x4f9333=>{const _0x176d96=_0xbbfba;return _0x4f9333[_0x176d96(0x20f)]()[_0x176d96(0x1d2)](_0x3e7eab)||containsPinyinMatch(_0x4f9333,_0x3e7eab);});}function filterWorldbookEntries(_0x4813ab,_0x431c5b){const _0x1bb3b0=_0x54d6e8;if(!_0x4813ab||!_0x4813ab[_0x1bb3b0(0x1f3)]())return _0x431c5b;const _0x5bbf92=_0x4813ab[_0x1bb3b0(0x20f)]()['trim']();return _0x431c5b['filter'](_0x10aeb8=>{const _0x1c3b39=_0x1bb3b0,_0x443257=[_0x10aeb8[_0x1c3b39(0x212)]||'',_0x10aeb8[_0x1c3b39(0x22e)]||'',_0x10aeb8['content']||'']['join']('\x20')['toLowerCase']();return _0x443257[_0x1c3b39(0x1d2)](_0x5bbf92)||containsPinyinMatch(_0x10aeb8[_0x1c3b39(0x212)]||'',_0x5bbf92);});}function containsPinyinMatch(_0x485416,_0xfd8f5f){const _0x499aaa=_0x54d6e8,_0x433d4c={'世界书':'sjshu','条目':'tiaomu','编纂':_0x499aaa(0x2c7),'搜索':'sousuo'},_0x55303d=_0x433d4c[_0x485416];return _0x55303d&&_0x55303d[_0x499aaa(0x1d2)](_0xfd8f5f);}function highlightSearchMatch(_0x43210c,_0x160e75){const _0x4b599d=_0x54d6e8;if(!_0x160e75||!_0x160e75[_0x4b599d(0x1f3)]())return _0x43210c;const _0x5dd2b4=new RegExp('('+_0x160e75[_0x4b599d(0x23a)](/[.*+?^${}()|[\]\\]/g,'\x5c$&')+')','gi');return _0x43210c[_0x4b599d(0x23a)](_0x5dd2b4,_0x4b599d(0x1ed));}function debounce(_0x2911af,_0x2b7dcd){let _0x2a10d6;return function _0x546ee2(..._0x42dd59){const _0x4a14b2=()=>{clearTimeout(_0x2a10d6),_0x2911af(..._0x42dd59);};clearTimeout(_0x2a10d6),_0x2a10d6=setTimeout(_0x4a14b2,_0x2b7dcd);};}export{initialize,getSettings,saveSettings,resetSettings,_0x4c225a as testApiConnection,_0x4895f3 as fetchEmbeddingModels,_0x121473 as fetchRerankModels,getVectorCount,purgeStorage,getMessagesForCondensation,processCondensation,ingestTextToHanlinyuan,getCollectionId,toggleSessionLock,isSessionLocked,getLockedSessionInfo,addKnowledgeBase,removeKnowledgeBase,getLocalKnowledgeBases,getGlobalKnowledgeBases,toggleKnowledgeBase,moveKnowledgeBase,filterWorldbooks,filterWorldbookEntries,highlightSearchMatch,debounce};function initialize(){const _0x720856=_0x54d6e8;context=SillyTavern[_0x720856(0x214)]();if(!context){console[_0x720856(0x203)](_0x720856(0x200));return;}settings=getSettings(),!window[_0x720856(0x22c)]&&(window[_0x720856(0x22c)]={}),window[_0x720856(0x22c)][_0x720856(0x21b)]=rearrangeChat,window['hanlinyuanRagProcessor'][_0x720856(0x294)]=!![],console[_0x720856(0x28b)](_0x720856(0x21c));}async function ingestTextToHanlinyuan(_0x348741,_0x14747e='manual',_0x48aff6={},_0x15d822=()=>{},_0x2b1f3c=null,_0x27d252=()=>{},_0x43c6b2=()=>{},_0x10ba40=null,_0x311661=0x0){const _0x5f2968=_0x54d6e8;if(!_0x348741||!_0x348741['trim']())return{'success':![],'error':'输入文本为空'};if(!settings)return{'success':![],'error':_0x5f2968(0x245)};try{const _0xd90518=getCollectionIdInfo(),_0x15ace9=await _0x5bce7c();if(_0xd90518[_0x5f2968(0x243)]&&_0xd90518[_0x5f2968(0x243)]===_0x15ace9&&_0xd90518[_0x5f2968(0x243)]!==_0xd90518[_0x5f2968(0x1ea)]){const _0x2a7326=confirm(_0x5f2968(0x222));if(_0x2a7326)_0x27d252(_0x5f2968(0x208)+_0xd90518['oldId'],_0x5f2968(0x29a)),await purgeStorage(_0xd90518[_0x5f2968(0x243)]),_0x27d252(_0x5f2968(0x247),_0x5f2968(0x2b1));else return _0x27d252(_0x5f2968(0x264),_0x5f2968(0x292)),toastr[_0x5f2968(0x292)]('操作已取消。'),{'success':![],'error':_0x5f2968(0x1e8)};}let _0x316ff4,_0x530cbc;const _0x59829f=new Date()['toLocaleString'](_0x5f2968(0x2b4),{'hour12':![]}),_0x28b428=getCharacterName()||_0x5f2968(0x20e);switch(_0x14747e){case'chat_history':const _0x5a9fea=_0x48aff6['range']||{},_0x14e8af=_0x5a9fea['start']??'?',_0x2438f5=_0x5a9fea[_0x5f2968(0x262)]===0x0?'末':_0x5a9fea[_0x5f2968(0x262)]??'?';_0x316ff4=_0x28b428+':\x20'+_0x14e8af+'楼-'+_0x2438f5+'楼';break;case _0x5f2968(0x1ee):const _0x5be9f3=_0x48aff6[_0x5f2968(0x201)]||_0x5f2968(0x270),_0x34b747=_0x48aff6[_0x5f2968(0x297)]||'未知条目';_0x316ff4=_0x5be9f3+':\x20'+_0x34b747;break;case'novel':_0x316ff4=_0x5f2968(0x25f)+(_0x48aff6[_0x5f2968(0x254)]||_0x5f2968(0x227));break;case _0x5f2968(0x23e):default:_0x316ff4=_0x5f2968(0x2a8)+_0x59829f;break;}const _0x1debf2=Object[_0x5f2968(0x267)](getKnowledgeBases()),_0x2a29ab=_0x1debf2[_0x5f2968(0x259)](_0x1f5d9b=>_0x1f5d9b[_0x5f2968(0x1fe)]===_0x316ff4);if(_0x2a29ab)_0x530cbc=_0x2a29ab['id'],_0x27d252(_0x5f2968(0x248)+_0x316ff4+_0x5f2968(0x282),_0x5f2968(0x292));else{_0x27d252(_0x5f2968(0x27d)+_0x316ff4+_0x5f2968(0x2a7),_0x5f2968(0x292));const _0x2a57f8=addKnowledgeBase(_0x316ff4);_0x530cbc=_0x2a57f8['id'];}const _0x49d822=getCharacterStableId(),_0x4fdd3e=_0x49d822+'_'+_0x530cbc;_0x27d252('[翰林院-核心]\x20已创建并锁定知识库:\x20'+_0x316ff4+_0x5f2968(0x26c)+_0x4fdd3e+')',_0x5f2968(0x2b1)),_0x27d252(_0x5f2968(0x260)+_0x4fdd3e,'info'),_0x15d822({'message':'正在智能分块...','processed':0x0,'total':0x1});const _0x5481dc=splitIntoChunks(_0x348741,_0x14747e,_0x48aff6),_0x402aad=_0x5481dc[_0x5f2968(0x241)];if(_0x2b1f3c?.['aborted'])throw new Error(_0x5f2968(0x23f));_0x27d252(_0x5f2968(0x25b)+_0x316ff4+_0x5f2968(0x209)+_0x402aad+_0x5f2968(0x265),'info');if(_0x402aad===0x0)return{'success':!![],'count':0x0};const _0x400ad3=settings[_0x5f2968(0x1da)][_0x5f2968(0x287)]||0x5;let _0x34cec2=_0x311661;for(let _0xa3c57b=_0x311661;_0xa3c57b<_0x402aad;_0xa3c57b+=_0x400ad3){if(_0x2b1f3c?.[_0x5f2968(0x1fc)])throw new Error(_0x5f2968(0x23f));const _0x3dea49=_0x5481dc['slice'](_0xa3c57b,_0xa3c57b+_0x400ad3);_0x15d822({'message':'正在处理\x20'+(_0xa3c57b+0x1)+'-'+(_0xa3c57b+_0x3dea49[_0x5f2968(0x241)])+'\x20块','processed':_0xa3c57b,'total':_0x402aad});const _0x311989=_0x3dea49[_0x5f2968(0x2a5)](_0xbcacaf=>_0xbcacaf[_0x5f2968(0x220)]),_0x599be5=await getEmbeddings(_0x311989,_0x2b1f3c);if(_0x2b1f3c?.[_0x5f2968(0x1fc)])throw new Error(_0x5f2968(0x23f));if(_0x3dea49[_0x5f2968(0x241)]!==_0x599be5['length'])throw new Error(_0x5f2968(0x25a));const _0x14114a=_0x3dea49[_0x5f2968(0x2a5)]((_0x3f62e9,_0x155950)=>({..._0x3f62e9,'vector':_0x599be5[_0x155950]}));await insertVectors(_0x14114a,_0x2b1f3c,_0x4fdd3e),_0x34cec2+=_0x3dea49['length'],_0x10ba40&&_0x4cea90[_0x5f2968(0x2b7)](_0x10ba40,_0x34cec2,_0x402aad),await _0x43c6b2();}return _0x10ba40&&_0x4cea90[_0x5f2968(0x24e)](_0x10ba40),_0x27d252(_0x5f2968(0x2bb)+_0x34cec2+_0x5f2968(0x28e),_0x5f2968(0x2b1)),{'success':!![],'count':_0x34cec2};}catch(_0x33e3e9){if(_0x33e3e9[_0x5f2968(0x1fe)]===_0x5f2968(0x23f)){_0x27d252(_0x5f2968(0x2a9),_0x5f2968(0x29a));throw _0x33e3e9;}return console['error'](_0x5f2968(0x2c2),_0x33e3e9),_0x27d252(_0x5f2968(0x1df)+_0x33e3e9['message'],_0x5f2968(0x203)),{'success':![],'error':_0x33e3e9['message']};}}function getSettings(){const _0x543ee4=_0x54d6e8;if(!context||!context[_0x543ee4(0x252)])return structuredClone(_0x547a57);let _0x9cde81=context[_0x543ee4(0x252)][MODULE_NAME];!_0x9cde81&&(_0x9cde81={},context[_0x543ee4(0x252)][MODULE_NAME]=_0x9cde81);_0x9cde81['condensationHistory']===undefined&&(_0x9cde81[_0x543ee4(0x235)]={});_0x9cde81['knowledgeBases']===undefined&&(_0x9cde81[_0x543ee4(0x2a2)]={});for(const _0x1c5eb6 in _0x547a57){if(_0x9cde81[_0x1c5eb6]===undefined)_0x9cde81[_0x1c5eb6]=structuredClone(_0x547a57[_0x1c5eb6]);else{if(typeof _0x547a57[_0x1c5eb6]===_0x543ee4(0x26b)&&!Array[_0x543ee4(0x240)](_0x547a57[_0x1c5eb6])&&_0x547a57[_0x1c5eb6]!==null)for(const _0x5275be in _0x547a57[_0x1c5eb6]){_0x9cde81[_0x1c5eb6][_0x5275be]===undefined&&(_0x9cde81[_0x1c5eb6][_0x5275be]=_0x547a57[_0x1c5eb6][_0x5275be]);}}}return _0x9cde81;}function saveSettings(){if(context)context['saveSettingsDebounced']();}function resetSettings(){const _0x18beb=_0x54d6e8;context&&(context[_0x18beb(0x252)][MODULE_NAME]=structuredClone(_0x547a57),saveSettings());}function showNotification(_0x28352c,_0x5b9128=_0x54d6e8(0x292)){toastr[_0x5b9128](_0x28352c);}function getTagForSource(_0x512c21){const _0x5cc072=_0x54d6e8;switch(_0x512c21){case _0x5cc072(0x258):return _0x5cc072(0x295);case _0x5cc072(0x1ee):return _0x5cc072(0x1e4);case _0x5cc072(0x23e):return _0x5cc072(0x26e);case _0x5cc072(0x1fd):return'小说录入';default:return'资料';}}function splitIntoChunks(_0x57e35f,_0x48274e,_0x1ed2c2={}){const _0x3ec870=_0x54d6e8;switch(_0x48274e){case _0x3ec870(0x1fd):return _chunkForNovel(_0x57e35f,_0x1ed2c2);case _0x3ec870(0x258):return _chunkForChatHistory(_0x57e35f,_0x1ed2c2);case _0x3ec870(0x1ee):return _chunkForLorebook(_0x57e35f,_0x1ed2c2);case'manual':return _chunkForManual(_0x57e35f,_0x1ed2c2);default:console['warn'](_0x3ec870(0x224)+_0x48274e+_0x3ec870(0x26a));return _chunkForManual(_0x57e35f,{..._0x1ed2c2,'sourceName':_0x1ed2c2['sourceName']||'未知来源'});}}function _chunkForNovel(_0x2f10ff,_0x644479){const _0x2cdedf=_0x54d6e8,{chunkSize:_0x46ac20,overlap:_0x546555}=settings[_0x2cdedf(0x277)],{sourceName:sourceName='小说'}=_0x644479,_0x216af5=[];if(!_0x2f10ff||_0x46ac20<=0x0)return _0x216af5;const _0x1aa2b0=/(第\s*[一二三四五六七八九十百千万零\d]+\s*卷)/gim,_0x198b64=/(第\s*[一二三四五六七八九十百千万零\d]+\s*[章回节部])|^(Chapter\s+\d+)/gim;let _0x102b80=0x0;const _0x49c2b6=_0x2f10ff['split']('\x0a');let _0x1e7b02=_0x2cdedf(0x2b0),_0x367c9f='第1章',_0x4204fe=[];function _0x2e981c(){const _0x3e1331=_0x2cdedf;if(_0x4204fe[_0x3e1331(0x241)]===0x0)return;const _0x511f04=_0x4204fe[_0x3e1331(0x28c)]('\x0a');let _0x4f3dc6=0x0,_0xbe37a2=0x1;while(_0x4f3dc6<_0x511f04['length']){const _0xc42d46=Math['min'](_0x4f3dc6+_0x46ac20,_0x511f04['length']),_0x56a59b=_0x511f04[_0x3e1331(0x288)](_0x4f3dc6,_0xc42d46);if(_0x56a59b['trim']()['length']>0x0){const _0x1b9f40={'source':_0x3e1331(0x1fd),'sourceName':sourceName,'timestamp':new Date()[_0x3e1331(0x296)](),'globalIndex':_0x102b80++,'volume':_0x1e7b02,'chapter':_0x367c9f,'section':_0xbe37a2},_0x5c5caf=getTagForSource(_0x3e1331(0x1fd)),_0x57026b='[来源:\x20'+sourceName+',\x20'+_0x1e7b02+',\x20'+_0x367c9f+_0x3e1331(0x21f)+_0xbe37a2+'节]',_0x1d20d4='<'+_0x5c5caf+'>\x0a'+_0x57026b+'\x0a'+_0x56a59b+'\x0a'+_0x5c5caf+'>';_0x216af5[_0x3e1331(0x1e1)]({'text':_0x1d20d4,'metadata':_0x1b9f40}),_0xbe37a2++;}_0x4f3dc6+=_0x46ac20-_0x546555;if(_0x4f3dc6>=_0x511f04['length'])break;}_0x4204fe=[];}for(const _0x1c0963 of _0x49c2b6){const _0x3fdd24=_0x1c0963[_0x2cdedf(0x1f3)]();if(_0x1aa2b0['test'](_0x3fdd24))_0x2e981c(),_0x1e7b02=_0x3fdd24,_0x367c9f=_0x2cdedf(0x1e5);else _0x198b64[_0x2cdedf(0x249)](_0x3fdd24)?(_0x2e981c(),_0x367c9f=_0x3fdd24):_0x4204fe['push'](_0x1c0963);}_0x2e981c();if(_0x216af5[_0x2cdedf(0x241)]===0x0&&_0x2f10ff[_0x2cdedf(0x241)]>0x0){let _0x4c4e66=0x0,_0x869160=0x1;while(_0x4c4e66<_0x2f10ff[_0x2cdedf(0x241)]){const _0x3d550f=Math[_0x2cdedf(0x1dc)](_0x4c4e66+_0x46ac20,_0x2f10ff[_0x2cdedf(0x241)]),_0x170332=_0x2f10ff['substring'](_0x4c4e66,_0x3d550f),_0x42cfa0={'source':_0x2cdedf(0x1fd),'sourceName':sourceName,'timestamp':new Date()[_0x2cdedf(0x296)](),'globalIndex':_0x216af5[_0x2cdedf(0x241)],'volume':_0x2cdedf(0x2b0),'chapter':_0x2cdedf(0x1e5),'section':_0x869160},_0x180c37=getTagForSource(_0x2cdedf(0x1fd)),_0x1d408b='[来源:\x20'+sourceName+_0x2cdedf(0x27f)+_0x869160+'节]',_0x48bcd1='<'+_0x180c37+'>\x0a'+_0x1d408b+'\x0a'+_0x170332+_0x2cdedf(0x217)+_0x180c37+'>';_0x216af5[_0x2cdedf(0x1e1)]({'text':_0x48bcd1,'metadata':_0x42cfa0}),_0x869160++,_0x4c4e66+=_0x46ac20-_0x546555;}}return _0x216af5;}function _chunkForChatHistory(_0xb3d0fc,_0x5ba0c4){const _0x5193c0=_0x54d6e8,{chunkSize:_0x4e4b84,overlap:_0x20a1ad}=settings['advanced'],{floor:_0x4df28d,is_user:_0x5d6bf6,timestamp:_0x6b6478}=_0x5ba0c4,_0x3584cc=[];if(!_0xb3d0fc||_0x4e4b84<=0x0)return _0x3584cc;let _0x48c0d0=0x1,_0xf31c66=0x0;while(_0xf31c66<_0xb3d0fc[_0x5193c0(0x241)]){const _0x2dad01=Math[_0x5193c0(0x1dc)](_0xf31c66+_0x4e4b84,_0xb3d0fc['length']),_0x540051=_0xb3d0fc[_0x5193c0(0x288)](_0xf31c66,_0x2dad01),_0xcec89b=_0x5193c0(0x257)+_0x4df28d+_0x5193c0(0x21f)+_0x48c0d0+'部分]',_0x3e2df6=getTagForSource(_0x5193c0(0x258)),_0x29b3df='<'+_0x3e2df6+'>\x0a'+_0xcec89b+'\x0a'+_0x540051+_0x5193c0(0x217)+_0x3e2df6+'>';_0x3584cc['push']({'text':_0x29b3df,'metadata':{'source':'chat_history','sourceName':_0x5193c0(0x24d)+_0x4df28d,'floor':_0x4df28d,'part':_0x48c0d0,'is_user':_0x5d6bf6,'timestamp':_0x6b6478}}),_0x48c0d0++,_0xf31c66+=_0x4e4b84-_0x20a1ad;if(_0xf31c66>=_0xb3d0fc['length'])break;}return _0x3584cc;}function _chunkForLorebook(_0x4e0154,_0x189fb6){const _0x13bcad=_0x54d6e8,{chunkSize:_0x3c54f3,overlap:_0x487ced}=settings[_0x13bcad(0x277)],{sourceName:sourceName='世界书条目'}=_0x189fb6,_0x51a085=[];if(!_0x4e0154||_0x3c54f3<=0x0)return _0x51a085;let _0x3dfe22=0x1,_0x1bd457=0x0;while(_0x1bd457<_0x4e0154[_0x13bcad(0x241)]){const _0x2ee4d5=Math[_0x13bcad(0x1dc)](_0x1bd457+_0x3c54f3,_0x4e0154[_0x13bcad(0x241)]),_0x1bf894=_0x4e0154[_0x13bcad(0x288)](_0x1bd457,_0x2ee4d5),_0x1ff0bb='[来源:\x20世界书,\x20条目:\x20'+sourceName+_0x13bcad(0x21f)+_0x3dfe22+_0x13bcad(0x21d),_0x4d66a5=getTagForSource(_0x13bcad(0x1ee)),_0x2d3ada='<'+_0x4d66a5+'>\x0a'+_0x1ff0bb+'\x0a'+_0x1bf894+'\x0a'+_0x4d66a5+'>';_0x51a085[_0x13bcad(0x1e1)]({'text':_0x2d3ada,'metadata':{'source':_0x13bcad(0x1ee),'sourceName':sourceName,'part':_0x3dfe22,'timestamp':new Date()[_0x13bcad(0x296)]()}}),_0x3dfe22++,_0x1bd457+=_0x3c54f3-_0x487ced;if(_0x1bd457>=_0x4e0154[_0x13bcad(0x241)])break;}return _0x51a085;}function _chunkForManual(_0xcbcb2d,_0x3c1471){const _0x5c0130=_0x54d6e8,{chunkSize:_0x15362f,overlap:_0x12a721}=settings['advanced'],{sourceName:sourceName=_0x5c0130(0x26e)}=_0x3c1471,_0x2b692e=[];if(!_0xcbcb2d||_0x15362f<=0x0)return _0x2b692e;const _0x42cf3c=new Date(),_0x1122fc=_0x42cf3c[_0x5c0130(0x2a0)](_0x5c0130(0x2b4));let _0x13a965=0x1,_0x229aa8=0x0;while(_0x229aa8<_0xcbcb2d[_0x5c0130(0x241)]){const _0x1e2a95=Math[_0x5c0130(0x1dc)](_0x229aa8+_0x15362f,_0xcbcb2d[_0x5c0130(0x241)]),_0x3c0241=_0xcbcb2d[_0x5c0130(0x288)](_0x229aa8,_0x1e2a95),_0x15e4c3='[来源:\x20'+sourceName+',\x20向量化录入时间:\x20'+_0x1122fc+_0x5c0130(0x21f)+_0x13a965+'部分]',_0x10532d=getTagForSource(_0x5c0130(0x23e)),_0x36e4bb='<'+_0x10532d+'>\x0a'+_0x15e4c3+'\x0a'+_0x3c0241+_0x5c0130(0x217)+_0x10532d+'>';_0x2b692e[_0x5c0130(0x1e1)]({'text':_0x36e4bb,'metadata':{'source':_0x5c0130(0x23e),'sourceName':sourceName,'part':_0x13a965,'timestamp':_0x42cf3c[_0x5c0130(0x296)]()}}),_0x13a965++,_0x229aa8+=_0x15362f-_0x12a721;if(_0x229aa8>=_0xcbcb2d[_0x5c0130(0x241)])break;}return _0x2b692e;}import{getCollectionId as _0x5bce7c,getCharacterName}from'./utils/context-utils.js';async function getCollectionId(){return lockedCollectionId||await _0x5bce7c();}async function toggleSessionLock(){return lockedCollectionId?(lockedCollectionId=null,![]):(lockedCollectionId=await _0x5bce7c(),!![]);}function isSessionLocked(){return lockedCollectionId!==null;}function getLockedSessionInfo(){const _0x2b8b5d=_0x54d6e8;if(!lockedCollectionId)return null;return{'id':lockedCollectionId,'name':_0x2b8b5d(0x253)+lockedCollectionId[_0x2b8b5d(0x288)](0x0,0x8)+'...)'};}function getLocalKnowledgeBases(){const _0x4ab27b=_0x54d6e8,_0x2b9c0c=getCharacterStableId();return!settings[_0x4ab27b(0x2a2)][_0x2b9c0c]&&(settings[_0x4ab27b(0x2a2)][_0x2b9c0c]={}),settings[_0x4ab27b(0x2a2)][_0x2b9c0c];}function getGlobalKnowledgeBases(){const _0x551d10=_0x54d6e8;return!settings[_0x551d10(0x2a2)][GLOBAL_SCOPE_ID]&&(settings['knowledgeBases'][GLOBAL_SCOPE_ID]={}),settings[_0x551d10(0x2a2)][GLOBAL_SCOPE_ID];}function getKnowledgeBases(){const _0x4d303c=getLocalKnowledgeBases(),_0x2baf64=getGlobalKnowledgeBases();return{..._0x2baf64,..._0x4d303c};}function addKnowledgeBase(_0x5c2a76){const _0x466309=_0x54d6e8;if(!_0x5c2a76||!_0x5c2a76['trim']())throw new Error(_0x466309(0x261));const _0x3b9a6b=getCharacterStableId(),_0x2026d7=getLocalKnowledgeBases(),_0x2e401d=_0x466309(0x275)+Date['now']()+'_'+Math[_0x466309(0x1d8)]()[_0x466309(0x230)](0x24)[_0x466309(0x288)](0x2,0x9),_0x11ac80={'id':_0x2e401d,'name':_0x5c2a76['trim'](),'enabled':!![],'createdAt':new Date()[_0x466309(0x296)](),'owner':_0x3b9a6b};return _0x2026d7[_0x2e401d]=_0x11ac80,saveSettings(),console[_0x466309(0x28b)]('[翰林院-核心]\x20已为角色\x20'+_0x3b9a6b+_0x466309(0x210)+_0x5c2a76+'\x20(ID:\x20'+_0x2e401d+')'),_0x11ac80;}async function removeKnowledgeBase(_0xf14a1d,_0x2d18bd){const _0x46f056=_0x54d6e8,_0x4d5c58=getCharacterStableId(),_0x16791a=_0x2d18bd===_0x46f056(0x20d)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x1b1cfd=_0x16791a[_0xf14a1d],_0x26c38f=_0x1b1cfd?.[_0x46f056(0x1fe)]||_0xf14a1d;if(!_0x1b1cfd){console[_0x46f056(0x29a)]('[翰林院-核心]\x20尝试删除一个不存在的知识库:\x20'+_0xf14a1d+_0x46f056(0x285)+_0x2d18bd+')');return;}const _0x2c6888=_0x2d18bd==='global'?_0x1b1cfd[_0x46f056(0x2c6)]||GLOBAL_SCOPE_ID:_0x4d5c58,_0x1e427a=_0x2c6888+'_'+_0xf14a1d;console[_0x46f056(0x28b)](_0x46f056(0x276)+_0xf14a1d+_0x46f056(0x215)+_0x1e427a);const _0x37b8b2=await purgeStorage(_0x1e427a);_0x37b8b2?(delete _0x16791a[_0xf14a1d],saveSettings(),console['log'](_0x46f056(0x228)+_0xf14a1d+_0x46f056(0x1f7)),toastr[_0x46f056(0x2b1)](_0x46f056(0x280)+_0x26c38f+_0x46f056(0x1e3))):(console['error'](_0x46f056(0x2a3)+_0x1e427a+_0x46f056(0x1f2)),toastr[_0x46f056(0x203)](_0x46f056(0x216)));}function toggleKnowledgeBase(_0x4dce9d,_0x504e60){const _0x24df44=_0x54d6e8,_0x1a001b=_0x504e60==='global'?getGlobalKnowledgeBases():getLocalKnowledgeBases();_0x1a001b[_0x4dce9d]&&(_0x1a001b[_0x4dce9d]['enabled']=!_0x1a001b[_0x4dce9d][_0x24df44(0x251)],saveSettings(),console['log'](_0x24df44(0x1ec)+_0x4dce9d+_0x24df44(0x285)+_0x504e60+_0x24df44(0x2af)+(_0x1a001b[_0x4dce9d][_0x24df44(0x251)]?'启用':'禁用')));}function generateHash(_0x291e42){const _0x39d5ef=_0x54d6e8;let _0x4a6bf0=0x0;for(let _0x199ffc=0x0;_0x199ffc<_0x291e42['length'];_0x199ffc++){const _0x10021b=_0x291e42[_0x39d5ef(0x213)](_0x199ffc);_0x4a6bf0=(_0x4a6bf0<<0x5)-_0x4a6bf0+_0x10021b,_0x4a6bf0=_0x4a6bf0&_0x4a6bf0;}return Math[_0x39d5ef(0x1d5)](_0x4a6bf0)[_0x39d5ef(0x230)](0x24);}async function queryVectors(_0x16afb7){const _0x53f168=_0x54d6e8;console[_0x53f168(0x28b)](_0x53f168(0x219));const _0x4c852d=getCharacterStableId(),_0x505962=getLocalKnowledgeBases(),_0x46aa15=getGlobalKnowledgeBases(),_0x4d1d27=Object[_0x53f168(0x267)](_0x505962)[_0x53f168(0x211)](_0x55e9e5=>_0x55e9e5['enabled']),_0x5a7622=Object[_0x53f168(0x267)](_0x46aa15)[_0x53f168(0x211)](_0x4fa18e=>_0x4fa18e[_0x53f168(0x251)]),_0x449683=[..._0x4d1d27[_0x53f168(0x2a5)](_0x3e0b1d=>({..._0x3e0b1d,'scope':_0x53f168(0x22a)})),..._0x5a7622[_0x53f168(0x2a5)](_0x17b19e=>({..._0x17b19e,'scope':_0x53f168(0x20d)}))];if(_0x449683['length']===0x0){console[_0x53f168(0x28b)]('[翰林院-日志]\x20没有启用的新知识库,尝试查询旧版单体宝库...');const _0x1ac3a9=await _0x5bce7c();if(!_0x1ac3a9)return[];_0x449683[_0x53f168(0x1e1)]({'id':null,'name':'旧版宝库\x20(Legacy)','scope':_0x53f168(0x1f5)});}const _0x24c645=(await getEmbeddings([_0x16afb7]))[0x0];let _0x5e084b=[];const _0x15aa0f=_0x449683[_0x53f168(0x2a5)](_0x4ff2bf=>{const _0x1bce73=_0x53f168;let _0x43eeff;if(_0x4ff2bf['scope']===_0x1bce73(0x1f5))_0x43eeff=_0x5bce7c();else{const _0x33e5bd=_0x4ff2bf[_0x1bce73(0x263)]===_0x1bce73(0x20d)?_0x4ff2bf['owner']||GLOBAL_SCOPE_ID:_0x4c852d;_0x43eeff=Promise['resolve'](_0x33e5bd+'_'+_0x4ff2bf['id']);}return _0x43eeff['then'](_0x3f199a=>{const _0x922c8e=_0x1bce73;if(!_0x3f199a)return[];console[_0x922c8e(0x28b)](_0x922c8e(0x1f9)+_0x4ff2bf[_0x922c8e(0x1fe)]+_0x922c8e(0x1f6)+_0x3f199a+')');const _0x4069e7={'collectionId':_0x3f199a,'searchText':_0x16afb7,'topK':settings['advanced']['maxResults'],'threshold':settings[_0x922c8e(0x277)]['matchThreshold'],'source':'webllm','embeddings':{[_0x16afb7]:_0x24c645}};return fetch(_0x922c8e(0x20a),{'method':'POST','headers':context[_0x922c8e(0x246)](),'body':JSON[_0x922c8e(0x29c)](_0x4069e7)})['then'](async _0xb6b3b8=>{const _0x25ad3b=_0x922c8e;if(!_0xb6b3b8['ok']){const _0x298a2b=await _0xb6b3b8[_0x25ad3b(0x220)]();return console[_0x25ad3b(0x203)](_0x25ad3b(0x1f1)+_0x3f199a+_0x25ad3b(0x29f),_0x298a2b),[];}const _0x204656=await _0xb6b3b8[_0x25ad3b(0x223)](),_0x38efd5=_0x204656['metadata']||_0x204656[_0x25ad3b(0x29d)]||_0x204656[_0x25ad3b(0x2a1)]||[];return console[_0x25ad3b(0x28b)](_0x25ad3b(0x281)+_0x4ff2bf[_0x25ad3b(0x1fe)]+_0x25ad3b(0x1dd)+_0x38efd5[_0x25ad3b(0x241)]+_0x25ad3b(0x2c3)),_0x38efd5;})['catch'](_0x55ccef=>{const _0x477af0=_0x922c8e;return console['error'](_0x477af0(0x1f1)+_0x3f199a+_0x477af0(0x269),_0x55ccef),[];});});}),_0x3354c3=await Promise[_0x53f168(0x20b)](_0x15aa0f);_0x5e084b=_0x3354c3[_0x53f168(0x1e6)](),console[_0x53f168(0x28b)](_0x53f168(0x2ac)+_0x5e084b['length']+_0x53f168(0x2bc));const _0x8d42ec=[],_0x49bc4a=new Set();for(const _0x313700 of _0x5e084b){_0x313700&&_0x313700['text']&&!_0x49bc4a[_0x53f168(0x218)](_0x313700[_0x53f168(0x220)])&&(_0x49bc4a[_0x53f168(0x232)](_0x313700['text']),_0x8d42ec[_0x53f168(0x1e1)](_0x313700));}return console['log'](_0x53f168(0x229)+_0x8d42ec[_0x53f168(0x241)]+_0x53f168(0x2c3)),_0x8d42ec[_0x53f168(0x2b8)]((_0x2d88ea,_0x2979eb)=>(_0x2979eb['score']||0x0)-(_0x2d88ea['score']||0x0)),_0x8d42ec;}async function insertVectors(_0x45bd06,_0x456508=null,_0x3405dc){const _0x133bc3=_0x54d6e8;if(!_0x3405dc)throw new Error(_0x133bc3(0x26f));if(_0x45bd06[_0x133bc3(0x241)]===0x0)return{'success':!![],'count':0x0};const _0xb0b597=_0x45bd06[_0x133bc3(0x2a5)]((_0x4564bc,_0x351eea)=>({'hash':generateHash(_0x4564bc[_0x133bc3(0x220)]+Date[_0x133bc3(0x25e)]()+_0x351eea),'text':_0x4564bc[_0x133bc3(0x220)],'metadata':_0x4564bc[_0x133bc3(0x293)]||{'source':'unknown','timestamp':new Date()['toISOString']()}})),_0x3827d3=_0xb0b597[_0x133bc3(0x250)]((_0x167af3,_0x1ff0b9,_0x5c2c54)=>{const _0x539ed9=_0x133bc3;return _0x167af3[_0x1ff0b9[_0x539ed9(0x220)]]=_0x45bd06[_0x5c2c54][_0x539ed9(0x2aa)],_0x167af3;},{}),_0x185575={'collectionId':_0x3405dc,'items':_0xb0b597,'source':_0x133bc3(0x1e2),'embeddings':_0x3827d3},_0x3bee26=await fetch(_0x133bc3(0x205),{'method':'POST','headers':context[_0x133bc3(0x246)](),'body':JSON[_0x133bc3(0x29c)](_0x185575),'signal':_0x456508});if(!_0x3bee26['ok']){const _0x3adbb2=await _0x3bee26[_0x133bc3(0x220)]();console[_0x133bc3(0x203)]('[翰林院-日志]\x20忆识存入API错误:',_0x3adbb2);throw new Error(_0x133bc3(0x244)+_0x3bee26['status']+':\x20'+_0x3adbb2);}return{'success':!![],'count':_0xb0b597[_0x133bc3(0x241)]};}async function getVectorCount(_0xd0f383=null,_0x317c18=_0x54d6e8(0x22a)){const _0xa27903=_0x54d6e8,_0x5eeb4d=getCharacterStableId();if(_0xd0f383){const _0x5e4960=_0x317c18===_0xa27903(0x20d)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x2dfce3=_0x5e4960[_0xd0f383];if(!_0x2dfce3)return console[_0xa27903(0x29a)](_0xa27903(0x23d)+_0x317c18+_0xa27903(0x27e)+_0xd0f383+_0xa27903(0x225)),0x0;const _0x241832=_0x317c18===_0xa27903(0x20d)?_0x2dfce3[_0xa27903(0x2c6)]||GLOBAL_SCOPE_ID:_0x5eeb4d,_0x1ab412=_0x241832+'_'+_0xd0f383;return await countVectorsInCollection(_0x1ab412);}else{console[_0xa27903(0x28b)](_0xa27903(0x2b9));const _0x48b323=Object[_0xa27903(0x267)](getLocalKnowledgeBases()),_0x17f796=Object[_0xa27903(0x267)](getGlobalKnowledgeBases()),_0x29fb6f=[];_0x48b323[_0xa27903(0x286)](_0x2905f0=>{const _0x118e3f=_0xa27903,_0x8c3760=_0x5eeb4d+'_'+_0x2905f0['id'];_0x29fb6f[_0x118e3f(0x1e1)](countVectorsInCollection(_0x8c3760));}),_0x17f796[_0xa27903(0x286)](_0x5df13a=>{const _0x5ba7e3=_0xa27903,_0x133eb8=_0x5df13a['owner']||GLOBAL_SCOPE_ID,_0x530082=_0x133eb8+'_'+_0x5df13a['id'];_0x29fb6f[_0x5ba7e3(0x1e1)](countVectorsInCollection(_0x530082));});const _0x3fc305=await _0x5bce7c();_0x29fb6f[_0xa27903(0x1e1)](countVectorsInCollection(_0x3fc305));const _0x5a9cbd=await Promise[_0xa27903(0x20b)](_0x29fb6f),_0x6ab812=_0x5a9cbd['reduce']((_0x59aa08,_0x2595bc)=>_0x59aa08+_0x2595bc,0x0);return console[_0xa27903(0x28b)](_0xa27903(0x1db)+_0x6ab812),_0x6ab812;}}async function countVectorsInCollection(_0x4f3edc){const _0x1d4a6e=_0x54d6e8;if(!_0x4f3edc)return 0x0;console[_0x1d4a6e(0x28b)](_0x1d4a6e(0x1f0)+_0x4f3edc);const _0x356795={'collectionId':_0x4f3edc,'source':_0x1d4a6e(0x1e2),'embeddings':{}};try{const _0x51c8f5=await fetch(_0x1d4a6e(0x2b6),{'method':_0x1d4a6e(0x21e),'headers':context[_0x1d4a6e(0x246)](),'body':JSON['stringify'](_0x356795)});if(!_0x51c8f5['ok']){if(_0x51c8f5['status']===0x194)console[_0x1d4a6e(0x28b)](_0x1d4a6e(0x1fa)+_0x4f3edc+_0x1d4a6e(0x23b));else{const _0x8e0a9a=await _0x51c8f5[_0x1d4a6e(0x220)]();console['warn'](_0x1d4a6e(0x234)+_0x4f3edc+_0x1d4a6e(0x238)+_0x51c8f5['status']+'):',_0x8e0a9a);}return 0x0;}const _0x35e7dd=await _0x51c8f5[_0x1d4a6e(0x223)]();let _0x1b45a3=0x0;if(Array[_0x1d4a6e(0x240)](_0x35e7dd))_0x1b45a3=_0x35e7dd[_0x1d4a6e(0x241)];else _0x35e7dd&&_0x35e7dd['hashes']&&(_0x1b45a3=_0x35e7dd[_0x1d4a6e(0x279)][_0x1d4a6e(0x241)]);return _0x1b45a3;}catch(_0x3e4704){return console['error'](_0x1d4a6e(0x25c)+_0x4f3edc+_0x1d4a6e(0x269),_0x3e4704),0x0;}}async function purgeStorage(_0x2da48e=null){const _0x362ebe=_0x54d6e8;console[_0x362ebe(0x28b)](_0x362ebe(0x2a6));const _0x6c81d1=_0x2da48e||await getCollectionId();if(!_0x6c81d1)return console[_0x362ebe(0x203)](_0x362ebe(0x2ae)),toastr[_0x362ebe(0x203)](_0x362ebe(0x2ba)),![];console[_0x362ebe(0x28b)](_0x362ebe(0x255)+_0x6c81d1);const _0x27ce3d={'collectionId':_0x6c81d1};console[_0x362ebe(0x28b)](_0x362ebe(0x24f),JSON[_0x362ebe(0x29c)](_0x27ce3d,null,0x2));const _0x34f6ac=await fetch('/api/vector/purge',{'method':_0x362ebe(0x21e),'headers':context[_0x362ebe(0x246)](),'body':JSON[_0x362ebe(0x29c)](_0x27ce3d)});console[_0x362ebe(0x28b)](_0x362ebe(0x278)+_0x34f6ac[_0x362ebe(0x1e9)]);if(!_0x34f6ac['ok']){const _0x444887=await _0x34f6ac[_0x362ebe(0x220)]();console[_0x362ebe(0x203)](_0x362ebe(0x206),_0x444887);}else console[_0x362ebe(0x28b)](_0x362ebe(0x24a));return _0x34f6ac['ok'];}function _0xef88(){const _0x5d6b2b=['mes','includes','61112rcxDHS','start','abs','\x20失败:\x20','rerank_score','random','findIndex','retrieval','[翰林院-日志]\x20所有知识库统计完成,总向量数:\x20','min','\x20返回\x20','top_n','[翰林院-核心]\x20文本录入失败:\x20','queryMessageCount','push','webllm','\x22\x20已删除。','世界书','第1章','flat','[翰林院-核心]\x20凝识任务已锁定知识库:\x20','用户取消了迁移操作','status','newId','\x20记录凝识范围:\x20','[翰林院-核心]\x20知识库\x20','$1','lorebook','14668VCEQfi','[翰林院-日志]\x20统计目标集合ID:\x20','[翰林院-日志]\x20查询知识库\x20','\x20失败,删除操作中止。','trim','[翰林院-核心]\x20已为宝库\x20','legacy','\x20(ID:\x20','\x20及其向量数据。','embeddings','[翰林院-日志]\x20正在查询知识库:\x20','[翰林院-日志]\x20集合\x20','[翰林院-Rerank]\x20元数据加权排序完成。','aborted','novel','name','index','[翰林院]\x20未能获取SillyTavern上下文,初始化失败。','bookName','[翰林院-核心]\x20聊天记录凝识失败:\x20','error','262662eXVfFR','/api/vector/insert','[翰林院-日志]\x20清空宝库API错误:','84WxgOjN','[翰林院-迁移]\x20用户确认迁移,正在处理旧宝库:\x20','\x27的文本分割成\x20','/api/vector/query','all','\x20不存在,返回空数组。','global','未知角色','toLowerCase','\x20添加新知识库:\x20','filter','comment','charCodeAt','getContext',',将清空集合:\x20','删除知识库失败,未能清空后端数据。','\x0a','has','[翰林院-日志]\x20开始多知识库向量查询...','original_index','rearrangeChat','翰林院忆识核心已启动\x20(V5.2-集成版),已注册到全局\x20hanlinyuanRagProcessor\x20对象。','部分]','POST',',\x20第','text','template','检测到旧版数据。此操作将把旧数据迁移到新格式,过程不可逆,是否继续?','json','[翰林院-分块]\x20未知的来源类型\x20\x27','\x20的知识库。','user','未知小说','[翰林院-核心]\x20成功删除知识库\x20','[翰林院-日志]\x20去重后剩余\x20','local','Rerank失败:\x20','hanlinyuanRagProcessor','\x20个知识块,准备入库。','key','[翰林院-核心]\x20聊天记录凝识完成,成功插入\x20','toString','final_score','add','】已成功移动到','[翰林院-日志]\x20获取集合\x20','condensationHistory','is_user','529349lkmgvj','\x20列表API时出现问题\x20(状态:\x20','[翰林院-配置]\x20为旧版知识库\x20','replace','\x20不存在,计为\x200。','[翰林院-配置]\x20','[翰林院-计数]\x20在作用域\x20\x27','manual','AbortError','isArray','length','chat','oldId','忆识存入API错误\x20','核心未初始化','getRequestHeaders','[翰林院-迁移]\x20旧宝库已清空。','[翰林院-核心]\x20检测到同名知识库\x20\x22','test','[翰林院-日志]\x20清空宝库API调用成功。','hybrid_alpha','notify','聊天记录\x20#','clearJob','[翰林院-日志]\x20发送到\x20/api/vector/purge\x20的请求体:','reduce','enabled','extensionSettings','(已锁定:\x20','sourceName','[翰林院-日志]\x20清空目标集合ID:\x20','聊天记录:\x20','[来源:\x20聊天记录,\x20楼层:\x20#','chat_history','find','文本块和向量数量不匹配','[翰林院-核心]\x20将来源\x27','[翰林院-日志]\x20统计集合\x20','messageTypes','now','小说:\x20','[翰林院-核心]\x20已锁定忆识宝库ID:\x20','知识库名称不能为空','end','scope','[翰林院-迁移]\x20用户取消了迁移操作。','\x20个块。','\x20补充所有者ID:\x20','values','7tfqHXM','\x20时发生网络错误:','\x27,使用通用分块逻辑。','object','\x20(集合ID:\x20',']\x20的消息已成功凝识。','手动录入','insertVectors\x20必须接收一个有效的\x20collectionId\x20参数。','未分类世界书','3129mfiGNl','25sdVrwD','getTime','知识库【','task_','[翰林院-核心]\x20准备删除知识库\x20','advanced','[翰林院-日志]\x20/api/vector/purge\x20响应状态:\x20','hashes','rerank','quiet','凝识之权未开启','[翰林院-核心]\x20准备为任务\x20\x22','\x27\x20中未找到ID为\x20',',\x20第1卷,\x20第1章,\x20第','知识库\x20\x22','[翰林院-日志]\x20知识库\x20','\x22,将数据合并入库。','message','score','\x20(范围:\x20','forEach','batchSize','substring','max','HANLINYUAN_RAG','log','join','%%HANLINYUAN_RAG_INJECTION%%','\x20个向量条目。','移动失败:未找到源条目。','source','_global','info','metadata','initialized','聊天记录','toISOString','entryName','floor','injection','warn','1613310nOTImO','stringify','results','外部Rerank完成','\x20失败:','toLocaleString','data','knowledgeBases','[翰林院-核心]\x20清空向量集合\x20','slice','map','[翰林院-日志]\x20开始清空宝库...','\x22\x20创建专属知识库...','手动录入:\x20','[翰林院-核心]\x20文本录入任务被用户中止。','vector','send_date','[翰林院-日志]\x20所有知识库查询完毕,共获得\x20','在源作用域\x20\x27','[翰林院-日志]\x20无法确定要清空的目标集合ID。',')\x20的状态已切换为:\x20','第1卷','success','3072312HceboQ','depth','zh-CN','[翰林院-核心]\x20processCondensation\x20失败:','/api/vector/list','saveProgress','sort','[翰林院-日志]\x20开始获取所有知识库的向量总数...','无法确定要清空的目标宝库。','[翰林院-核心]\x20成功插入\x20','\x20条初步结果。','[翰林院-迁移]\x20集合\x20','relevance_score','[翰林院]\x20检索或注入时发生错误:','77mviEMN','position','[翰林院-核心]\x20ingestTextToHanlinyuan\x20失败:','\x20条结果。','condensation','[翰林院-Rerank]\x20开始元数据加权最终排序...','owner','bianzhuan'];_0xef88=function(){return _0x5d6b2b;};return _0xef88();}function getMessagesForCondensation(_0x16dd8d=null){const _0x3e7d50=_0x54d6e8;if(!settings[_0x3e7d50(0x2c4)][_0x3e7d50(0x251)])return showNotification(_0x3e7d50(0x27c),'warning'),[];const {layerStart:_0x504fe5,layerEnd:_0x3606e0}=settings[_0x3e7d50(0x2c4)],_0x19beb2=_0x16dd8d||settings[_0x3e7d50(0x2c4)][_0x3e7d50(0x25d)],_0x4bcd25=context['chat'][_0x3e7d50(0x241)],_0x26d5d5=Math[_0x3e7d50(0x289)](0x0,_0x504fe5-0x1),_0x43f03b=_0x3606e0===0x0||_0x3606e0>_0x4bcd25?_0x4bcd25:Math[_0x3e7d50(0x1dc)](_0x4bcd25,_0x3606e0),_0x161be2=context[_0x3e7d50(0x242)]['slice'](_0x26d5d5,_0x43f03b);return _0x161be2['filter'](_0x79a5e0=>{const _0x1937b0=_0x3e7d50,_0x157ced=_0x79a5e0[_0x1937b0(0x236)]===!![],_0x58ba7a=_0x79a5e0[_0x1937b0(0x236)]===![];if(!_0x79a5e0[_0x1937b0(0x2c8)]||!_0x79a5e0[_0x1937b0(0x2c8)][_0x1937b0(0x1f3)]())return![];return _0x19beb2[_0x1937b0(0x226)]&&_0x157ced||_0x19beb2['ai']&&_0x58ba7a;});}async function processCondensation(_0x4d5bfa,_0x35d52b=()=>{},_0x296f54=null){const _0x2fe584=_0x54d6e8;if(!_0x4d5bfa||_0x4d5bfa[_0x2fe584(0x241)]===0x0)return{'success':![],'error':'No\x20messages\x20to\x20process.'};try{let _0x181d3f,_0x9d939c;const _0x33a404=getCharacterName()||'未知角色';if(_0x296f54){const _0x36a089=_0x296f54[_0x2fe584(0x1d4)]??'?',_0x16aeb5=_0x296f54[_0x2fe584(0x262)]===0x0?'末':_0x296f54[_0x2fe584(0x262)]??'?';_0x181d3f=_0x33a404+':\x20'+_0x36a089+'楼-'+_0x16aeb5+'楼';}else{const _0x55a42c=new Date()[_0x2fe584(0x2a0)]('zh-CN',{'hour12':![]});_0x181d3f=_0x2fe584(0x256)+_0x55a42c;}const _0x252de2=Object['values'](getLocalKnowledgeBases()),_0x5420c1=_0x252de2[_0x2fe584(0x259)](_0x3bbf44=>_0x3bbf44['name']===_0x181d3f);if(_0x5420c1)_0x9d939c=_0x5420c1['id'],_0x35d52b('[翰林院-核心]\x20检测到同名知识库\x20\x22'+_0x181d3f+_0x2fe584(0x282),_0x2fe584(0x292));else{_0x35d52b('[翰林院-核心]\x20准备为任务\x20\x22'+_0x181d3f+'\x22\x20创建专属知识库...',_0x2fe584(0x292));const _0x1ce0b5=addKnowledgeBase(_0x181d3f);_0x9d939c=_0x1ce0b5['id'];}const _0x50e7a5=getCharacterStableId(),_0x2bf790=_0x50e7a5+'_'+_0x9d939c;_0x35d52b(_0x2fe584(0x1e7)+_0x181d3f+_0x2fe584(0x26c)+_0x2bf790+')','success');const _0x1eb868=[],_0x1c0773=context['chat'];for(const _0xb3dece of _0x4d5bfa){const _0x3a06d7=(_0xb3dece[_0x2fe584(0x2c8)]||'')[_0x2fe584(0x23a)](/<[^>]*>/g,'')['trim']();if(_0x3a06d7['length']===0x0)continue;let _0x5a8356;if(_0xb3dece[_0x2fe584(0x298)]!==undefined&&_0xb3dece[_0x2fe584(0x298)]!==null)_0x5a8356=_0xb3dece['floor'];else{const _0x10c644=_0x1c0773[_0x2fe584(0x1d9)](_0xa96391=>_0xa96391===_0xb3dece);_0x5a8356=_0x10c644!==-0x1?_0x10c644+0x1:-0x1;}const _0x5c0556=new Date(_0xb3dece[_0x2fe584(0x2ab)]),_0x44cbf6=isNaN(_0x5c0556[_0x2fe584(0x273)]())?new Date()[_0x2fe584(0x296)]():_0x5c0556[_0x2fe584(0x296)](),_0x34d3dd=splitIntoChunks(_0x3a06d7,_0x2fe584(0x258),{'floor':_0x5a8356,'is_user':_0xb3dece['is_user'],'timestamp':_0x44cbf6});_0x1eb868[_0x2fe584(0x1e1)](..._0x34d3dd);}if(_0x1eb868[_0x2fe584(0x241)]===0x0)return{'success':!![],'count':0x0};_0x35d52b('[翰林院-核心]\x20已将\x20'+_0x4d5bfa['length']+'\x20条消息分解为\x20'+_0x1eb868['length']+_0x2fe584(0x22d),_0x2fe584(0x292));const _0x2eae52=settings[_0x2fe584(0x1da)][_0x2fe584(0x287)]||0x5;let _0x35b8df=0x0;for(let _0x226e40=0x0;_0x226e40<_0x1eb868[_0x2fe584(0x241)];_0x226e40+=_0x2eae52){const _0x41fd88=_0x1eb868[_0x2fe584(0x2a4)](_0x226e40,_0x226e40+_0x2eae52),_0x1f467d=_0x41fd88[_0x2fe584(0x2a5)](_0x4e4fea=>_0x4e4fea[_0x2fe584(0x220)]),_0x58ebe6=await getEmbeddings(_0x1f467d);if(_0x41fd88[_0x2fe584(0x241)]!==_0x58ebe6[_0x2fe584(0x241)])throw new Error(_0x2fe584(0x25a));const _0x483083=_0x41fd88[_0x2fe584(0x2a5)]((_0x2ae9f7,_0x7ae9a3)=>({..._0x2ae9f7,'vector':_0x58ebe6[_0x7ae9a3]}));await insertVectors(_0x483083,null,_0x2bf790),_0x35b8df+=_0x41fd88[_0x2fe584(0x241)];}if(_0x296f54){const _0x599789=_0x296f54[_0x2fe584(0x262)]===0x0?context['chat'][_0x2fe584(0x241)]:_0x296f54[_0x2fe584(0x262)],_0xe8b048=getCharacterStableId();!settings[_0x2fe584(0x235)][_0xe8b048]&&(settings[_0x2fe584(0x235)][_0xe8b048]={}),settings[_0x2fe584(0x235)][_0xe8b048][_0x2bf790]={'start':_0x296f54[_0x2fe584(0x1d4)],'end':_0x599789,'timestamp':new Date()['toISOString']()},saveSettings(),_0x35d52b(_0x2fe584(0x1f4)+_0x2bf790+_0x2fe584(0x1eb)+_0x296f54[_0x2fe584(0x1d4)]+'-'+_0x599789,_0x2fe584(0x292));}_0x35d52b(_0x2fe584(0x22f)+_0x35b8df+'\x20个条目。',_0x2fe584(0x2b1));const _0x216f7d=_0x4d5bfa[_0x2fe584(0x2a5)](_0x19a2d4=>{const _0xbe8fdf=_0x2fe584,_0x5f5b6b=_0x1c0773['findIndex'](_0xb7660d=>_0xb7660d===_0x19a2d4),_0x5e0ee5=_0x5f5b6b!==-0x1?_0x5f5b6b+0x1:-0x1,_0x2c94e0=_0x19a2d4[_0xbe8fdf(0x236)]?'用户':getCharacterName()||'AI';return'['+_0x2c94e0+'\x20-\x20楼层\x20#'+_0x5e0ee5+_0xbe8fdf(0x26d);});return{'success':!![],'count':_0x35b8df,'messages':_0x216f7d};}catch(_0x4bf0a3){return console[_0x2fe584(0x203)](_0x2fe584(0x2b5),_0x4bf0a3),_0x35d52b(_0x2fe584(0x202)+_0x4bf0a3[_0x2fe584(0x283)],_0x2fe584(0x203)),{'success':![],'error':_0x4bf0a3['message']};}}async function rerankResults(_0x5dba89,_0xae171c,_0x2304e3){const _0x4bd2bb=_0x54d6e8;let _0x3b655f=_0x5dba89;if(_0x2304e3[_0x4bd2bb(0x27a)]['enabled']&&_0x5dba89[_0x4bd2bb(0x241)]>0x0){console[_0x4bd2bb(0x28b)]('[翰林院-Rerank]\x20开始外部API重排序...');try{const _0x24c499=_0x5dba89[_0x4bd2bb(0x2a5)](_0x139803=>_0x139803[_0x4bd2bb(0x220)]),_0x48f475=await executeRerank(_0xae171c,_0x24c499,_0x2304e3[_0x4bd2bb(0x27a)]),_0x2270dd=_0x5dba89['map']((_0x2b8cb2,_0x487016)=>({..._0x2b8cb2,'original_index':_0x487016}));_0x3b655f=_0x2270dd[_0x4bd2bb(0x2a5)](_0x5b2277=>{const _0x4895f5=_0x4bd2bb,_0x1f3ad5=_0x48f475[_0x4895f5(0x29d)][_0x4895f5(0x259)](_0x47e8ab=>_0x47e8ab[_0x4895f5(0x1ff)]===_0x5b2277[_0x4895f5(0x21a)]),_0x1745ea=_0x1f3ad5?_0x1f3ad5[_0x4895f5(0x2be)]:0x0;return{..._0x5b2277,'rerank_score':_0x1745ea};});if(_0x2304e3[_0x4bd2bb(0x27a)][_0x4bd2bb(0x24c)])showNotification(_0x4bd2bb(0x29e),_0x4bd2bb(0x2b1));}catch(_0x5a0289){console[_0x4bd2bb(0x203)]('[翰林院-Rerank]\x20外部Rerank失败,将仅使用内部加权。',_0x5a0289);if(_0x2304e3[_0x4bd2bb(0x27a)][_0x4bd2bb(0x24c)])showNotification(_0x4bd2bb(0x22b)+_0x5a0289[_0x4bd2bb(0x283)],_0x4bd2bb(0x203));_0x3b655f['forEach'](_0x5aecec=>_0x5aecec[_0x4bd2bb(0x1d7)]=0x0);}}else _0x3b655f[_0x4bd2bb(0x286)](_0x412d55=>_0x412d55[_0x4bd2bb(0x1d7)]=0x0);console[_0x4bd2bb(0x28b)](_0x4bd2bb(0x2c5));const _0x3e3567=context[_0x4bd2bb(0x242)][_0x4bd2bb(0x241)],_0x503273=_0x2304e3[_0x4bd2bb(0x27a)][_0x4bd2bb(0x24b)],_0x447c47=_0x3b655f[_0x4bd2bb(0x2a5)](_0x57380d=>{const _0x100336=_0x4bd2bb;let _0x21dd56=0x1;const _0x14197e=_0x57380d[_0x100336(0x293)]||{};switch(_0x14197e[_0x100336(0x290)]){case _0x100336(0x1ee):_0x21dd56*=1.2;break;case'manual':_0x21dd56*=1.1;break;case _0x100336(0x258):if(_0x14197e['floor']&&_0x3e3567>0x0){const _0x5ec00e=_0x14197e[_0x100336(0x298)]/_0x3e3567;_0x21dd56*=0x1+_0x5ec00e;}break;}const _0x4ca68d=_0x57380d[_0x100336(0x1d7)]*_0x503273+(_0x57380d[_0x100336(0x284)]||0x0)*(0x1-_0x503273),_0x44e284=_0x4ca68d*_0x21dd56;return{..._0x57380d,'final_score':_0x44e284};});return _0x447c47[_0x4bd2bb(0x2b8)]((_0x33e93b,_0x767ab7)=>(_0x767ab7[_0x4bd2bb(0x231)]||0x0)-(_0x33e93b[_0x4bd2bb(0x231)]||0x0)),console[_0x4bd2bb(0x28b)](_0x4bd2bb(0x1fb)),_0x447c47[_0x4bd2bb(0x2a4)](0x0,_0x2304e3[_0x4bd2bb(0x27a)][_0x4bd2bb(0x1de)]);}async function rearrangeChat(_0x570493,_0x45a138,_0x4ec855,_0xc03d27){const _0x458262=_0x54d6e8;setExtensionPrompt(_0x458262(0x28a),'',settings['injection'][_0x458262(0x2c1)],settings[_0x458262(0x299)][_0x458262(0x2b3)],![],settings[_0x458262(0x299)]['depth_role']);if(_0xc03d27===_0x458262(0x27b)||!settings[_0x458262(0x1da)]['enabled'])return;const _0x48c98e=_0x570493[_0x458262(0x2a4)](-settings['advanced'][_0x458262(0x1e0)]);if(_0x48c98e[_0x458262(0x241)]===0x0)return;const _0x41b971=_0x48c98e[_0x458262(0x2a5)](_0x3b6956=>_0x3b6956[_0x458262(0x2c8)])[_0x458262(0x28c)]('\x20')['replace'](/<[^>]*>/g,'')[_0x458262(0x1f3)]();if(!_0x41b971)return;try{const _0x4d67f9=await queryVectors(_0x41b971);if(_0x4d67f9[_0x458262(0x241)]===0x0)return;const _0x12f34a=await rerankResults(_0x4d67f9,_0x41b971,settings);if(_0x12f34a[_0x458262(0x241)]===0x0)return;const _0xa02313=_0x12f34a['map'](_0x1b5fd4=>_0x1b5fd4['text'])[_0x458262(0x28c)]('\x0a\x0a');let _0x39c725=settings[_0x458262(0x299)][_0x458262(0x221)]['replace']('{{text}}',_0xa02313);_0x39c725[_0x458262(0x1f3)]()&&(_0x39c725=_0x458262(0x28d)+_0x39c725),setExtensionPrompt(_0x458262(0x28a),_0x39c725,settings[_0x458262(0x299)][_0x458262(0x2c1)],settings[_0x458262(0x299)][_0x458262(0x2b3)],![],settings['injection']['depth_role']);}catch(_0x183208){console[_0x458262(0x203)](_0x458262(0x2bf),_0x183208);if(settings[_0x458262(0x1da)]['notify'])showNotification('忆识检索失败:\x20'+_0x183208['message'],_0x458262(0x203));}}async function moveKnowledgeBase(_0x322826,_0x53ed8c){const _0x3a3d93=_0x54d6e8,_0x31160a=_0x53ed8c===_0x3a3d93(0x20d)?_0x3a3d93(0x22a):'global',_0x5be5eb=getCharacterStableId();if(!_0x5be5eb&&_0x31160a===_0x3a3d93(0x22a)){toastr[_0x3a3d93(0x203)]('移动失败:没有当前角色,无法移入局部知识库。');return;}const _0x1372e2=_0x53ed8c===_0x3a3d93(0x20d)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x5c5d20=_0x31160a==='global'?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x142069=_0x1372e2[_0x322826];if(!_0x142069){const _0x1937be=_0x3a3d93(0x2ad)+_0x53ed8c+_0x3a3d93(0x27e)+_0x322826+_0x3a3d93(0x225);console[_0x3a3d93(0x203)](_0x3a3d93(0x23c)+_0x1937be),toastr['error'](_0x3a3d93(0x28f));return;}_0x53ed8c===_0x3a3d93(0x22a)&&_0x31160a===_0x3a3d93(0x20d)&&!_0x142069['owner']&&(console[_0x3a3d93(0x28b)](_0x3a3d93(0x239)+_0x322826+_0x3a3d93(0x266)+_0x5be5eb),_0x142069[_0x3a3d93(0x2c6)]=_0x5be5eb);delete _0x1372e2[_0x322826],_0x5c5d20[_0x322826]=_0x142069,saveSettings();const _0x212c0c=_0x3a3d93(0x274)+_0x142069['name']+_0x3a3d93(0x233)+(_0x31160a===_0x3a3d93(0x20d)?'全局':'局部')+'。';console[_0x3a3d93(0x28b)]('[翰林院-配置]\x20'+_0x212c0c);}async function getAllVectorsFromCollection(_0x31242c){const _0x5b7bf6=_0x54d6e8,_0x79d14e='*',_0x424a54={'collectionId':_0x31242c,'searchText':_0x79d14e,'topK':0x2710,'threshold':0x0,'source':_0x5b7bf6(0x1e2),'embeddings':{}},_0x1b93f5=(await getEmbeddings([_0x79d14e]))[0x0];_0x424a54[_0x5b7bf6(0x1f8)]={[_0x79d14e]:_0x1b93f5};const _0x3d18a4=await fetch(_0x5b7bf6(0x20a),{'method':_0x5b7bf6(0x21e),'headers':context[_0x5b7bf6(0x246)](),'body':JSON['stringify'](_0x424a54)});if(!_0x3d18a4['ok']){if(_0x3d18a4[_0x5b7bf6(0x1e9)]===0x194)return console['log'](_0x5b7bf6(0x2bd)+_0x31242c+_0x5b7bf6(0x20c)),[];const _0x794023=await _0x3d18a4[_0x5b7bf6(0x220)]();throw new Error('查询集合\x20'+_0x31242c+_0x5b7bf6(0x1d6)+_0x794023);}const _0x522a99=await _0x3d18a4[_0x5b7bf6(0x223)]();return _0x522a99[_0x5b7bf6(0x293)]||_0x522a99[_0x5b7bf6(0x29d)]||_0x522a99[_0x5b7bf6(0x2a1)]||[];}
+'use strict';const _0x10918d=_0xedaa;(function(_0x2e866d,_0x3f31c8){const _0x337c51=_0xedaa,_0x14944d=_0x2e866d();while(!![]){try{const _0x24a2dc=-parseInt(_0x337c51(0x25c))/0x1*(-parseInt(_0x337c51(0x1a7))/0x2)+-parseInt(_0x337c51(0x173))/0x3*(parseInt(_0x337c51(0x21f))/0x4)+-parseInt(_0x337c51(0x1ef))/0x5*(-parseInt(_0x337c51(0x22f))/0x6)+-parseInt(_0x337c51(0x262))/0x7*(parseInt(_0x337c51(0x183))/0x8)+-parseInt(_0x337c51(0x225))/0x9*(parseInt(_0x337c51(0x1df))/0xa)+-parseInt(_0x337c51(0x268))/0xb*(parseInt(_0x337c51(0x1d8))/0xc)+-parseInt(_0x337c51(0x18a))/0xd*(-parseInt(_0x337c51(0x194))/0xe);if(_0x24a2dc===_0x3f31c8)break;else _0x14944d['push'](_0x14944d['shift']());}catch(_0x581ba3){_0x14944d['push'](_0x14944d['shift']());}}}(_0x4bee,0x92589));import{extension_prompt_roles,setExtensionPrompt}from'/script.js';import*as _0x533d09 from'./utils/context-utils.js';import{getCollectionIdInfo,getCharacterId,getCharacterStableId}from'./utils/context-utils.js';import{defaultSettings as _0x1faf33}from'./rag-settings.js';import*as _0x4f3bd3 from'./ingestion-manager.js';import{getEmbeddings,fetchEmbeddingModels as _0x114c4c,fetchRerankModels as _0x290abb,executeRerank,testApiConnection as _0x3b687a}from'./rag-api.js';const MODULE_NAME=_0x10918d(0x270),OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME='vectors_rearrangeChat',GLOBAL_SCOPE_ID=_0x10918d(0x264);let context=null,settings=null,lockedCollectionId=null;function filterWorldbooks(_0x4aac41,_0xb1567d){const _0x1936fc=_0x10918d;if(!_0x4aac41||!_0x4aac41[_0x1936fc(0x1de)]())return _0xb1567d;const _0x4be4ca=_0x4aac41[_0x1936fc(0x263)]()['trim']();return _0xb1567d[_0x1936fc(0x178)](_0x58ca9a=>{const _0x1b02b6=_0x1936fc;return _0x58ca9a[_0x1b02b6(0x263)]()[_0x1b02b6(0x17e)](_0x4be4ca)||containsPinyinMatch(_0x58ca9a,_0x4be4ca);});}function filterWorldbookEntries(_0x376d83,_0x22d20a){const _0x547bbb=_0x10918d;if(!_0x376d83||!_0x376d83[_0x547bbb(0x1de)]())return _0x22d20a;const _0xdffb3e=_0x376d83['toLowerCase']()[_0x547bbb(0x1de)]();return _0x22d20a['filter'](_0x57717a=>{const _0x3c3a8c=_0x547bbb,_0x3038aa=[_0x57717a[_0x3c3a8c(0x191)]||'',_0x57717a[_0x3c3a8c(0x1ea)]||'',_0x57717a[_0x3c3a8c(0x21c)]||''][_0x3c3a8c(0x256)]('\x20')[_0x3c3a8c(0x263)]();return _0x3038aa['includes'](_0xdffb3e)||containsPinyinMatch(_0x57717a[_0x3c3a8c(0x191)]||'',_0xdffb3e);});}function _0xedaa(_0x19f7ec,_0x30c663){const _0x4bee98=_0x4bee();return _0xedaa=function(_0xedaabd,_0x496aa2){_0xedaabd=_0xedaabd-0x16d;let _0x13420a=_0x4bee98[_0xedaabd];return _0x13420a;},_0xedaa(_0x19f7ec,_0x30c663);}function containsPinyinMatch(_0x4a145c,_0xb75d04){const _0x7c2f4f=_0x10918d,_0x257166={'世界书':'sjshu','条目':_0x7c2f4f(0x1a9),'编纂':'bianzhuan','搜索':_0x7c2f4f(0x1cd)},_0x375e6a=_0x257166[_0x4a145c];return _0x375e6a&&_0x375e6a[_0x7c2f4f(0x17e)](_0xb75d04);}function highlightSearchMatch(_0x35e7c6,_0x39f3da){const _0x555269=_0x10918d;if(!_0x39f3da||!_0x39f3da[_0x555269(0x1de)]())return _0x35e7c6;const _0xc00606=new RegExp('('+_0x39f3da[_0x555269(0x1b0)](/[.*+?^${}()|[\]\\]/g,'\x5c$&')+')','gi');return _0x35e7c6[_0x555269(0x1b0)](_0xc00606,_0x555269(0x1f8));}function debounce(_0x4fc051,_0xb116de){let _0x2aa9bf;return function _0x2e3e0d(..._0x1c19d9){const _0x368589=()=>{clearTimeout(_0x2aa9bf),_0x4fc051(..._0x1c19d9);};clearTimeout(_0x2aa9bf),_0x2aa9bf=setTimeout(_0x368589,_0xb116de);};}export{initialize,getSettings,saveSettings,resetSettings,_0x3b687a as testApiConnection,_0x114c4c as fetchEmbeddingModels,_0x290abb as fetchRerankModels,getVectorCount,purgeStorage,getMessagesForCondensation,processCondensation,ingestTextToHanlinyuan,getCollectionId,toggleSessionLock,isSessionLocked,getLockedSessionInfo,addKnowledgeBase,removeKnowledgeBase,getLocalKnowledgeBases,getGlobalKnowledgeBases,toggleKnowledgeBase,moveKnowledgeBase,filterWorldbooks,filterWorldbookEntries,highlightSearchMatch,debounce};function initialize(){const _0x502caa=_0x10918d;context=SillyTavern[_0x502caa(0x1bf)]();if(!context){console[_0x502caa(0x26c)]('[翰林院]\x20未能获取SillyTavern上下文,初始化失败。');return;}settings=getSettings(),!window['hanlinyuanRagProcessor']&&(window['hanlinyuanRagProcessor']={}),window[_0x502caa(0x213)][_0x502caa(0x172)]=rearrangeChat,window[_0x502caa(0x213)]['initialized']=!![],console[_0x502caa(0x21a)](_0x502caa(0x170));}async function ingestTextToHanlinyuan(_0x35ca18,_0xe6ef69=_0x10918d(0x24e),_0x35fb93={},_0x3ab962=()=>{},_0xb85115=null,_0x114abe=()=>{},_0x2d7c7a=()=>{},_0x58ebcf=null,_0x3191db=0x0){const _0x9c2abf=_0x10918d;if(!_0x35ca18||!_0x35ca18['trim']())return{'success':![],'error':_0x9c2abf(0x236)};if(!settings)return{'success':![],'error':_0x9c2abf(0x254)};try{const _0x322013=getCollectionIdInfo(),_0x4687a4=await _0x45ee52();if(_0x322013[_0x9c2abf(0x1e8)]&&_0x322013[_0x9c2abf(0x1e8)]===_0x4687a4&&_0x322013[_0x9c2abf(0x1e8)]!==_0x322013['newId']){const _0x587279=confirm(_0x9c2abf(0x26a));if(_0x587279)_0x114abe('[翰林院-迁移]\x20用户确认迁移,正在处理旧宝库:\x20'+_0x322013['oldId'],_0x9c2abf(0x242)),await purgeStorage(_0x322013[_0x9c2abf(0x1e8)]),_0x114abe(_0x9c2abf(0x1a6),_0x9c2abf(0x1e7));else return _0x114abe(_0x9c2abf(0x1e3),'info'),toastr[_0x9c2abf(0x1ee)](_0x9c2abf(0x258)),{'success':![],'error':'用户取消了迁移操作'};}let _0x491a8b,_0x4344ae;const _0x59df0a=new Date()[_0x9c2abf(0x214)]('zh-CN',{'hour12':![]}),_0x3e621f=getCharacterName()||_0x9c2abf(0x1bd);switch(_0xe6ef69){case'chat_history':const _0x1b0379=_0x35fb93['range']||{},_0x48e9f6=_0x1b0379['start']??'?',_0x4f6ca4=_0x1b0379['end']===0x0?'末':_0x1b0379[_0x9c2abf(0x20e)]??'?';_0x491a8b=_0x3e621f+':\x20'+_0x48e9f6+'楼-'+_0x4f6ca4+'楼';break;case'lorebook':const _0x1f2146=_0x35fb93[_0x9c2abf(0x218)]||'未分类世界书',_0x2a69b1=_0x35fb93[_0x9c2abf(0x196)]||_0x9c2abf(0x1a5);_0x491a8b=_0x1f2146+':\x20'+_0x2a69b1;break;case _0x9c2abf(0x185):_0x491a8b=_0x9c2abf(0x221)+(_0x35fb93[_0x9c2abf(0x17a)]||_0x9c2abf(0x197));break;case _0x9c2abf(0x24e):default:_0x491a8b=_0x9c2abf(0x20f)+_0x59df0a;break;}const _0x20bacd=Object[_0x9c2abf(0x188)](getKnowledgeBases()),_0x2b2d3b=_0x20bacd[_0x9c2abf(0x206)](_0x1da126=>_0x1da126['name']===_0x491a8b);if(_0x2b2d3b)_0x4344ae=_0x2b2d3b['id'],_0x114abe(_0x9c2abf(0x1fb)+_0x491a8b+'\x22,将数据合并入库。',_0x9c2abf(0x1ee));else{_0x114abe(_0x9c2abf(0x18f)+_0x491a8b+'\x22\x20创建专属知识库...',_0x9c2abf(0x1ee));const _0x2de0c0=addKnowledgeBase(_0x491a8b);_0x4344ae=_0x2de0c0['id'];}const _0x43730c=getCharacterStableId(),_0x1b3a94=_0x43730c+'_'+_0x4344ae;_0x114abe(_0x9c2abf(0x1f1)+_0x491a8b+_0x9c2abf(0x23f)+_0x1b3a94+')',_0x9c2abf(0x1e7)),_0x114abe(_0x9c2abf(0x1b7)+_0x1b3a94,_0x9c2abf(0x1ee)),_0x3ab962({'message':_0x9c2abf(0x207),'processed':0x0,'total':0x1});const _0x36c4b5=splitIntoChunks(_0x35ca18,_0xe6ef69,_0x35fb93),_0x439e21=_0x36c4b5[_0x9c2abf(0x233)];if(_0xb85115?.[_0x9c2abf(0x22d)])throw new Error(_0x9c2abf(0x1f2));_0x114abe(_0x9c2abf(0x1b6)+_0x491a8b+'\x27的文本分割成\x20'+_0x439e21+_0x9c2abf(0x20b),'info');if(_0x439e21===0x0)return{'success':!![],'count':0x0};const _0x3c9802=settings['retrieval'][_0x9c2abf(0x1d5)]||0x5;let _0x368978=_0x3191db;for(let _0x55c771=_0x3191db;_0x55c771<_0x439e21;_0x55c771+=_0x3c9802){if(_0xb85115?.[_0x9c2abf(0x22d)])throw new Error(_0x9c2abf(0x1f2));const _0x4a2b41=_0x36c4b5[_0x9c2abf(0x19c)](_0x55c771,_0x55c771+_0x3c9802);_0x3ab962({'message':_0x9c2abf(0x1a0)+(_0x55c771+0x1)+'-'+(_0x55c771+_0x4a2b41['length'])+'\x20块','processed':_0x55c771,'total':_0x439e21});const _0x27cdb7=_0x4a2b41['map'](_0x48175b=>_0x48175b[_0x9c2abf(0x1c0)]),_0x587a92=await getEmbeddings(_0x27cdb7,_0xb85115);if(_0xb85115?.[_0x9c2abf(0x22d)])throw new Error('AbortError');if(_0x4a2b41[_0x9c2abf(0x233)]!==_0x587a92[_0x9c2abf(0x233)])throw new Error(_0x9c2abf(0x231));const _0x28cc07=_0x4a2b41[_0x9c2abf(0x201)]((_0x36c9ff,_0xd2676f)=>({..._0x36c9ff,'vector':_0x587a92[_0xd2676f]}));await insertVectors(_0x28cc07,_0xb85115,_0x1b3a94),_0x368978+=_0x4a2b41['length'],_0x58ebcf&&_0x4f3bd3[_0x9c2abf(0x20a)](_0x58ebcf,_0x368978,_0x439e21),await _0x2d7c7a();}return _0x58ebcf&&_0x4f3bd3[_0x9c2abf(0x228)](_0x58ebcf),_0x114abe(_0x9c2abf(0x1d1)+_0x368978+_0x9c2abf(0x261),_0x9c2abf(0x1e7)),{'success':!![],'count':_0x368978};}catch(_0x2affb1){if(_0x2affb1['name']==='AbortError'){_0x114abe(_0x9c2abf(0x174),'warn');throw _0x2affb1;}return console[_0x9c2abf(0x26c)]('[翰林院-核心]\x20ingestTextToHanlinyuan\x20失败:',_0x2affb1),_0x114abe(_0x9c2abf(0x25f)+_0x2affb1[_0x9c2abf(0x22c)],'error'),{'success':![],'error':_0x2affb1['message']};}}function getSettings(){const _0x4315c1=_0x10918d;if(!context||!context['extensionSettings'])return structuredClone(_0x1faf33);let _0x33827e=context[_0x4315c1(0x1f4)][MODULE_NAME];!_0x33827e&&(_0x33827e={},context['extensionSettings'][MODULE_NAME]=_0x33827e);_0x33827e[_0x4315c1(0x25d)]===undefined&&(_0x33827e[_0x4315c1(0x25d)]={});_0x33827e[_0x4315c1(0x266)]===undefined&&(_0x33827e[_0x4315c1(0x266)]={});for(const _0x9173ed in _0x1faf33){if(_0x33827e[_0x9173ed]===undefined)_0x33827e[_0x9173ed]=structuredClone(_0x1faf33[_0x9173ed]);else{if(typeof _0x1faf33[_0x9173ed]===_0x4315c1(0x16e)&&!Array[_0x4315c1(0x182)](_0x1faf33[_0x9173ed])&&_0x1faf33[_0x9173ed]!==null)for(const _0x2885ad in _0x1faf33[_0x9173ed]){_0x33827e[_0x9173ed][_0x2885ad]===undefined&&(_0x33827e[_0x9173ed][_0x2885ad]=_0x1faf33[_0x9173ed][_0x2885ad]);}}}return _0x33827e;}function saveSettings(){const _0x1475b5=_0x10918d;if(context)context[_0x1475b5(0x1c6)]();}function resetSettings(){const _0x51c253=_0x10918d;context&&(context[_0x51c253(0x1f4)][MODULE_NAME]=structuredClone(_0x1faf33),saveSettings());}function showNotification(_0x3373d5,_0x1b755d='info'){toastr[_0x1b755d](_0x3373d5);}function getTagForSource(_0x90347a){const _0x3f5e3e=_0x10918d;switch(_0x90347a){case'chat_history':return _0x3f5e3e(0x1d3);case _0x3f5e3e(0x20c):return'世界书';case'manual':return _0x3f5e3e(0x238);case _0x3f5e3e(0x185):return _0x3f5e3e(0x223);default:return'资料';}}function splitIntoChunks(_0x4c0dd9,_0x1daeac,_0x50cdf1={}){const _0x26e9f7=_0x10918d;switch(_0x1daeac){case _0x26e9f7(0x185):return _chunkForNovel(_0x4c0dd9,_0x50cdf1);case _0x26e9f7(0x26e):return _chunkForChatHistory(_0x4c0dd9,_0x50cdf1);case _0x26e9f7(0x20c):return _chunkForLorebook(_0x4c0dd9,_0x50cdf1);case'manual':return _chunkForManual(_0x4c0dd9,_0x50cdf1);default:console[_0x26e9f7(0x242)]('[翰林院-分块]\x20未知的来源类型\x20\x27'+_0x1daeac+_0x26e9f7(0x220));return _chunkForManual(_0x4c0dd9,{..._0x50cdf1,'sourceName':_0x50cdf1[_0x26e9f7(0x17a)]||'未知来源'});}}function _chunkForNovel(_0x127b0e,_0x289ca2){const _0x260a0f=_0x10918d,{chunkSize:_0x1ca321,overlap:_0x27f53d}=settings[_0x260a0f(0x1cc)],{sourceName:sourceName='小说'}=_0x289ca2,_0x38fb6e=[];if(!_0x127b0e||_0x1ca321<=0x0)return _0x38fb6e;const _0xef1374=/(第\s*[一二三四五六七八九十百千万零\d]+\s*卷)/gim,_0x2624a8=/(第\s*[一二三四五六七八九十百千万零\d]+\s*[章回节部])|^(Chapter\s+\d+)/gim;let _0x3e3493=0x0;const _0x330477=_0x127b0e[_0x260a0f(0x16f)]('\x0a');let _0x4f684e=_0x260a0f(0x24d),_0x5bee5d=_0x260a0f(0x22b),_0x5422ee=[];function _0x468b14(){const _0x2354f2=_0x260a0f;if(_0x5422ee[_0x2354f2(0x233)]===0x0)return;const _0x50d653=_0x5422ee['join']('\x0a');let _0x494f88=0x0,_0x2f0bbe=0x1;while(_0x494f88<_0x50d653['length']){const _0x479b1f=Math['min'](_0x494f88+_0x1ca321,_0x50d653['length']),_0x3cb53d=_0x50d653[_0x2354f2(0x23b)](_0x494f88,_0x479b1f);if(_0x3cb53d['trim']()['length']>0x0){const _0x43ec25={'source':'novel','sourceName':sourceName,'timestamp':new Date()['toISOString'](),'globalIndex':_0x3e3493++,'volume':_0x4f684e,'chapter':_0x5bee5d,'section':_0x2f0bbe},_0x259620=getTagForSource(_0x2354f2(0x185)),_0x1cac52=_0x2354f2(0x1b3)+sourceName+',\x20'+_0x4f684e+',\x20'+_0x5bee5d+',\x20第'+_0x2f0bbe+'节]',_0x275699='<'+_0x259620+'>\x0a'+_0x1cac52+'\x0a'+_0x3cb53d+_0x2354f2(0x175)+_0x259620+'>';_0x38fb6e[_0x2354f2(0x211)]({'text':_0x275699,'metadata':_0x43ec25}),_0x2f0bbe++;}_0x494f88+=_0x1ca321-_0x27f53d;if(_0x494f88>=_0x50d653[_0x2354f2(0x233)])break;}_0x5422ee=[];}for(const _0x273df8 of _0x330477){const _0x12eaa1=_0x273df8['trim']();if(_0xef1374['test'](_0x12eaa1))_0x468b14(),_0x4f684e=_0x12eaa1,_0x5bee5d=_0x260a0f(0x22b);else _0x2624a8[_0x260a0f(0x202)](_0x12eaa1)?(_0x468b14(),_0x5bee5d=_0x12eaa1):_0x5422ee[_0x260a0f(0x211)](_0x273df8);}_0x468b14();if(_0x38fb6e[_0x260a0f(0x233)]===0x0&&_0x127b0e[_0x260a0f(0x233)]>0x0){let _0x4c4dc0=0x0,_0x21efe6=0x1;while(_0x4c4dc0<_0x127b0e[_0x260a0f(0x233)]){const _0x4ca38c=Math[_0x260a0f(0x24c)](_0x4c4dc0+_0x1ca321,_0x127b0e[_0x260a0f(0x233)]),_0x566ab5=_0x127b0e[_0x260a0f(0x23b)](_0x4c4dc0,_0x4ca38c),_0x52727c={'source':_0x260a0f(0x185),'sourceName':sourceName,'timestamp':new Date()[_0x260a0f(0x181)](),'globalIndex':_0x38fb6e[_0x260a0f(0x233)],'volume':_0x260a0f(0x24d),'chapter':_0x260a0f(0x22b),'section':_0x21efe6},_0x17d916=getTagForSource('novel'),_0x8e64d2=_0x260a0f(0x1b3)+sourceName+_0x260a0f(0x267)+_0x21efe6+'节]',_0x3ec3bf='<'+_0x17d916+'>\x0a'+_0x8e64d2+'\x0a'+_0x566ab5+_0x260a0f(0x175)+_0x17d916+'>';_0x38fb6e[_0x260a0f(0x211)]({'text':_0x3ec3bf,'metadata':_0x52727c}),_0x21efe6++,_0x4c4dc0+=_0x1ca321-_0x27f53d;}}return _0x38fb6e;}function _chunkForChatHistory(_0x100047,_0x55e932){const _0x42ea36=_0x10918d,{chunkSize:_0xa698ed,overlap:_0x479e9e}=settings[_0x42ea36(0x1cc)],{floor:_0x47d9a8,is_user:_0x3ffa79,timestamp:_0x39c784}=_0x55e932,_0x338bac=[];if(!_0x100047||_0xa698ed<=0x0)return _0x338bac;let _0x444085=0x1,_0x4f194d=0x0;while(_0x4f194d<_0x100047[_0x42ea36(0x233)]){const _0x5dbdb2=Math['min'](_0x4f194d+_0xa698ed,_0x100047['length']),_0x31fbcf=_0x100047[_0x42ea36(0x23b)](_0x4f194d,_0x5dbdb2),_0x18267c='[来源:\x20聊天记录,\x20楼层:\x20#'+_0x47d9a8+_0x42ea36(0x189)+_0x444085+_0x42ea36(0x1f7),_0xc6b926=getTagForSource(_0x42ea36(0x26e)),_0x3287f9='<'+_0xc6b926+'>\x0a'+_0x18267c+'\x0a'+_0x31fbcf+_0x42ea36(0x175)+_0xc6b926+'>';_0x338bac[_0x42ea36(0x211)]({'text':_0x3287f9,'metadata':{'source':'chat_history','sourceName':_0x42ea36(0x1e0)+_0x47d9a8,'floor':_0x47d9a8,'part':_0x444085,'is_user':_0x3ffa79,'timestamp':_0x39c784}}),_0x444085++,_0x4f194d+=_0xa698ed-_0x479e9e;if(_0x4f194d>=_0x100047[_0x42ea36(0x233)])break;}return _0x338bac;}function _chunkForLorebook(_0x30e99a,_0x44e4f4){const _0x553aac=_0x10918d,{chunkSize:_0x13c029,overlap:_0x330b03}=settings['advanced'],{sourceName:sourceName='世界书条目'}=_0x44e4f4,_0xd1990f=[];if(!_0x30e99a||_0x13c029<=0x0)return _0xd1990f;let _0x2e53df=0x1,_0x265314=0x0;while(_0x265314<_0x30e99a[_0x553aac(0x233)]){const _0x547d80=Math[_0x553aac(0x24c)](_0x265314+_0x13c029,_0x30e99a[_0x553aac(0x233)]),_0x318591=_0x30e99a[_0x553aac(0x23b)](_0x265314,_0x547d80),_0x2ac9bf=_0x553aac(0x1ae)+sourceName+',\x20第'+_0x2e53df+'部分]',_0xd0baa1=getTagForSource(_0x553aac(0x20c)),_0x336307='<'+_0xd0baa1+'>\x0a'+_0x2ac9bf+'\x0a'+_0x318591+'\x0a'+_0xd0baa1+'>';_0xd1990f[_0x553aac(0x211)]({'text':_0x336307,'metadata':{'source':'lorebook','sourceName':sourceName,'part':_0x2e53df,'timestamp':new Date()[_0x553aac(0x181)]()}}),_0x2e53df++,_0x265314+=_0x13c029-_0x330b03;if(_0x265314>=_0x30e99a[_0x553aac(0x233)])break;}return _0xd1990f;}function _chunkForManual(_0x449811,_0x1d3bb2){const _0x3d2f38=_0x10918d,{chunkSize:_0x3c8a41,overlap:_0x493794}=settings[_0x3d2f38(0x1cc)],{sourceName:sourceName='手动录入'}=_0x1d3bb2,_0x4da1b2=[];if(!_0x449811||_0x3c8a41<=0x0)return _0x4da1b2;const _0x229e24=new Date(),_0x409b52=_0x229e24[_0x3d2f38(0x214)](_0x3d2f38(0x1ac));let _0x3c57e9=0x1,_0x21d43f=0x0;while(_0x21d43f<_0x449811[_0x3d2f38(0x233)]){const _0x4a06d6=Math[_0x3d2f38(0x24c)](_0x21d43f+_0x3c8a41,_0x449811[_0x3d2f38(0x233)]),_0x31e92f=_0x449811[_0x3d2f38(0x23b)](_0x21d43f,_0x4a06d6),_0x5290d1=_0x3d2f38(0x1b3)+sourceName+_0x3d2f38(0x1a2)+_0x409b52+_0x3d2f38(0x189)+_0x3c57e9+_0x3d2f38(0x1f7),_0x5346f9=getTagForSource(_0x3d2f38(0x24e)),_0x1a4f0d='<'+_0x5346f9+'>\x0a'+_0x5290d1+'\x0a'+_0x31e92f+'\x0a'+_0x5346f9+'>';_0x4da1b2['push']({'text':_0x1a4f0d,'metadata':{'source':_0x3d2f38(0x24e),'sourceName':sourceName,'part':_0x3c57e9,'timestamp':_0x229e24[_0x3d2f38(0x181)]()}}),_0x3c57e9++,_0x21d43f+=_0x3c8a41-_0x493794;if(_0x21d43f>=_0x449811[_0x3d2f38(0x233)])break;}return _0x4da1b2;}import{getCollectionId as _0x45ee52,getCharacterName}from'./utils/context-utils.js';async function getCollectionId(){return lockedCollectionId||await _0x45ee52();}async function toggleSessionLock(){return lockedCollectionId?(lockedCollectionId=null,![]):(lockedCollectionId=await _0x45ee52(),!![]);}function isSessionLocked(){return lockedCollectionId!==null;}function getLockedSessionInfo(){const _0x24370c=_0x10918d;if(!lockedCollectionId)return null;return{'id':lockedCollectionId,'name':'(已锁定:\x20'+lockedCollectionId[_0x24370c(0x23b)](0x0,0x8)+_0x24370c(0x241)};}function getLocalKnowledgeBases(){const _0xa45410=_0x10918d,_0x190a6c=getCharacterStableId();return!settings['knowledgeBases'][_0x190a6c]&&(settings[_0xa45410(0x266)][_0x190a6c]={}),settings[_0xa45410(0x266)][_0x190a6c];}function getGlobalKnowledgeBases(){const _0x22d869=_0x10918d;return!settings['knowledgeBases'][GLOBAL_SCOPE_ID]&&(settings['knowledgeBases'][GLOBAL_SCOPE_ID]={}),settings[_0x22d869(0x266)][GLOBAL_SCOPE_ID];}function getKnowledgeBases(){const _0x283957=getLocalKnowledgeBases(),_0x55cf01=getGlobalKnowledgeBases();return{..._0x55cf01,..._0x283957};}function addKnowledgeBase(_0x357895){const _0x46d5f9=_0x10918d;if(!_0x357895||!_0x357895['trim']())throw new Error(_0x46d5f9(0x1c3));const _0x3a6f7b=getCharacterStableId(),_0x86fbc8=getLocalKnowledgeBases(),_0xcdb209=_0x46d5f9(0x190)+Date[_0x46d5f9(0x246)]()+'_'+Math[_0x46d5f9(0x1fd)]()['toString'](0x24)[_0x46d5f9(0x23b)](0x2,0x9),_0xae5e78={'id':_0xcdb209,'name':_0x357895[_0x46d5f9(0x1de)](),'enabled':!![],'createdAt':new Date()[_0x46d5f9(0x181)](),'owner':_0x3a6f7b};return _0x86fbc8[_0xcdb209]=_0xae5e78,saveSettings(),console[_0x46d5f9(0x21a)]('[翰林院-核心]\x20已为角色\x20'+_0x3a6f7b+'\x20添加新知识库:\x20'+_0x357895+_0x46d5f9(0x184)+_0xcdb209+')'),_0xae5e78;}async function removeKnowledgeBase(_0x2ff6ae,_0x4c7a8c){const _0x1be834=_0x10918d,_0x31f90c=getCharacterStableId(),_0x1e99df=_0x4c7a8c===_0x1be834(0x1e6)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x5e933f=_0x1e99df[_0x2ff6ae],_0x5b7143=_0x5e933f?.[_0x1be834(0x235)]||_0x2ff6ae;if(!_0x5e933f){console[_0x1be834(0x242)](_0x1be834(0x1fc)+_0x2ff6ae+_0x1be834(0x226)+_0x4c7a8c+')');return;}const _0x552f86=_0x4c7a8c==='global'?_0x5e933f[_0x1be834(0x1f5)]||GLOBAL_SCOPE_ID:_0x31f90c,_0x3b63d5=_0x552f86+'_'+_0x2ff6ae;console[_0x1be834(0x21a)]('[翰林院-核心]\x20准备删除知识库\x20'+_0x2ff6ae+_0x1be834(0x1f6)+_0x3b63d5);const _0x57172a=await purgeStorage(_0x3b63d5);_0x57172a?(delete _0x1e99df[_0x2ff6ae],saveSettings(),console['log'](_0x1be834(0x177)+_0x2ff6ae+'\x20及其向量数据。'),toastr['success'](_0x1be834(0x1b2)+_0x5b7143+_0x1be834(0x1d0))):(console[_0x1be834(0x26c)](_0x1be834(0x237)+_0x3b63d5+'\x20失败,删除操作中止。'),toastr[_0x1be834(0x26c)](_0x1be834(0x187)));}function toggleKnowledgeBase(_0x4e54c9,_0x9f6398){const _0xc8f430=_0x10918d,_0x2d5c5a=_0x9f6398===_0xc8f430(0x1e6)?getGlobalKnowledgeBases():getLocalKnowledgeBases();_0x2d5c5a[_0x4e54c9]&&(_0x2d5c5a[_0x4e54c9][_0xc8f430(0x210)]=!_0x2d5c5a[_0x4e54c9][_0xc8f430(0x210)],saveSettings(),console[_0xc8f430(0x21a)]('[翰林院-核心]\x20知识库\x20'+_0x4e54c9+'\x20(范围:\x20'+_0x9f6398+_0xc8f430(0x1c1)+(_0x2d5c5a[_0x4e54c9]['enabled']?'启用':'禁用')));}function generateHash(_0x1a12a5){const _0xbc01a4=_0x10918d;let _0x402a06=0x0;for(let _0x59031a=0x0;_0x59031a<_0x1a12a5[_0xbc01a4(0x233)];_0x59031a++){const _0xbb2c2e=_0x1a12a5['charCodeAt'](_0x59031a);_0x402a06=(_0x402a06<<0x5)-_0x402a06+_0xbb2c2e,_0x402a06=_0x402a06&_0x402a06;}return Math[_0xbc01a4(0x1a3)](_0x402a06)[_0xbc01a4(0x259)](0x24);}async function queryVectors(_0x56c65a){const _0x1349c6=_0x10918d;console['log'](_0x1349c6(0x193));const _0x10f9e4=getCharacterStableId(),_0x3b875b=getLocalKnowledgeBases(),_0x87f8e0=getGlobalKnowledgeBases(),_0x30262d=Object['values'](_0x3b875b)['filter'](_0x15fcf2=>_0x15fcf2[_0x1349c6(0x210)]),_0x4344b3=Object[_0x1349c6(0x188)](_0x87f8e0)['filter'](_0x4a87f4=>_0x4a87f4[_0x1349c6(0x210)]),_0x362df3=[..._0x30262d[_0x1349c6(0x201)](_0x3e54eb=>({..._0x3e54eb,'scope':_0x1349c6(0x1db)})),..._0x4344b3[_0x1349c6(0x201)](_0xc2c758=>({..._0xc2c758,'scope':_0x1349c6(0x1e6)}))];if(_0x362df3['length']===0x0){console[_0x1349c6(0x21a)](_0x1349c6(0x17b));const _0x2c00ca=await _0x45ee52();if(!_0x2c00ca)return[];_0x362df3['push']({'id':null,'name':_0x1349c6(0x250),'scope':_0x1349c6(0x22a)});}const _0x9c84c2=(await getEmbeddings([_0x56c65a]))[0x0];let _0x6af1f4=[];const _0x281832=_0x362df3[_0x1349c6(0x201)](_0x99bb9a=>{const _0x169cc3=_0x1349c6;let _0x20e0b0;if(_0x99bb9a['scope']===_0x169cc3(0x22a))_0x20e0b0=_0x45ee52();else{const _0x5529ac=_0x99bb9a[_0x169cc3(0x186)]===_0x169cc3(0x1e6)?_0x99bb9a[_0x169cc3(0x1f5)]||GLOBAL_SCOPE_ID:_0x10f9e4;_0x20e0b0=Promise[_0x169cc3(0x205)](_0x5529ac+'_'+_0x99bb9a['id']);}return _0x20e0b0[_0x169cc3(0x25a)](_0x3d7913=>{const _0x40743f=_0x169cc3;if(!_0x3d7913)return[];console[_0x40743f(0x21a)](_0x40743f(0x1d7)+_0x99bb9a['name']+_0x40743f(0x184)+_0x3d7913+')');const _0x9bf3a6={'collectionId':_0x3d7913,'searchText':_0x56c65a,'topK':settings['advanced'][_0x40743f(0x1ff)],'threshold':settings[_0x40743f(0x1cc)][_0x40743f(0x1fa)],'source':_0x40743f(0x216),'embeddings':{[_0x56c65a]:_0x9c84c2}};return fetch('/api/vector/query',{'method':_0x40743f(0x19f),'headers':context[_0x40743f(0x1c8)](),'body':JSON[_0x40743f(0x253)](_0x9bf3a6)})['then'](async _0x1b39d8=>{const _0x1e83fb=_0x40743f;if(!_0x1b39d8['ok']){const _0x1192ae=await _0x1b39d8[_0x1e83fb(0x1c0)]();return console['error']('[翰林院-日志]\x20查询知识库\x20'+_0x3d7913+_0x1e83fb(0x249),_0x1192ae),[];}const _0xc433f1=await _0x1b39d8['json']();let _0x28066f=[];if(Array[_0x1e83fb(0x182)](_0xc433f1))_0x28066f=_0xc433f1;else{if(_0xc433f1&&_0xc433f1[_0x1e83fb(0x1d2)]&&Array[_0x1e83fb(0x182)](_0xc433f1[_0x1e83fb(0x1d2)]))_0x28066f=_0xc433f1[_0x1e83fb(0x1d2)];else{if(_0xc433f1&&_0xc433f1[_0x1e83fb(0x1ce)]&&Array[_0x1e83fb(0x182)](_0xc433f1[_0x1e83fb(0x1ce)]))_0x28066f=_0xc433f1['results'];else _0xc433f1&&_0xc433f1[_0x1e83fb(0x265)]&&Array[_0x1e83fb(0x182)](_0xc433f1[_0x1e83fb(0x265)])&&(_0x28066f=_0xc433f1[_0x1e83fb(0x265)]);}}const _0x161727=_0x28066f[_0x1e83fb(0x201)](_0x12e44a=>{const _0x32be1e=_0x1e83fb;if(!_0x12e44a||typeof _0x12e44a[_0x32be1e(0x1c0)]!==_0x32be1e(0x1e1))return null;const _0x1be21f={'source':_0x32be1e(0x20d),'sourceName':'未知'},_0x26d732=_0x12e44a[_0x32be1e(0x1c0)][_0x32be1e(0x245)](/\[来源:\s*([^,\]]+)/);if(_0x26d732&&_0x26d732[0x1]){const _0x50ba96=_0x26d732[0x1][_0x32be1e(0x1de)]();switch(_0x50ba96){case _0x32be1e(0x1d3):_0x1be21f['source']=_0x32be1e(0x26e);const _0x160eea=_0x12e44a[_0x32be1e(0x1c0)]['match'](/楼层:\s*#(\d+)/);_0x160eea&&_0x160eea[0x1]&&(_0x1be21f[_0x32be1e(0x219)]=parseInt(_0x160eea[0x1],0xa),_0x1be21f['sourceName']=_0x32be1e(0x1e0)+_0x1be21f['floor']);break;case _0x32be1e(0x229):_0x1be21f[_0x32be1e(0x244)]='lorebook';const _0x5e1b99=_0x12e44a[_0x32be1e(0x1c0)][_0x32be1e(0x245)](/条目:\s*([^,\]]+)/);_0x5e1b99&&_0x5e1b99[0x1]&&(_0x1be21f['sourceName']=_0x5e1b99[0x1][_0x32be1e(0x1de)]());break;case _0x32be1e(0x238):_0x1be21f[_0x32be1e(0x244)]=_0x32be1e(0x24e);break;case'小说':case _0x32be1e(0x223):_0x1be21f['source']=_0x32be1e(0x185);const _0x2dc101=_0x12e44a[_0x32be1e(0x1c0)][_0x32be1e(0x245)](/来源:\s*([^,\]]+),\s*([^,\]]+),\s*([^,\]]+)/);_0x2dc101&&(_0x1be21f[_0x32be1e(0x17a)]=_0x2dc101[0x1]['trim'](),_0x1be21f[_0x32be1e(0x1cb)]=_0x2dc101[0x2][_0x32be1e(0x1de)](),_0x1be21f[_0x32be1e(0x1f3)]=_0x2dc101[0x3][_0x32be1e(0x1de)]());break;}}return{..._0x12e44a,'score':_0x12e44a['score']||0x1,'metadata':_0x1be21f};})['filter'](Boolean);return console[_0x1e83fb(0x21a)](_0x1e83fb(0x232)+_0x99bb9a[_0x1e83fb(0x235)]+_0x1e83fb(0x208)+_0x161727['length']+_0x1e83fb(0x17d)),_0x161727;})[_0x40743f(0x16d)](_0x30d3c3=>{const _0x24ee2e=_0x40743f;return console[_0x24ee2e(0x26c)](_0x24ee2e(0x23a)+_0x3d7913+_0x24ee2e(0x18e),_0x30d3c3),[];});});}),_0x1763c2=await Promise[_0x1349c6(0x1f0)](_0x281832);_0x6af1f4=_0x1763c2[_0x1349c6(0x1ca)](),console['log']('[翰林院-日志]\x20所有知识库查询完毕,共获得\x20'+_0x6af1f4['length']+_0x1349c6(0x1ed));const _0x3b27a1=[],_0x43ae93=new Set();for(const _0x53d4dc of _0x6af1f4){if(_0x53d4dc&&typeof _0x53d4dc===_0x1349c6(0x16e)&&_0x53d4dc[_0x1349c6(0x1c0)]&&typeof _0x53d4dc[_0x1349c6(0x1c0)]==='string'){const _0x588e56=_0x53d4dc[_0x1349c6(0x1c0)][_0x1349c6(0x1de)]();_0x588e56[_0x1349c6(0x233)]>0x0&&!_0x43ae93[_0x1349c6(0x19e)](_0x588e56)&&(_0x43ae93[_0x1349c6(0x239)](_0x588e56),_0x3b27a1['push'](_0x53d4dc));}}console[_0x1349c6(0x21a)](_0x1349c6(0x269)+_0x3b27a1[_0x1349c6(0x233)]+'\x20条结果。'),_0x3b27a1['sort']((_0x150f4c,_0x2bcc42)=>(_0x2bcc42[_0x1349c6(0x25b)]||0x0)-(_0x150f4c[_0x1349c6(0x25b)]||0x0));const _0x25ddb1=[..._0x3b27a1];return console[_0x1349c6(0x21a)]('[翰林院-修复]\x20最终返回数组长度:\x20'+_0x25ddb1[_0x1349c6(0x233)]),console[_0x1349c6(0x21a)](_0x1349c6(0x1e4),JSON[_0x1349c6(0x253)](_0x25ddb1[_0x1349c6(0x19c)](0x0,0x1),null,0x2)),_0x25ddb1;}async function insertVectors(_0x42958a,_0xe58c7b=null,_0x5966a2){const _0x26e9c1=_0x10918d;if(!_0x5966a2)throw new Error(_0x26e9c1(0x204));if(_0x42958a[_0x26e9c1(0x233)]===0x0)return{'success':!![],'count':0x0};const _0x23875b=_0x42958a[_0x26e9c1(0x201)]((_0x1bc51d,_0x19a93d)=>({'hash':generateHash(_0x1bc51d['text']+Date[_0x26e9c1(0x246)]()+_0x19a93d),'text':_0x1bc51d['text'],'metadata':_0x1bc51d[_0x26e9c1(0x1d2)]||{'source':_0x26e9c1(0x20d),'timestamp':new Date()[_0x26e9c1(0x181)]()}})),_0x5d1602=_0x23875b['reduce']((_0x3c29cd,_0x21e7fd,_0x2a8abe)=>{const _0x1889e3=_0x26e9c1;return _0x3c29cd[_0x21e7fd[_0x1889e3(0x1c0)]]=_0x42958a[_0x2a8abe]['vector'],_0x3c29cd;},{}),_0x1ec2a={'collectionId':_0x5966a2,'items':_0x23875b,'source':'webllm','embeddings':_0x5d1602},_0x3e80e3=await fetch(_0x26e9c1(0x230),{'method':_0x26e9c1(0x19f),'headers':context[_0x26e9c1(0x1c8)](),'body':JSON[_0x26e9c1(0x253)](_0x1ec2a),'signal':_0xe58c7b});if(!_0x3e80e3['ok']){const _0x472bd2=await _0x3e80e3[_0x26e9c1(0x1c0)]();console[_0x26e9c1(0x26c)](_0x26e9c1(0x195),_0x472bd2);throw new Error('忆识存入API错误\x20'+_0x3e80e3[_0x26e9c1(0x257)]+':\x20'+_0x472bd2);}return{'success':!![],'count':_0x23875b[_0x26e9c1(0x233)]};}async function getVectorCount(_0x4b31ab=null,_0x493d1e=_0x10918d(0x1db)){const _0x4b3f03=_0x10918d,_0x496907=getCharacterStableId();if(_0x4b31ab){const _0x4706cd=_0x493d1e===_0x4b3f03(0x1e6)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x377ffc=_0x4706cd[_0x4b31ab];if(!_0x377ffc)return console['warn'](_0x4b3f03(0x19b)+_0x493d1e+_0x4b3f03(0x18d)+_0x4b31ab+'\x20的知识库。'),0x0;const _0x206df6=_0x493d1e===_0x4b3f03(0x1e6)?_0x377ffc[_0x4b3f03(0x1f5)]||GLOBAL_SCOPE_ID:_0x496907,_0x88943e=_0x206df6+'_'+_0x4b31ab;return await countVectorsInCollection(_0x88943e);}else{console[_0x4b3f03(0x21a)]('[翰林院-日志]\x20开始获取所有知识库的向量总数...');const _0x548145=Object[_0x4b3f03(0x188)](getLocalKnowledgeBases()),_0x5f2b61=Object[_0x4b3f03(0x188)](getGlobalKnowledgeBases()),_0x363215=[];_0x548145[_0x4b3f03(0x26f)](_0x520ecb=>{const _0x57a731=_0x4b3f03,_0x586880=_0x496907+'_'+_0x520ecb['id'];_0x363215[_0x57a731(0x211)](countVectorsInCollection(_0x586880));}),_0x5f2b61[_0x4b3f03(0x26f)](_0xcc48ed=>{const _0x56cf0d=_0x4b3f03,_0x17b553=_0xcc48ed[_0x56cf0d(0x1f5)]||GLOBAL_SCOPE_ID,_0x3d3b68=_0x17b553+'_'+_0xcc48ed['id'];_0x363215[_0x56cf0d(0x211)](countVectorsInCollection(_0x3d3b68));});const _0x6395fc=await _0x45ee52();_0x363215[_0x4b3f03(0x211)](countVectorsInCollection(_0x6395fc));const _0x17bca4=await Promise['all'](_0x363215),_0x51aace=_0x17bca4[_0x4b3f03(0x24a)]((_0x1882bd,_0xbc1f0b)=>_0x1882bd+_0xbc1f0b,0x0);return console['log'](_0x4b3f03(0x1bc)+_0x51aace),_0x51aace;}}function _0x4bee(){const _0x50919b=['\x27\x20的注入设置,跳过处理。','\x27\x20中未找到ID为\x20','\x20时发生网络错误:','[翰林院-核心]\x20准备为任务\x20\x22','task_','comment','queryMessageCount','[翰林院-日志]\x20开始多知识库向量查询...','2716CUCPYN','[翰林院-日志]\x20忆识存入API错误:','entryName','未知小说','[翰林院-日志]\x20集合\x20','relevance_score','[翰林院-日志]\x20清空宝库API错误:','[翰林院-计数]\x20在作用域\x20\x27','slice','无法确定要清空的目标宝库。','has','POST','正在处理\x20','[翰林院-核心]\x20已将\x20',',\x20向量化录入时间:\x20','abs','移动失败:没有当前角色,无法移入局部知识库。','未知条目','[翰林院-迁移]\x20旧宝库已清空。','84902jBpIuP','notify','tiaomu','[翰林院-调试]\x20步骤3\x20-\x20按来源分组后的结果:','No\x20messages\x20to\x20process.','zh-CN','send_date','[来源:\x20世界书,\x20条目:\x20','/api/vector/purge','replace','查询集合\x20','知识库\x20\x22','[来源:\x20','_history','retrieval','[翰林院-核心]\x20将来源\x27','[翰林院-核心]\x20已锁定忆识宝库ID:\x20','[翰林院-配置]\x20','\x20条消息分解为\x20','\x20-\x20楼层\x20#','rerank_score','[翰林院-日志]\x20所有知识库统计完成,总向量数:\x20','未知角色','\x20条内容。','getContext','text',')\x20的状态已切换为:\x20','[翰林院-Rerank]\x20元数据加权排序完成。','知识库名称不能为空','[翰林院-核心]\x20聊天记录凝识失败:\x20','rerank','saveSettingsDebounced','\x22\x20创建专属知识库...','getRequestHeaders','[翰林院-日志]\x20获取集合\x20','flat','volume','advanced','sousuo','results','mes','\x22\x20已删除。','[翰林院-核心]\x20成功插入\x20','metadata','聊天记录','hasOwnProperty','batchSize','\x20失败:\x20','[翰林院-日志]\x20正在查询知识库:\x20','2253660vHRbOH','[翰林院-Rerank]\x20开始外部API重排序...','[翰林院-Rerank]\x20开始元数据加权最终排序...','local','keys','[翰林院-日志]\x20开始清空宝库...','trim','30xbpgfn','聊天记录\x20#','string','warning','[翰林院-迁移]\x20用户取消了迁移操作。','[翰林院-修复]\x20最终返回数组样本:','凝识之权未开启','global','success','oldId','[翰林院-迁移]\x20集合\x20','key','[翰林院-核心]\x20processCondensation\x20失败:','messageTypes','\x20条初步结果。','info','235855rMWXVT','all','[翰林院-核心]\x20已创建并锁定知识库:\x20','AbortError','chapter','extensionSettings','owner',',将清空集合:\x20','部分]','$1','depth','matchThreshold','[翰林院-核心]\x20检测到同名知识库\x20\x22','[翰林院-核心]\x20尝试删除一个不存在的知识库:\x20','random','[翰林院-日志]\x20清空宝库API调用成功。','maxResults','findIndex','map','test','start','insertVectors\x20必须接收一个有效的\x20collectionId\x20参数。','resolve','find','正在智能分块...','\x20返回\x20','index','saveProgress','\x20个块。','lorebook','unknown','end','手动录入:\x20','enabled','push','聊天记录:\x20','hanlinyuanRagProcessor','toLocaleString','忆识检索失败:\x20','webllm','_text}}','bookName','floor','log','position','content','\x20的知识库。','condensation','3512GQSShH','\x27,使用通用分块逻辑。','小说:\x20','is_user','小说录入','embeddings','1999395VdGKCm','\x20(范围:\x20','\x20不存在,返回空数组。','clearJob','世界书','legacy','第1章','message','aborted','injection_','36DSOBTK','/api/vector/insert','文本块和向量数量不匹配','[翰林院-V13\x20修复]\x20重建元数据后,知识库\x20','length','[翰林院-Rerank]\x20外部Rerank失败,将仅使用内部加权。','name','输入文本为空','[翰林院-核心]\x20清空向量集合\x20','手动录入','add','[翰林院-日志]\x20查询知识库\x20','substring','[翰林院-日志]\x20清空目标集合ID:\x20','Rerank失败:\x20','chat','\x20(集合ID:\x20','json','...)','warn','[翰林院-核心]\x20凝识任务已锁定知识库:\x20','source','match','now','HANLINYUAN_RAG_CHAT','depth_role','\x20失败:','reduce','HANLINYUAN_RAG_NOVEL','min','第1卷','manual','\x20不存在,计为\x200。','旧版宝库\x20(Legacy)','[翰林院-日志]\x20统计集合\x20','[翰林院]\x20未找到来源\x20\x27','stringify','核心未初始化','移动失败:未找到源条目。','join','status','操作已取消。','toString','then','score','7eJLBht','condensationHistory','\x27\x20注入\x20','[翰林院-核心]\x20文本录入失败:\x20','\x20补充所有者ID:\x20','\x20个向量条目。','1472996lBrdMi','toLowerCase','_global','data','knowledgeBases',',\x20第1卷,\x20第1章,\x20第','11sGxjdD','[翰林院-日志]\x20去重后剩余\x20','检测到旧版数据。此操作将把旧数据迁移到新格式,过程不可逆,是否继续?','top_n','error','user','chat_history','forEach','hanlinyuan-rag-core','catch','object','split','翰林院忆识核心已启动\x20(V5.2-集成版),已注册到全局\x20hanlinyuanRagProcessor\x20对象。',']\x20的消息已成功凝识。','rearrangeChat','165JwoigE','[翰林院-核心]\x20文本录入任务被用户中止。','\x0a','hybrid_alpha','[翰林院-核心]\x20成功删除知识库\x20','filter','/api/vector/list','sourceName','[翰林院-日志]\x20没有启用的新知识库,尝试查询旧版单体宝库...','[翰林院-日志]\x20统计目标集合ID:\x20','\x20条结果。','includes','[翰林院-调试]\x20步骤2\x20-\x20rerankResults返回的最终结果:','[翰林院-日志]\x20无法确定要清空的目标集合ID。','toISOString','isArray','40yPneoc','\x20(ID:\x20','novel','scope','删除知识库失败,未能清空后端数据。','values',',\x20第','132275KUxdfO','外部Rerank完成'];_0x4bee=function(){return _0x50919b;};return _0x4bee();}async function countVectorsInCollection(_0x4adb1d){const _0x262bba=_0x10918d;if(!_0x4adb1d)return 0x0;console[_0x262bba(0x21a)](_0x262bba(0x17c)+_0x4adb1d);const _0x221059={'collectionId':_0x4adb1d,'source':'webllm','embeddings':{}};try{const _0x52ac3d=await fetch(_0x262bba(0x179),{'method':'POST','headers':context[_0x262bba(0x1c8)](),'body':JSON[_0x262bba(0x253)](_0x221059)});if(!_0x52ac3d['ok']){if(_0x52ac3d[_0x262bba(0x257)]===0x194)console[_0x262bba(0x21a)](_0x262bba(0x198)+_0x4adb1d+_0x262bba(0x24f));else{const _0x167600=await _0x52ac3d[_0x262bba(0x1c0)]();console[_0x262bba(0x242)](_0x262bba(0x1c9)+_0x4adb1d+'\x20列表API时出现问题\x20(状态:\x20'+_0x52ac3d[_0x262bba(0x257)]+'):',_0x167600);}return 0x0;}const _0x3cece6=await _0x52ac3d[_0x262bba(0x240)]();let _0x421cd9=0x0;if(Array[_0x262bba(0x182)](_0x3cece6))_0x421cd9=_0x3cece6['length'];else _0x3cece6&&_0x3cece6['hashes']&&(_0x421cd9=_0x3cece6['hashes'][_0x262bba(0x233)]);return _0x421cd9;}catch(_0x2e42ba){return console[_0x262bba(0x26c)](_0x262bba(0x251)+_0x4adb1d+_0x262bba(0x18e),_0x2e42ba),0x0;}}async function purgeStorage(_0x57b3bc=null){const _0x250ed1=_0x10918d;console[_0x250ed1(0x21a)](_0x250ed1(0x1dd));const _0x16dec4=_0x57b3bc||await getCollectionId();if(!_0x16dec4)return console[_0x250ed1(0x26c)](_0x250ed1(0x180)),toastr[_0x250ed1(0x26c)](_0x250ed1(0x19d)),![];console[_0x250ed1(0x21a)](_0x250ed1(0x23c)+_0x16dec4);const _0x3f32d8={'collectionId':_0x16dec4};console[_0x250ed1(0x21a)]('[翰林院-日志]\x20发送到\x20/api/vector/purge\x20的请求体:',JSON['stringify'](_0x3f32d8,null,0x2));const _0x3ecccd=await fetch(_0x250ed1(0x1af),{'method':_0x250ed1(0x19f),'headers':context['getRequestHeaders'](),'body':JSON[_0x250ed1(0x253)](_0x3f32d8)});console[_0x250ed1(0x21a)]('[翰林院-日志]\x20/api/vector/purge\x20响应状态:\x20'+_0x3ecccd[_0x250ed1(0x257)]);if(!_0x3ecccd['ok']){const _0x5b77da=await _0x3ecccd[_0x250ed1(0x1c0)]();console[_0x250ed1(0x26c)](_0x250ed1(0x19a),_0x5b77da);}else console[_0x250ed1(0x21a)](_0x250ed1(0x1fe));return _0x3ecccd['ok'];}function getMessagesForCondensation(_0x38dfd1=null){const _0x4850d4=_0x10918d;if(!settings[_0x4850d4(0x21e)]['enabled'])return showNotification(_0x4850d4(0x1e5),_0x4850d4(0x1e2)),[];const {layerStart:_0x5250fb,layerEnd:_0x17eb2e}=settings[_0x4850d4(0x21e)],_0x2b0f4e=_0x38dfd1||settings[_0x4850d4(0x21e)][_0x4850d4(0x1ec)],_0x3d687a=context[_0x4850d4(0x23e)]['length'],_0x2a47a4=Math['max'](0x0,_0x5250fb-0x1),_0x1afda2=_0x17eb2e===0x0||_0x17eb2e>_0x3d687a?_0x3d687a:Math[_0x4850d4(0x24c)](_0x3d687a,_0x17eb2e),_0x182cd0=context[_0x4850d4(0x23e)][_0x4850d4(0x19c)](_0x2a47a4,_0x1afda2);return _0x182cd0[_0x4850d4(0x178)](_0x1b1f75=>{const _0x469b61=_0x4850d4,_0x5be475=_0x1b1f75[_0x469b61(0x222)]===!![],_0x139a80=_0x1b1f75[_0x469b61(0x222)]===![];if(!_0x1b1f75['mes']||!_0x1b1f75[_0x469b61(0x1cf)][_0x469b61(0x1de)]())return![];return _0x2b0f4e[_0x469b61(0x26d)]&&_0x5be475||_0x2b0f4e['ai']&&_0x139a80;});}async function processCondensation(_0x4c9d8e,_0x2c0e61=()=>{},_0x59b0ef=null){const _0x306fb2=_0x10918d;if(!_0x4c9d8e||_0x4c9d8e[_0x306fb2(0x233)]===0x0)return{'success':![],'error':_0x306fb2(0x1ab)};try{let _0x2920f8,_0x3039ee;const _0x3da4c2=getCharacterName()||_0x306fb2(0x1bd);if(_0x59b0ef){const _0x247352=_0x59b0ef[_0x306fb2(0x203)]??'?',_0x4d33dc=_0x59b0ef[_0x306fb2(0x20e)]===0x0?'末':_0x59b0ef[_0x306fb2(0x20e)]??'?';_0x2920f8=_0x3da4c2+':\x20'+_0x247352+'楼-'+_0x4d33dc+'楼';}else{const _0xf9efcb=new Date()[_0x306fb2(0x214)]('zh-CN',{'hour12':![]});_0x2920f8=_0x306fb2(0x212)+_0xf9efcb;}const _0xe9722a=Object['values'](getLocalKnowledgeBases()),_0x184ec8=_0xe9722a[_0x306fb2(0x206)](_0x3be35a=>_0x3be35a['name']===_0x2920f8);if(_0x184ec8)_0x3039ee=_0x184ec8['id'],_0x2c0e61(_0x306fb2(0x1fb)+_0x2920f8+'\x22,将数据合并入库。','info');else{_0x2c0e61(_0x306fb2(0x18f)+_0x2920f8+_0x306fb2(0x1c7),_0x306fb2(0x1ee));const _0x4be9fb=addKnowledgeBase(_0x2920f8);_0x3039ee=_0x4be9fb['id'];}const _0x48ea24=getCharacterStableId(),_0x397ca9=_0x48ea24+'_'+_0x3039ee;_0x2c0e61(_0x306fb2(0x243)+_0x2920f8+_0x306fb2(0x23f)+_0x397ca9+')',_0x306fb2(0x1e7));const _0x2a925a=[],_0x2f4d3c=context['chat'];for(const _0xee077f of _0x4c9d8e){const _0x5c925f=(_0xee077f[_0x306fb2(0x1cf)]||'')[_0x306fb2(0x1b0)](/<[^>]*>/g,'')['trim']();if(_0x5c925f['length']===0x0)continue;let _0x41c004;if(_0xee077f[_0x306fb2(0x219)]!==undefined&&_0xee077f[_0x306fb2(0x219)]!==null)_0x41c004=_0xee077f[_0x306fb2(0x219)];else{const _0x5aca0a=_0x2f4d3c[_0x306fb2(0x200)](_0x1ce17c=>_0x1ce17c===_0xee077f);_0x41c004=_0x5aca0a!==-0x1?_0x5aca0a+0x1:-0x1;}const _0x19f421=new Date(_0xee077f[_0x306fb2(0x1ad)]),_0xcd2914=isNaN(_0x19f421['getTime']())?new Date()['toISOString']():_0x19f421['toISOString'](),_0x15b638=splitIntoChunks(_0x5c925f,_0x306fb2(0x26e),{'floor':_0x41c004,'is_user':_0xee077f[_0x306fb2(0x222)],'timestamp':_0xcd2914});_0x2a925a[_0x306fb2(0x211)](..._0x15b638);}if(_0x2a925a[_0x306fb2(0x233)]===0x0)return{'success':!![],'count':0x0};_0x2c0e61(_0x306fb2(0x1a1)+_0x4c9d8e['length']+_0x306fb2(0x1b9)+_0x2a925a[_0x306fb2(0x233)]+'\x20个知识块,准备入库。',_0x306fb2(0x1ee));const _0x3ab550=settings[_0x306fb2(0x1b5)]['batchSize']||0x5;let _0x21518b=0x0;for(let _0x1f426b=0x0;_0x1f426b<_0x2a925a[_0x306fb2(0x233)];_0x1f426b+=_0x3ab550){const _0xf9e323=_0x2a925a[_0x306fb2(0x19c)](_0x1f426b,_0x1f426b+_0x3ab550),_0x13d241=_0xf9e323[_0x306fb2(0x201)](_0x443195=>_0x443195['text']),_0x5713b8=await getEmbeddings(_0x13d241);if(_0xf9e323[_0x306fb2(0x233)]!==_0x5713b8[_0x306fb2(0x233)])throw new Error(_0x306fb2(0x231));const _0x5656bc=_0xf9e323[_0x306fb2(0x201)]((_0x1e3bf2,_0xfb075a)=>({..._0x1e3bf2,'vector':_0x5713b8[_0xfb075a]}));await insertVectors(_0x5656bc,null,_0x397ca9),_0x21518b+=_0xf9e323[_0x306fb2(0x233)];}if(_0x59b0ef){const _0xd75587=_0x59b0ef[_0x306fb2(0x20e)]===0x0?context[_0x306fb2(0x23e)][_0x306fb2(0x233)]:_0x59b0ef['end'],_0x566d7e=getCharacterStableId();!settings[_0x306fb2(0x25d)][_0x566d7e]&&(settings[_0x306fb2(0x25d)][_0x566d7e]={}),settings['condensationHistory'][_0x566d7e][_0x397ca9]={'start':_0x59b0ef[_0x306fb2(0x203)],'end':_0xd75587,'timestamp':new Date()[_0x306fb2(0x181)]()},saveSettings(),_0x2c0e61('[翰林院-核心]\x20已为宝库\x20'+_0x397ca9+'\x20记录凝识范围:\x20'+_0x59b0ef[_0x306fb2(0x203)]+'-'+_0xd75587,_0x306fb2(0x1ee));}_0x2c0e61('[翰林院-核心]\x20聊天记录凝识完成,成功插入\x20'+_0x21518b+'\x20个条目。',_0x306fb2(0x1e7));const _0x51e74d=_0x4c9d8e['map'](_0x2402b4=>{const _0xf13b5=_0x306fb2,_0x21182e=_0x2f4d3c['findIndex'](_0x42efbd=>_0x42efbd===_0x2402b4),_0x43aa85=_0x21182e!==-0x1?_0x21182e+0x1:-0x1,_0x1671af=_0x2402b4[_0xf13b5(0x222)]?'用户':getCharacterName()||'AI';return'['+_0x1671af+_0xf13b5(0x1ba)+_0x43aa85+_0xf13b5(0x171);});return{'success':!![],'count':_0x21518b,'messages':_0x51e74d};}catch(_0x3ce9fd){return console['error'](_0x306fb2(0x1eb),_0x3ce9fd),_0x2c0e61(_0x306fb2(0x1c4)+_0x3ce9fd[_0x306fb2(0x22c)],_0x306fb2(0x26c)),{'success':![],'error':_0x3ce9fd[_0x306fb2(0x22c)]};}}async function rerankResults(_0x83bf0f,_0x27ec88,_0x176055){const _0x4b65c1=_0x10918d;let _0x15b179=_0x83bf0f;if(_0x176055[_0x4b65c1(0x1c5)][_0x4b65c1(0x210)]&&_0x83bf0f[_0x4b65c1(0x233)]>0x0){console[_0x4b65c1(0x21a)](_0x4b65c1(0x1d9));try{const _0x33be50=_0x83bf0f['map'](_0x30d23a=>_0x30d23a[_0x4b65c1(0x1c0)]),_0x163370=await executeRerank(_0x27ec88,_0x33be50,_0x176055[_0x4b65c1(0x1c5)]),_0x52d03f=_0x83bf0f[_0x4b65c1(0x201)]((_0x20d7b7,_0x5a0d71)=>({..._0x20d7b7,'original_index':_0x5a0d71}));_0x15b179=_0x52d03f[_0x4b65c1(0x201)](_0x11c1ba=>{const _0x493630=_0x4b65c1,_0x27172f=_0x163370['results'][_0x493630(0x206)](_0x37d738=>_0x37d738[_0x493630(0x209)]===_0x11c1ba['original_index']),_0x2c54f5=_0x27172f?_0x27172f[_0x493630(0x199)]:0x0;return{..._0x11c1ba,'rerank_score':_0x2c54f5};});if(_0x176055['rerank'][_0x4b65c1(0x1a8)])showNotification(_0x4b65c1(0x18b),_0x4b65c1(0x1e7));}catch(_0x427f0a){console['error'](_0x4b65c1(0x234),_0x427f0a);if(_0x176055[_0x4b65c1(0x1c5)][_0x4b65c1(0x1a8)])showNotification(_0x4b65c1(0x23d)+_0x427f0a[_0x4b65c1(0x22c)],'error');_0x15b179[_0x4b65c1(0x26f)](_0x3d73f7=>_0x3d73f7['rerank_score']=0x0);}}else _0x15b179[_0x4b65c1(0x26f)](_0x6d93e3=>_0x6d93e3[_0x4b65c1(0x1bb)]=0x0);console[_0x4b65c1(0x21a)](_0x4b65c1(0x1da));const _0x142660=context['chat'][_0x4b65c1(0x233)],_0x1ab6ce=_0x176055['rerank'][_0x4b65c1(0x176)],_0x30bd4d=_0x15b179[_0x4b65c1(0x201)](_0xf2cf22=>{const _0x39debc=_0x4b65c1;let _0x41f7c9=0x1;const _0x4e0c12=_0xf2cf22['metadata']||{};switch(_0x4e0c12[_0x39debc(0x244)]){case _0x39debc(0x20c):_0x41f7c9*=1.2;break;case _0x39debc(0x24e):_0x41f7c9*=1.1;break;case _0x39debc(0x26e):if(_0x4e0c12['floor']&&_0x142660>0x0){const _0x460a56=_0x4e0c12[_0x39debc(0x219)]/_0x142660;_0x41f7c9*=0x1+_0x460a56;}break;}const _0x3070aa=_0xf2cf22[_0x39debc(0x1bb)]*_0x1ab6ce+(_0xf2cf22[_0x39debc(0x25b)]||0x0)*(0x1-_0x1ab6ce),_0x4f8119=_0x3070aa*_0x41f7c9;return{'text':_0xf2cf22[_0x39debc(0x1c0)],'score':_0xf2cf22['score'],'rerank_score':_0xf2cf22[_0x39debc(0x1bb)],'final_score':_0x4f8119,'metadata':_0xf2cf22[_0x39debc(0x1d2)]};});return _0x30bd4d['sort']((_0x171a6d,_0x34377a)=>(_0x34377a['final_score']||0x0)-(_0x171a6d['final_score']||0x0)),console[_0x4b65c1(0x21a)](_0x4b65c1(0x1c2)),_0x30bd4d[_0x4b65c1(0x19c)](0x0,_0x176055[_0x4b65c1(0x1c5)][_0x4b65c1(0x26b)]);}async function rearrangeChat(_0x36c75e,_0x19d860,_0x57f228,_0x2169fd){const _0x3df6ad=_0x10918d,_0x6ba8e={'novel':_0x3df6ad(0x24b),'chat_history':_0x3df6ad(0x247),'lorebook':'HANLINYUAN_RAG_LOREBOOK','manual':'HANLINYUAN_RAG_MANUAL'};Object[_0x3df6ad(0x188)](_0x6ba8e)[_0x3df6ad(0x26f)](_0x6f28f=>{setExtensionPrompt(_0x6f28f,'',0x0,0x0,![],0x0);});if(_0x2169fd==='quiet'||!settings[_0x3df6ad(0x1b5)][_0x3df6ad(0x210)])return;const _0x318877=_0x36c75e[_0x3df6ad(0x19c)](-settings[_0x3df6ad(0x1cc)][_0x3df6ad(0x192)]);if(_0x318877[_0x3df6ad(0x233)]===0x0)return;const _0x73f904=_0x318877['map'](_0x1c33be=>_0x1c33be[_0x3df6ad(0x1cf)])['join']('\x20')[_0x3df6ad(0x1b0)](/<[^>]*>/g,'')[_0x3df6ad(0x1de)]();if(!_0x73f904)return;try{const _0x1a2ed1=await queryVectors(_0x73f904);console[_0x3df6ad(0x21a)]('[翰林院-调试]\x20步骤1\x20-\x20queryVectors返回的原始结果:',JSON[_0x3df6ad(0x253)](_0x1a2ed1[_0x3df6ad(0x201)](_0x493c3f=>_0x493c3f[_0x3df6ad(0x1d2)]),null,0x2));if(_0x1a2ed1['length']===0x0)return;const _0x1a1c2d=await rerankResults(_0x1a2ed1,_0x73f904,settings);if(_0x1a1c2d['length']===0x0)return;console['log'](_0x3df6ad(0x17f),JSON['stringify'](_0x1a1c2d[_0x3df6ad(0x201)](_0x36e30a=>_0x36e30a[_0x3df6ad(0x1d2)]),null,0x2));const _0x29fa47={'novel':[],'chat_history':[],'lorebook':[],'manual':[]};_0x1a1c2d[_0x3df6ad(0x26f)](_0x2bcd4d=>{const _0x537570=_0x3df6ad,_0x1f5590=_0x2bcd4d[_0x537570(0x1d2)]?.[_0x537570(0x244)];_0x1f5590&&_0x29fa47[_0x537570(0x1d4)](_0x1f5590)&&_0x29fa47[_0x1f5590][_0x537570(0x211)](_0x2bcd4d);}),console[_0x3df6ad(0x21a)](_0x3df6ad(0x1aa),JSON[_0x3df6ad(0x253)](Object[_0x3df6ad(0x1dc)](_0x29fa47)[_0x3df6ad(0x24a)]((_0xb33eb2,_0x65c848)=>{const _0x446449=_0x3df6ad;return _0xb33eb2[_0x65c848]=_0x29fa47[_0x65c848][_0x446449(0x233)],_0xb33eb2;},{}),null,0x2));for(const _0x10c9de in _0x29fa47){const _0x592acc=_0x29fa47[_0x10c9de];if(_0x592acc[_0x3df6ad(0x233)]===0x0)continue;const _0x1dfdd9=settings[_0x3df6ad(0x22e)+_0x10c9de[_0x3df6ad(0x1b0)](_0x3df6ad(0x1b4),'')];if(!_0x1dfdd9){console['warn'](_0x3df6ad(0x252)+_0x10c9de+_0x3df6ad(0x18c));continue;}const _0x385ce7=_0x592acc[_0x3df6ad(0x201)](_0x46d936=>_0x46d936['text'])['join']('\x0a\x0a'),_0x38fc43='{{'+_0x10c9de[_0x3df6ad(0x1b0)](_0x3df6ad(0x1b4),'')+_0x3df6ad(0x217);let _0x9999d5=_0x1dfdd9['template']['replace'](_0x38fc43,_0x385ce7);_0x9999d5[_0x3df6ad(0x1de)]()&&(_0x9999d5='%%'+_0x6ba8e[_0x10c9de]+'%%'+_0x9999d5),setExtensionPrompt(_0x6ba8e[_0x10c9de],_0x9999d5,_0x1dfdd9[_0x3df6ad(0x21b)],_0x1dfdd9[_0x3df6ad(0x1f9)],![],_0x1dfdd9[_0x3df6ad(0x248)]),console[_0x3df6ad(0x21a)]('[翰林院]\x20已为来源\x20\x27'+_0x10c9de+_0x3df6ad(0x25e)+_0x592acc[_0x3df6ad(0x233)]+_0x3df6ad(0x1be));}}catch(_0xb1ab57){console[_0x3df6ad(0x26c)]('[翰林院]\x20检索或注入时发生错误:',_0xb1ab57);if(settings[_0x3df6ad(0x1b5)]['notify'])showNotification(_0x3df6ad(0x215)+_0xb1ab57[_0x3df6ad(0x22c)],_0x3df6ad(0x26c));}}async function moveKnowledgeBase(_0x354500,_0x1a4c3f){const _0x1a1df0=_0x10918d,_0x550654=_0x1a4c3f===_0x1a1df0(0x1e6)?_0x1a1df0(0x1db):'global',_0x4e0890=getCharacterStableId();if(!_0x4e0890&&_0x550654===_0x1a1df0(0x1db)){toastr[_0x1a1df0(0x26c)](_0x1a1df0(0x1a4));return;}const _0xfe9ec2=_0x1a4c3f==='global'?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x4924c2=_0x550654==='global'?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x341231=_0xfe9ec2[_0x354500];if(!_0x341231){const _0x5ae023='在源作用域\x20\x27'+_0x1a4c3f+_0x1a1df0(0x18d)+_0x354500+_0x1a1df0(0x21d);console['error'](_0x1a1df0(0x1b8)+_0x5ae023),toastr[_0x1a1df0(0x26c)](_0x1a1df0(0x255));return;}_0x1a4c3f==='local'&&_0x550654===_0x1a1df0(0x1e6)&&!_0x341231[_0x1a1df0(0x1f5)]&&(console[_0x1a1df0(0x21a)]('[翰林院-配置]\x20为旧版知识库\x20'+_0x354500+_0x1a1df0(0x260)+_0x4e0890),_0x341231[_0x1a1df0(0x1f5)]=_0x4e0890);delete _0xfe9ec2[_0x354500],_0x4924c2[_0x354500]=_0x341231,saveSettings();const _0x5ab98a='知识库【'+_0x341231[_0x1a1df0(0x235)]+'】已成功移动到'+(_0x550654===_0x1a1df0(0x1e6)?'全局':'局部')+'。';console['log'](_0x1a1df0(0x1b8)+_0x5ab98a);}async function getAllVectorsFromCollection(_0xd2529e){const _0x2c7bdf=_0x10918d,_0x42807a='*',_0x5963a5={'collectionId':_0xd2529e,'searchText':_0x42807a,'topK':0x2710,'threshold':0x0,'source':_0x2c7bdf(0x216),'embeddings':{}},_0x5329d8=(await getEmbeddings([_0x42807a]))[0x0];_0x5963a5[_0x2c7bdf(0x224)]={[_0x42807a]:_0x5329d8};const _0x42bcd7=await fetch('/api/vector/query',{'method':_0x2c7bdf(0x19f),'headers':context[_0x2c7bdf(0x1c8)](),'body':JSON['stringify'](_0x5963a5)});if(!_0x42bcd7['ok']){if(_0x42bcd7[_0x2c7bdf(0x257)]===0x194)return console['log'](_0x2c7bdf(0x1e9)+_0xd2529e+_0x2c7bdf(0x227)),[];const _0x217984=await _0x42bcd7[_0x2c7bdf(0x1c0)]();throw new Error(_0x2c7bdf(0x1b1)+_0xd2529e+_0x2c7bdf(0x1d6)+_0x217984);}const _0x15cc7a=await _0x42bcd7['json']();return _0x15cc7a[_0x2c7bdf(0x1d2)]||_0x15cc7a[_0x2c7bdf(0x1ce)]||_0x15cc7a[_0x2c7bdf(0x265)]||[];}