From a198b8606daf1db85a92c8b9f2eb8ce85772deda Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Tue, 4 Nov 2025 23:38:44 +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 426b26d..e98a495 100644 --- a/core/rag-processor.js +++ b/core/rag-processor.js @@ -1 +1 @@ -'use strict';const _0x58d31a=_0x53b6;function _0x1622(){const _0x44770a=['settingsVersion','[翰林院]\x20常规组返回\x20','unknown','part','substring','翰林院通告','\x22\x20已删除。','success','/api/vector/list',']\x20更正为\x20[','9770fBLQzy','toISOString','owner','queryMessageCount','在源作用域\x20\x27','rerank_score','stringify','status','[翰林院-日志]\x20所有知识库查询完毕,共获得\x20','\x20记录凝识范围:\x20','oldId','initialized','[翰林院-户口普查]\x20知识库\x20\x22','trim','key','[来源:\x20','includes','小说:','max','翰林院忆识核心已启动\x20(V5.2-集成版),已注册到全局\x20hanlinyuanRagProcessor\x20对象。','warning','[翰林院-核心]\x20凝识任务已锁定知识库:\x20','小说录入','floor','\x20条结果。','is_user','[翰林院-日志]\x20发送到\x20/api/vector/purge\x20的请求体:','未分类世界书',',将清空集合:\x20','message','296oKIudR','聊天记录','[翰林院-核心]\x20准备删除知识库\x20','test','HANLINYUAN_RAG_LOREBOOK','聊天记录\x20#','[翰林院-修复]\x20最终返回数组长度:\x20','[翰林院-核心]\x20已将\x20','用户取消了迁移操作','end','has','外部Rerank完成','toString','map','检测到旧版数据,正在进行一次性户口普查...','\x20个块。','\x27\x20中未找到ID为\x20','error','[翰林院-日志]\x20清空宝库API调用成功。','\x20的知识库。',',\x20第1卷,\x20第1章,\x20第','score','\x20列表API时出现问题\x20(状态:\x20','maxResults','[翰林院-日志]\x20统计集合\x20','POST','data','知识库名称不能为空','knowledgeBases','179090OcfiBh','[翰林院-计数]\x20在作用域\x20\x27','vectors_rearrangeChat','injection_','\x22,将数据合并入库。','chapter','所有启用库','keys','[翰林院-日志]\x20集合\x20','aborted','forEach','Rerank失败:\x20','42WlHeXY','start','json','scope','HANLINYUAN_RAG_CHAT','getRequestHeaders','手动录入:\x20','部分]','[翰林院]\x20最终无可用结果,注入中止。','hasOwnProperty','第1章','/api/vector/insert','[翰林院]\x20已从\x20','now','\x5c$&','[翰林院-日志]\x20清空目标集合ID:\x20',',\x20向量化录入时间:\x20','reranked','min','range','[翰林院-日志]\x20开始获取所有知识库的向量总数...','[翰林院-日志]\x20无法确定要清空的目标集合ID。','5951CTTLpp','\x20(集合ID:\x20','mes','comment','charCodeAt','\x22\x20创建专属知识库...','\x20条消息分解为\x20','\x0a$1','[翰林院]\x20创建优先查询组:\x20','移动失败:没有当前角色,无法移入局部知识库。','世界书','\x20个向量条目。','个库)','metadata','global','toLowerCase','(已锁定:\x20','微言录总结','enabled','小说:\x20','push','世界书条目','advanced','正在智能分块...','vector','\x20及其向量数据。','find','lorebook','log','379748NPvGyV','task_','flat','[翰林院-日志]\x20查询知识库\x20','replace','match','abs','27405tTGBRP','matchThreshold','extensionSettings','random','[翰林院-日志]\x20清空宝库API错误:','\x20(范围:\x20','AbortError','zh-CN','manual','统一检索部分的Rerank已完成','删除知识库失败,未能清空后端数据。','[翰林院-迁移]\x20用户取消了迁移操作。','旧版宝库\x20(Legacy)','[翰林院-核心]\x20聊天记录凝识失败:\x20','isArray','未知角色','[翰林院-配置]\x20为旧版知识库\x20','\x20个特定知识库。','\x22\x20已从\x20[','514728YaAESa','操作已取消。','condensation','results','/api/vector/query','[翰林院-核心]\x20ingestTextToHanlinyuan\x20失败:','sjshu','add','\x20池精确提取\x20','\x27\x20注入\x20','values','insertVectors\x20必须接收一个有效的\x20collectionId\x20参数。','[翰林院-Rerank]\x20外部Rerank失败,将仅使用内部加权。',',\x20第','legacy','[翰林院-核心]\x20准备为任务\x20\x22','priorityRetrieval','join','[翰林院-迁移]\x20集合\x20','凝识之权未开启','[翰林院-分块]\x20未知的来源类型\x20\x27','\x20时发生网络错误:','notify','length','text','移动失败:未找到源条目。','final_score','[翰林院]\x20最终准备注入\x20','[翰林院-日志]\x20查询白名单已提供,将查询\x20','】已成功移动到','[翰林院-修复]\x20最终返回数组样本:','\x20失败:\x20','无法确定要清空的目标宝库。','user','rearrangeChat','[翰林院-日志]\x20忆识存入API错误:','[翰林院-日志]\x20开始向量查询...\x20(目标:\x20','hashes',')\x20的状态已切换为:\x20','findIndex'];_0x1622=function(){return _0x44770a;};return _0x1622();}(function(_0x596dc9,_0x1b5a25){const _0x14a3a1=_0x53b6,_0x313834=_0x596dc9();while(!![]){try{const _0x42322b=parseInt(_0x14a3a1(0x1ef))/0x1*(parseInt(_0x14a3a1(0x19a))/0x2)+parseInt(_0x14a3a1(0x206))/0x3+-parseInt(_0x14a3a1(0x233))/0x4+parseInt(_0x14a3a1(0x23a))/0x5*(parseInt(_0x14a3a1(0x1a6))/0x6)+parseInt(_0x14a3a1(0x1d5))/0x7*(parseInt(_0x14a3a1(0x17d))/0x8)+parseInt(_0x14a3a1(0x24d))/0x9+-parseInt(_0x14a3a1(0x27f))/0xa*(parseInt(_0x14a3a1(0x1bc))/0xb);if(_0x42322b===_0x1b5a25)break;else _0x313834['push'](_0x313834['shift']());}catch(_0x3c946f){_0x313834['push'](_0x313834['shift']());}}}(_0x1622,0x50f29));import{extension_prompt_roles,setExtensionPrompt}from'/script.js';import*as _0x4b95b8 from'./utils/context-utils.js';import{getCollectionIdInfo,getCharacterId,getCharacterStableId}from'./utils/context-utils.js';import{defaultSettings as _0x2e18e9}from'./rag-settings.js';import*as _0x373cd3 from'./ingestion-manager.js';import{getEmbeddings,fetchEmbeddingModels as _0x1849a7,fetchRerankModels as _0x3bc1c3,executeRerank,testApiConnection as _0x30722b}from'./rag-api.js';import{superSort}from'./super-sorter.js';const MODULE_NAME=_0x58d31a(0x216),OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME=_0x58d31a(0x19c),GLOBAL_SCOPE_ID='_global';let context=null,settings=null,lockedCollectionId=null;function filterWorldbooks(_0x539dec,_0x3a0bf1){const _0x59ffde=_0x58d31a;if(!_0x539dec||!_0x539dec[_0x59ffde(0x28c)]())return _0x3a0bf1;const _0x27dfd2=_0x539dec[_0x59ffde(0x225)]()[_0x59ffde(0x28c)]();return _0x3a0bf1['filter'](_0x39d823=>{const _0x4ecdc6=_0x59ffde;return _0x39d823[_0x4ecdc6(0x225)]()[_0x4ecdc6(0x28f)](_0x27dfd2)||containsPinyinMatch(_0x39d823,_0x27dfd2);});}function filterWorldbookEntries(_0x450631,_0x5ed999){const _0x2cd35c=_0x58d31a;if(!_0x450631||!_0x450631['trim']())return _0x5ed999;const _0x24b2dc=_0x450631[_0x2cd35c(0x225)]()[_0x2cd35c(0x28c)]();return _0x5ed999[_0x2cd35c(0x1cf)](_0x4ee205=>{const _0x5189ac=_0x2cd35c,_0x32842a=[_0x4ee205[_0x5189ac(0x1bf)]||'',_0x4ee205[_0x5189ac(0x28d)]||'',_0x4ee205['content']||''][_0x5189ac(0x25e)]('\x20')['toLowerCase']();return _0x32842a['includes'](_0x24b2dc)||containsPinyinMatch(_0x4ee205[_0x5189ac(0x1bf)]||'',_0x24b2dc);});}function containsPinyinMatch(_0x4c2bc4,_0x452a22){const _0x40548c=_0x58d31a,_0x40da67={'世界书':_0x40548c(0x253),'条目':_0x40548c(0x1f1),'编纂':_0x40548c(0x21a),'搜索':'sousuo'},_0x2c4c09=_0x40da67[_0x4c2bc4];return _0x2c4c09&&_0x2c4c09[_0x40548c(0x28f)](_0x452a22);}function highlightSearchMatch(_0x515c83,_0x266bdd){const _0x4a64b1=_0x58d31a;if(!_0x266bdd||!_0x266bdd['trim']())return _0x515c83;const _0x2a17fd=new RegExp('('+_0x266bdd[_0x4a64b1(0x237)](/[.*+?^${}()|[\]\\]/g,_0x4a64b1(0x1b4))+')','gi');return _0x515c83[_0x4a64b1(0x237)](_0x2a17fd,_0x4a64b1(0x21d));}function debounce(_0x5aa464,_0x5d6b00){let _0x5cbd9b;return function _0x51a303(..._0x45ab36){const _0x2196d3=()=>{clearTimeout(_0x5cbd9b),_0x5aa464(..._0x45ab36);};clearTimeout(_0x5cbd9b),_0x5cbd9b=setTimeout(_0x2196d3,_0x5d6b00);};}export{initialize,getSettings,saveSettings,resetSettings,_0x30722b as testApiConnection,_0x1849a7 as fetchEmbeddingModels,_0x3bc1c3 as fetchRerankModels,getVectorCount,purgeStorage,getMessagesForCondensation,processCondensation,ingestTextToHanlinyuan,getCollectionId,toggleSessionLock,isSessionLocked,getLockedSessionInfo,addKnowledgeBase,removeKnowledgeBase,getLocalKnowledgeBases,getGlobalKnowledgeBases,toggleKnowledgeBase,moveKnowledgeBase,filterWorldbooks,filterWorldbookEntries,highlightSearchMatch,debounce};function initialize(){const _0x41579c=_0x58d31a;context=SillyTavern['getContext']();if(!context){console[_0x41579c(0x18e)](_0x41579c(0x204));return;}settings=getSettings(),!window[_0x41579c(0x1c8)]&&(window[_0x41579c(0x1c8)]={}),window[_0x41579c(0x1c8)][_0x41579c(0x26f)]=rearrangeChat,window[_0x41579c(0x1c8)][_0x41579c(0x28a)]=!![],console['log'](_0x41579c(0x292));}async function ingestTextToHanlinyuan(_0x1d76c7,_0x382fcc=_0x58d31a(0x242),_0x23eb41={},_0x466453=()=>{},_0x32b9f4=null,_0xdee15b=()=>{},_0x56dd99=()=>{},_0x32cf6e=null,_0x2173be=0x0){const _0x4a4703=_0x58d31a;if(!_0x1d76c7||!_0x1d76c7[_0x4a4703(0x28c)]())return{'success':![],'error':_0x4a4703(0x1cc)};if(!settings)return{'success':![],'error':'核心未初始化'};try{const _0x37504d=getCollectionIdInfo(),_0x545a65=await _0x23dff3();if(_0x37504d['oldId']&&_0x37504d['oldId']===_0x545a65&&_0x37504d[_0x4a4703(0x289)]!==_0x37504d[_0x4a4703(0x1d4)]){const _0x57f18e=confirm(_0x4a4703(0x1e1));if(_0x57f18e)_0xdee15b('[翰林院-迁移]\x20用户确认迁移,正在处理旧宝库:\x20'+_0x37504d[_0x4a4703(0x289)],_0x4a4703(0x205)),await purgeStorage(_0x37504d['oldId']),_0xdee15b('[翰林院-迁移]\x20旧宝库已清空。',_0x4a4703(0x27c));else return _0xdee15b(_0x4a4703(0x245),_0x4a4703(0x1c4)),toastr['info'](_0x4a4703(0x24e)),{'success':![],'error':_0x4a4703(0x185)};}let _0xbf02df,_0x2ff584;const _0x61d7f9=new Date()['toLocaleString'](_0x4a4703(0x241),{'hour12':![]}),_0x1d5b37=getCharacterName()||_0x4a4703(0x249);switch(_0x382fcc){case'chat_history':const _0x466861=_0x23eb41[_0x4a4703(0x1b9)]||{},_0x15eead=_0x466861[_0x4a4703(0x1a7)]??'?',_0x1a5600=_0x466861[_0x4a4703(0x186)]===0x0?'末':_0x466861['end']??'?';_0xbf02df=_0x1d5b37+':\x20'+_0x15eead+'楼-'+_0x1a5600+'楼';break;case _0x4a4703(0x231):const _0x4cf7b6=_0x23eb41['bookName']||_0x4a4703(0x29a);if(_0x23eb41['entryName']&&_0x23eb41[_0x4a4703(0x1f2)][_0x4a4703(0x28f)](_0x4a4703(0x227)))_0x23eb41[_0x4a4703(0x1f2)]=_0x4a4703(0x1e2);else _0x23eb41[_0x4a4703(0x1f2)]&&_0x23eb41[_0x4a4703(0x1f2)][_0x4a4703(0x28f)]('宏史卷总结')&&(_0x23eb41['entryName']='对话记录大总结');const _0x5942c2=_0x23eb41[_0x4a4703(0x1f2)]||'未知条目';_0xbf02df=_0x4cf7b6+':\x20'+_0x5942c2;break;case'novel':_0xbf02df=_0x4a4703(0x229)+(_0x23eb41[_0x4a4703(0x1d0)]||'未知小说');break;case _0x4a4703(0x242):default:_0xbf02df=_0x4a4703(0x1ac)+_0x61d7f9;break;}const _0x131eb1=Object[_0x4a4703(0x257)](getKnowledgeBases()),_0x5b281a=_0x131eb1[_0x4a4703(0x230)](_0x2f6a9e=>_0x2f6a9e[_0x4a4703(0x1f4)]===_0xbf02df);if(_0x5b281a)_0x2ff584=_0x5b281a['id'],_0xdee15b('[翰林院-核心]\x20检测到同名知识库\x20\x22'+_0xbf02df+_0x4a4703(0x19e),'info');else{_0xdee15b('[翰林院-核心]\x20准备为任务\x20\x22'+_0xbf02df+_0x4a4703(0x1c1),'info');const _0x8934a7=addKnowledgeBase(_0xbf02df,_0x382fcc);_0x2ff584=_0x8934a7['id'];}const _0x1956ad=getCharacterStableId(),_0x3dda90=_0x1956ad+'_'+_0x2ff584;_0xdee15b('[翰林院-核心]\x20已创建并锁定知识库:\x20'+_0xbf02df+_0x4a4703(0x1bd)+_0x3dda90+')',_0x4a4703(0x27c)),_0xdee15b(_0x4a4703(0x1f5)+_0x3dda90,_0x4a4703(0x1c4)),_0x466453({'message':_0x4a4703(0x22d),'processed':0x0,'total':0x1});const _0x13af12=splitIntoChunks(_0x1d76c7,_0x382fcc,_0x23eb41),_0x3fe8c3=_0x13af12[_0x4a4703(0x264)];if(_0x32b9f4?.[_0x4a4703(0x1a3)])throw new Error('AbortError');_0xdee15b('[翰林院-核心]\x20将来源\x27'+_0xbf02df+_0x4a4703(0x1e4)+_0x3fe8c3+_0x4a4703(0x18c),_0x4a4703(0x1c4));if(_0x3fe8c3===0x0)return{'success':!![],'count':0x0};const _0x572f63=settings[_0x4a4703(0x219)][_0x4a4703(0x1e9)]||0x5;let _0x1be833=_0x2173be;for(let _0x254274=_0x2173be;_0x254274<_0x3fe8c3;_0x254274+=_0x572f63){if(_0x32b9f4?.[_0x4a4703(0x1a3)])throw new Error('AbortError');const _0x309ea1=_0x13af12[_0x4a4703(0x20c)](_0x254274,_0x254274+_0x572f63);_0x466453({'message':_0x4a4703(0x1e3)+(_0x254274+0x1)+'-'+(_0x254274+_0x309ea1[_0x4a4703(0x264)])+'\x20块','processed':_0x254274,'total':_0x3fe8c3});const _0x4bbcbb=_0x309ea1[_0x4a4703(0x18a)](_0x16dc9f=>_0x16dc9f[_0x4a4703(0x265)]),_0x130372=await getEmbeddings(_0x4bbcbb,_0x32b9f4);if(_0x32b9f4?.['aborted'])throw new Error(_0x4a4703(0x240));if(_0x309ea1[_0x4a4703(0x264)]!==_0x130372[_0x4a4703(0x264)])throw new Error('文本块和向量数量不匹配');const _0x5ee4f5=_0x309ea1[_0x4a4703(0x18a)]((_0x5e88ce,_0xaaa16)=>({..._0x5e88ce,'vector':_0x130372[_0xaaa16]}));await insertVectors(_0x5ee4f5,_0x32b9f4,_0x3dda90),_0x1be833+=_0x309ea1[_0x4a4703(0x264)],_0x32cf6e&&_0x373cd3['saveProgress'](_0x32cf6e,_0x1be833,_0x3fe8c3),await _0x56dd99();}return _0x32cf6e&&_0x373cd3[_0x4a4703(0x20b)](_0x32cf6e),_0xdee15b(_0x4a4703(0x1d3)+_0x1be833+_0x4a4703(0x221),_0x4a4703(0x27c)),{'success':!![],'count':_0x1be833};}catch(_0x1f0223){if(_0x1f0223[_0x4a4703(0x1f4)]===_0x4a4703(0x240)){_0xdee15b(_0x4a4703(0x1da),_0x4a4703(0x205));throw _0x1f0223;}return console[_0x4a4703(0x18e)](_0x4a4703(0x252),_0x1f0223),_0xdee15b(_0x4a4703(0x209)+_0x1f0223[_0x4a4703(0x17c)],'error'),{'success':![],'error':_0x1f0223[_0x4a4703(0x17c)]};}}function getSettings(){const _0x1fd69f=_0x58d31a;if(!context||!context[_0x1fd69f(0x23c)])return structuredClone(_0x2e18e9);let _0x2dadba=context['extensionSettings'][MODULE_NAME];!_0x2dadba&&(_0x2dadba={},context[_0x1fd69f(0x23c)][MODULE_NAME]=_0x2dadba);_0x2dadba[_0x1fd69f(0x20a)]===undefined&&(_0x2dadba[_0x1fd69f(0x20a)]={});_0x2dadba[_0x1fd69f(0x199)]===undefined&&(_0x2dadba['knowledgeBases']={});for(const _0x16fc98 in _0x2e18e9){if(_0x2dadba[_0x16fc98]===undefined)_0x2dadba[_0x16fc98]=structuredClone(_0x2e18e9[_0x16fc98]);else{if(typeof _0x2e18e9[_0x16fc98]==='object'&&!Array['isArray'](_0x2e18e9[_0x16fc98])&&_0x2e18e9[_0x16fc98]!==null)for(const _0x209e6b in _0x2e18e9[_0x16fc98]){_0x2dadba[_0x16fc98][_0x209e6b]===undefined&&(_0x2dadba[_0x16fc98][_0x209e6b]=_0x2e18e9[_0x16fc98][_0x209e6b]);}}}return _0x2dadba;}function saveSettings(){const _0x555599=_0x58d31a;if(context)context[_0x555599(0x1eb)]();}function resetSettings(){context&&(context['extensionSettings'][MODULE_NAME]=structuredClone(_0x2e18e9),saveSettings());}function showNotification(_0x2cb3cd,_0x38f328=_0x58d31a(0x1c4)){toastr[_0x38f328](_0x2cb3cd);}function getTagForSource(_0xfef1de){const _0x4084eb=_0x58d31a;switch(_0xfef1de){case _0x4084eb(0x1dd):return _0x4084eb(0x17e);case'lorebook':return _0x4084eb(0x220);case _0x4084eb(0x242):return'手动录入';case _0x4084eb(0x1d9):return _0x4084eb(0x295);default:return'资料';}}function splitIntoChunks(_0x2d938c,_0x200900,_0x351e70={}){const _0xc05d27=_0x58d31a;switch(_0x200900){case _0xc05d27(0x1d9):return _chunkForNovel(_0x2d938c,_0x351e70);case'chat_history':return _chunkForChatHistory(_0x2d938c,_0x351e70);case'lorebook':return _chunkForLorebook(_0x2d938c,_0x351e70);case'manual':return _chunkForManual(_0x2d938c,_0x351e70);default:console[_0xc05d27(0x205)](_0xc05d27(0x261)+_0x200900+'\x27,使用通用分块逻辑。');return _chunkForManual(_0x2d938c,{..._0x351e70,'sourceName':_0x351e70[_0xc05d27(0x1d0)]||'未知来源'});}}function _chunkForNovel(_0x325958,_0xce1e7b){const _0x2c8441=_0x58d31a,{chunkSize:_0x13f95e,overlap:_0x14e5f0}=settings[_0x2c8441(0x22c)],{sourceName:sourceName='小说'}=_0xce1e7b,_0x4e86ac=[];if(!_0x325958||_0x13f95e<=0x0)return _0x4e86ac;const _0x52b9ce=/(第\s*[一二三四五六七八九十百千万零\d]+\s*卷)/gim,_0x3250c6=/(第\s*[一二三四五六七八九十百千万零\d]+\s*[章回节部])|^(Chapter\s+\d+)/gim;let _0x1e061f=0x0;const _0xa9849d=_0x325958['split']('\x0a');let _0x56b681='第1卷',_0x241726='第1章',_0x50ed63=[];function _0x238a47(){const _0x4d89ff=_0x2c8441;if(_0x50ed63[_0x4d89ff(0x264)]===0x0)return;const _0x35b7f4=_0x50ed63['join']('\x0a');let _0x387535=0x0,_0x1b9f8a=0x1;while(_0x387535<_0x35b7f4[_0x4d89ff(0x264)]){const _0x14aa58=Math[_0x4d89ff(0x1b8)](_0x387535+_0x13f95e,_0x35b7f4[_0x4d89ff(0x264)]),_0xa0409e=_0x35b7f4[_0x4d89ff(0x279)](_0x387535,_0x14aa58);if(_0xa0409e[_0x4d89ff(0x28c)]()[_0x4d89ff(0x264)]>0x0){const _0x260cc4={'source':_0x4d89ff(0x1d9),'sourceName':sourceName,'timestamp':new Date()[_0x4d89ff(0x280)](),'globalIndex':_0x1e061f++,'volume':_0x56b681,'chapter':_0x241726,'section':_0x1b9f8a},_0x53fc9a=getTagForSource('novel'),_0x32e214=_0x4d89ff(0x28e)+sourceName+',\x20'+_0x56b681+',\x20'+_0x241726+',\x20第'+_0x1b9f8a+'节]',_0x3a56c2='<'+_0x53fc9a+'>\x0a'+_0x32e214+'\x0a'+_0xa0409e+_0x4d89ff(0x1c3)+_0x53fc9a+'>';_0x4e86ac[_0x4d89ff(0x22a)]({'text':_0x3a56c2,'metadata':_0x260cc4}),_0x1b9f8a++;}_0x387535+=_0x13f95e-_0x14e5f0;if(_0x387535>=_0x35b7f4[_0x4d89ff(0x264)])break;}_0x50ed63=[];}for(const _0x171b95 of _0xa9849d){const _0x4e6fc0=_0x171b95[_0x2c8441(0x28c)]();if(_0x52b9ce[_0x2c8441(0x180)](_0x4e6fc0))_0x238a47(),_0x56b681=_0x4e6fc0,_0x241726='第1章';else _0x3250c6[_0x2c8441(0x180)](_0x4e6fc0)?(_0x238a47(),_0x241726=_0x4e6fc0):_0x50ed63[_0x2c8441(0x22a)](_0x171b95);}_0x238a47();if(_0x4e86ac[_0x2c8441(0x264)]===0x0&&_0x325958[_0x2c8441(0x264)]>0x0){let _0x175af8=0x0,_0x45b5b7=0x1;while(_0x175af8<_0x325958[_0x2c8441(0x264)]){const _0x3722c5=Math[_0x2c8441(0x1b8)](_0x175af8+_0x13f95e,_0x325958[_0x2c8441(0x264)]),_0x427030=_0x325958[_0x2c8441(0x279)](_0x175af8,_0x3722c5),_0x348198={'source':_0x2c8441(0x1d9),'sourceName':sourceName,'timestamp':new Date()['toISOString'](),'globalIndex':_0x4e86ac[_0x2c8441(0x264)],'volume':'第1卷','chapter':_0x2c8441(0x1b0),'section':_0x45b5b7},_0x4a6e44=getTagForSource('novel'),_0x30c90f=_0x2c8441(0x28e)+sourceName+_0x2c8441(0x191)+_0x45b5b7+'节]',_0x5c75f1='<'+_0x4a6e44+'>\x0a'+_0x30c90f+'\x0a'+_0x427030+'\x0a';_0x4e86ac[_0x2c8441(0x22a)]({'text':_0x5c75f1,'metadata':_0x348198}),_0x45b5b7++,_0x175af8+=_0x13f95e-_0x14e5f0;}}return _0x4e86ac;}function _chunkForChatHistory(_0x406a5a,_0x1ae9c4){const _0x5eb32a=_0x58d31a,{chunkSize:_0x4de07c,overlap:_0x5db0f3}=settings['advanced'],{floor:_0x326a0c,is_user:_0x4f1d7d,timestamp:_0x5b402b}=_0x1ae9c4,_0x310555=[];if(!_0x406a5a||_0x4de07c<=0x0)return _0x310555;let _0x7174cc=0x1,_0x250368=0x0;while(_0x250368<_0x406a5a[_0x5eb32a(0x264)]){const _0x5e42f3=Math['min'](_0x250368+_0x4de07c,_0x406a5a[_0x5eb32a(0x264)]),_0x3aaeb5=_0x406a5a[_0x5eb32a(0x279)](_0x250368,_0x5e42f3),_0xd4b1b8=_0x5eb32a(0x1ce)+_0x326a0c+_0x5eb32a(0x25a)+_0x7174cc+_0x5eb32a(0x1ad),_0x33434e=getTagForSource(_0x5eb32a(0x1dd)),_0x9bdbbc='<'+_0x33434e+'>\x0a'+_0xd4b1b8+'\x0a'+_0x3aaeb5+'\x0a';_0x310555[_0x5eb32a(0x22a)]({'text':_0x9bdbbc,'metadata':{'source':'chat_history','sourceName':_0x5eb32a(0x182)+_0x326a0c,'floor':_0x326a0c,'part':_0x7174cc,'is_user':_0x4f1d7d,'timestamp':_0x5b402b}}),_0x7174cc++,_0x250368+=_0x4de07c-_0x5db0f3;if(_0x250368>=_0x406a5a[_0x5eb32a(0x264)])break;}return _0x310555;}function _chunkForLorebook(_0xa8717a,_0xc4601){const _0x154a55=_0x58d31a,{chunkSize:_0x1cbeb8,overlap:_0x13228a}=settings['advanced'],{bookName:bookName=_0x154a55(0x220),entryName:entryName=_0x154a55(0x22b)}=_0xc4601,_0x16c118=[];if(!_0xa8717a||_0x1cbeb8<=0x0)return _0x16c118;let _0x1092cc=0x1,_0x533672=0x0;while(_0x533672<_0xa8717a[_0x154a55(0x264)]){const _0xfbe3dc=Math[_0x154a55(0x1b8)](_0x533672+_0x1cbeb8,_0xa8717a[_0x154a55(0x264)]),_0x347ad2=_0xa8717a[_0x154a55(0x279)](_0x533672,_0xfbe3dc),_0x3d4f24=_0x154a55(0x28e)+bookName+_0x154a55(0x213)+entryName+',\x20第'+_0x1092cc+_0x154a55(0x1ad),_0xb252d6=getTagForSource(_0x154a55(0x231)),_0x43ee5d='<'+_0xb252d6+'>\x0a'+_0x3d4f24+'\x0a'+_0x347ad2+_0x154a55(0x1c3)+_0xb252d6+'>';_0x16c118[_0x154a55(0x22a)]({'text':_0x43ee5d,'metadata':{'source':_0x154a55(0x231),'sourceName':bookName+':\x20'+entryName,'bookName':bookName,'entryName':entryName,'part':_0x1092cc,'timestamp':new Date()['toISOString']()}}),_0x1092cc++,_0x533672+=_0x1cbeb8-_0x13228a;if(_0x533672>=_0xa8717a[_0x154a55(0x264)])break;}return _0x16c118;}function _chunkForManual(_0x3485b0,_0x38a717){const _0x5dc93e=_0x58d31a,{chunkSize:_0x20b9f1,overlap:_0x5d44dd}=settings[_0x5dc93e(0x22c)],{sourceName:sourceName=_0x5dc93e(0x210)}=_0x38a717,_0x31c8c5=[];if(!_0x3485b0||_0x20b9f1<=0x0)return _0x31c8c5;const _0x5061b7=new Date(),_0x7a759c=_0x5061b7[_0x5dc93e(0x1ee)](_0x5dc93e(0x241));let _0x3aa5d0=0x1,_0x5f567f=0x0;while(_0x5f567f<_0x3485b0[_0x5dc93e(0x264)]){const _0x4e57c7=Math['min'](_0x5f567f+_0x20b9f1,_0x3485b0[_0x5dc93e(0x264)]),_0x5b96c9=_0x3485b0['substring'](_0x5f567f,_0x4e57c7),_0x1708fe='[来源:\x20'+sourceName+_0x5dc93e(0x1b6)+_0x7a759c+_0x5dc93e(0x25a)+_0x3aa5d0+_0x5dc93e(0x1ad),_0xdb8f6d=getTagForSource('manual'),_0x2bc1cd='<'+_0xdb8f6d+'>\x0a'+_0x1708fe+'\x0a'+_0x5b96c9+_0x5dc93e(0x1c3)+_0xdb8f6d+'>';_0x31c8c5[_0x5dc93e(0x22a)]({'text':_0x2bc1cd,'metadata':{'source':_0x5dc93e(0x242),'sourceName':sourceName,'part':_0x3aa5d0,'timestamp':_0x5061b7[_0x5dc93e(0x280)]()}}),_0x3aa5d0++,_0x5f567f+=_0x20b9f1-_0x5d44dd;if(_0x5f567f>=_0x3485b0[_0x5dc93e(0x264)])break;}return _0x31c8c5;}import{getCollectionId as _0x23dff3,getCharacterName}from'./utils/context-utils.js';async function getCollectionId(){return lockedCollectionId||await _0x23dff3();}async function toggleSessionLock(){return lockedCollectionId?(lockedCollectionId=null,![]):(lockedCollectionId=await _0x23dff3(),!![]);}function isSessionLocked(){return lockedCollectionId!==null;}function getLockedSessionInfo(){const _0x501c8b=_0x58d31a;if(!lockedCollectionId)return null;return{'id':lockedCollectionId,'name':_0x501c8b(0x226)+lockedCollectionId[_0x501c8b(0x279)](0x0,0x8)+'...)'};}function getLocalKnowledgeBases(){const _0x34d31c=_0x58d31a,_0x43dcac=getCharacterStableId();return!settings[_0x34d31c(0x199)][_0x43dcac]&&(settings[_0x34d31c(0x199)][_0x43dcac]={}),settings[_0x34d31c(0x199)][_0x43dcac];}function getGlobalKnowledgeBases(){const _0x339e72=_0x58d31a;return!settings[_0x339e72(0x199)][GLOBAL_SCOPE_ID]&&(settings[_0x339e72(0x199)][GLOBAL_SCOPE_ID]={}),settings[_0x339e72(0x199)][GLOBAL_SCOPE_ID];}function getKnowledgeBases(){const _0x22bc0a=getLocalKnowledgeBases(),_0x198fce=getGlobalKnowledgeBases();return{..._0x198fce,..._0x22bc0a};}function addKnowledgeBase(_0x257e43,_0x158af9='manual'){const _0xf07685=_0x58d31a;if(!_0x257e43||!_0x257e43['trim']())throw new Error(_0xf07685(0x198));const _0x5d6491=getCharacterStableId(),_0x2362ac=getLocalKnowledgeBases(),_0x15a996=_0xf07685(0x234)+Date[_0xf07685(0x1b3)]()+'_'+Math[_0xf07685(0x23d)]()[_0xf07685(0x189)](0x24)[_0xf07685(0x279)](0x2,0x9),_0x2dba56={'id':_0x15a996,'name':_0x257e43[_0xf07685(0x28c)](),'enabled':!![],'createdAt':new Date()[_0xf07685(0x280)](),'owner':_0x5d6491,'source':_0x158af9};return _0x2362ac[_0x15a996]=_0x2dba56,saveSettings(),console[_0xf07685(0x232)](_0xf07685(0x1f6)+_0x5d6491+'\x20添加新知识库:\x20'+_0x257e43+_0xf07685(0x1ff)+_0x15a996+')'),_0x2dba56;}async function removeKnowledgeBase(_0x2701bc,_0x23e100){const _0x51dbe8=_0x58d31a,_0x17a79d=getCharacterStableId(),_0x49461c=_0x23e100===_0x51dbe8(0x224)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x2dc46c=_0x49461c[_0x2701bc],_0x294eb1=_0x2dc46c?.['name']||_0x2701bc;if(!_0x2dc46c){console[_0x51dbe8(0x205)]('[翰林院-核心]\x20尝试删除一个不存在的知识库:\x20'+_0x2701bc+_0x51dbe8(0x23f)+_0x23e100+')');return;}const _0x17e58e=_0x23e100===_0x51dbe8(0x224)?_0x2dc46c[_0x51dbe8(0x281)]||GLOBAL_SCOPE_ID:_0x17a79d,_0x1c60db=_0x17e58e+'_'+_0x2701bc;console['log'](_0x51dbe8(0x17f)+_0x2701bc+_0x51dbe8(0x17b)+_0x1c60db);const _0x177240=await purgeStorage(_0x1c60db);_0x177240?(delete _0x49461c[_0x2701bc],saveSettings(),console[_0x51dbe8(0x232)](_0x51dbe8(0x1db)+_0x2701bc+_0x51dbe8(0x22f)),toastr[_0x51dbe8(0x27c)](_0x51dbe8(0x1e0)+_0x294eb1+_0x51dbe8(0x27b))):(console[_0x51dbe8(0x18e)]('[翰林院-核心]\x20清空向量集合\x20'+_0x1c60db+'\x20失败,删除操作中止。'),toastr['error'](_0x51dbe8(0x244)));}function toggleKnowledgeBase(_0x1ac22c,_0x10e82c){const _0x435bf0=_0x58d31a,_0xea3a6d=_0x10e82c===_0x435bf0(0x224)?getGlobalKnowledgeBases():getLocalKnowledgeBases();_0xea3a6d[_0x1ac22c]&&(_0xea3a6d[_0x1ac22c][_0x435bf0(0x228)]=!_0xea3a6d[_0x1ac22c][_0x435bf0(0x228)],saveSettings(),console[_0x435bf0(0x232)](_0x435bf0(0x21b)+_0x1ac22c+_0x435bf0(0x23f)+_0x10e82c+_0x435bf0(0x273)+(_0xea3a6d[_0x1ac22c][_0x435bf0(0x228)]?'启用':'禁用')));}function generateHash(_0x4773c8){const _0x167c79=_0x58d31a;let _0x1467cf=0x0;for(let _0x361110=0x0;_0x361110<_0x4773c8['length'];_0x361110++){const _0x1ef1e6=_0x4773c8[_0x167c79(0x1c0)](_0x361110);_0x1467cf=(_0x1467cf<<0x5)-_0x1467cf+_0x1ef1e6,_0x1467cf=_0x1467cf&_0x1467cf;}return Math[_0x167c79(0x239)](_0x1467cf)['toString'](0x24);}function _0x53b6(_0x470fb9,_0x1fd1c9){const _0x1622f5=_0x1622();return _0x53b6=function(_0x53b69d,_0x3469c5){_0x53b69d=_0x53b69d-0x17b;let _0x14e9bf=_0x1622f5[_0x53b69d];return _0x14e9bf;},_0x53b6(_0x470fb9,_0x1fd1c9);}async function queryVectors(_0x5b0b6d,_0x456ef5={}){const _0x170b01=_0x58d31a,{includeBases:includeBases=null}=_0x456ef5;console['log'](_0x170b01(0x271)+(includeBases?'指定知识库':_0x170b01(0x1a0))+')');const _0x8a8278=getCharacterStableId();let _0x2cf293;if(includeBases)_0x2cf293=includeBases,console[_0x170b01(0x232)](_0x170b01(0x269)+_0x2cf293[_0x170b01(0x264)]+_0x170b01(0x24b));else{const _0x3905b6=getLocalKnowledgeBases(),_0x1d3e32=getGlobalKnowledgeBases(),_0x2bda21=Object[_0x170b01(0x257)](_0x3905b6)[_0x170b01(0x1cf)](_0x38bada=>_0x38bada[_0x170b01(0x228)]),_0xe9c8fc=Object[_0x170b01(0x257)](_0x1d3e32)[_0x170b01(0x1cf)](_0x522f2b=>_0x522f2b[_0x170b01(0x228)]);_0x2cf293=[..._0x2bda21['map'](_0x1f4684=>({..._0x1f4684,'scope':'local'})),..._0xe9c8fc[_0x170b01(0x18a)](_0x544079=>({..._0x544079,'scope':'global'}))];}if(_0x2cf293[_0x170b01(0x264)]===0x0&&!includeBases){console['log'](_0x170b01(0x217));const _0x524db3=await _0x23dff3();if(!_0x524db3)return[];_0x2cf293[_0x170b01(0x22a)]({'id':null,'name':_0x170b01(0x246),'scope':'legacy'});}if(_0x2cf293['length']===0x0)return console[_0x170b01(0x232)]('[翰林院-日志]\x20没有可供查询的知识库,查询中止。'),[];const _0x5696c1=(await getEmbeddings([_0x5b0b6d]))[0x0];if(!_0x5696c1)throw new Error('未能生成查询向量。');let _0x9644f=[];const _0x22a314=_0x2cf293['map'](_0x4e0a58=>{const _0x20aeeb=_0x170b01;let _0x5570dc;if(_0x4e0a58[_0x20aeeb(0x1a9)]===_0x20aeeb(0x25b))_0x5570dc=_0x23dff3();else{const _0x1c3540=_0x4e0a58[_0x20aeeb(0x1a9)]===_0x20aeeb(0x224)?_0x4e0a58[_0x20aeeb(0x281)]||GLOBAL_SCOPE_ID:_0x8a8278;_0x5570dc=Promise['resolve'](_0x1c3540+'_'+_0x4e0a58['id']);}return _0x5570dc[_0x20aeeb(0x1cb)](_0x49584e=>{const _0x337bb4=_0x20aeeb;if(!_0x49584e)return[];console[_0x337bb4(0x232)](_0x337bb4(0x1d8)+_0x4e0a58['name']+'\x20(ID:\x20'+_0x49584e+')');const _0x33a6f1={'collectionId':_0x49584e,'searchText':_0x5b0b6d,'topK':settings[_0x337bb4(0x22c)][_0x337bb4(0x194)],'threshold':settings[_0x337bb4(0x22c)][_0x337bb4(0x23b)],'source':_0x337bb4(0x207),'embeddings':{[_0x5b0b6d]:_0x5696c1}};return fetch(_0x337bb4(0x251),{'method':_0x337bb4(0x196),'headers':context[_0x337bb4(0x1ab)](),'body':JSON[_0x337bb4(0x285)](_0x33a6f1)})[_0x337bb4(0x1cb)](async _0x44b22c=>{const _0x3fa4e9=_0x337bb4;if(!_0x44b22c['ok']){const _0x448b70=await _0x44b22c[_0x3fa4e9(0x265)]();return console[_0x3fa4e9(0x18e)](_0x3fa4e9(0x236)+_0x49584e+'\x20失败:',_0x448b70),[];}const _0x1a89e6=await _0x44b22c['json']();let _0x32ebd7=[];if(Array['isArray'](_0x1a89e6))_0x32ebd7=_0x1a89e6;else{if(_0x1a89e6&&_0x1a89e6[_0x3fa4e9(0x223)]&&Array[_0x3fa4e9(0x248)](_0x1a89e6[_0x3fa4e9(0x223)]))_0x32ebd7=_0x1a89e6[_0x3fa4e9(0x223)];else{if(_0x1a89e6&&_0x1a89e6['results']&&Array[_0x3fa4e9(0x248)](_0x1a89e6[_0x3fa4e9(0x250)]))_0x32ebd7=_0x1a89e6['results'];else _0x1a89e6&&_0x1a89e6[_0x3fa4e9(0x197)]&&Array[_0x3fa4e9(0x248)](_0x1a89e6[_0x3fa4e9(0x197)])&&(_0x32ebd7=_0x1a89e6[_0x3fa4e9(0x197)]);}}const _0xd2bf7=_0x32ebd7[_0x3fa4e9(0x18a)](_0x46dc1f=>{const _0x3d832b=_0x3fa4e9;if(!_0x46dc1f||typeof _0x46dc1f[_0x3d832b(0x265)]!==_0x3d832b(0x1f0))return null;const _0x14fd9d={'source':_0x3d832b(0x277),'sourceName':'未知'},_0x460a1a=_0x46dc1f[_0x3d832b(0x265)]['match'](/^<([^>]+)>/),_0x3c6968=_0x460a1a?_0x460a1a[0x1]:'';switch(_0x3c6968){case _0x3d832b(0x17e):_0x14fd9d[_0x3d832b(0x1cd)]='chat_history';const _0x2c7823=_0x46dc1f['text'][_0x3d832b(0x238)](/楼层:\s*#(\d+),\s*第(\d+)部分/);_0x2c7823&&_0x2c7823[0x1]&&_0x2c7823[0x2]&&(_0x14fd9d[_0x3d832b(0x296)]=parseInt(_0x2c7823[0x1],0xa),_0x14fd9d[_0x3d832b(0x278)]=parseInt(_0x2c7823[0x2],0xa),_0x14fd9d['sourceName']='聊天记录\x20#'+_0x14fd9d[_0x3d832b(0x296)]);break;case'世界书':_0x14fd9d[_0x3d832b(0x1cd)]=_0x3d832b(0x231);const _0x1dfae1=_0x46dc1f[_0x3d832b(0x265)][_0x3d832b(0x238)](/\[来源:\s*([^,]+),\s*条目:\s*([^,]+),\s*第(\d+)部分\]/);_0x1dfae1&&_0x1dfae1[0x1]&&_0x1dfae1[0x2]&&_0x1dfae1[0x3]&&(_0x14fd9d[_0x3d832b(0x20d)]=_0x1dfae1[0x1][_0x3d832b(0x28c)](),_0x14fd9d[_0x3d832b(0x1f2)]=_0x1dfae1[0x2][_0x3d832b(0x28c)](),_0x14fd9d[_0x3d832b(0x278)]=parseInt(_0x1dfae1[0x3],0xa),_0x14fd9d[_0x3d832b(0x1d0)]=_0x14fd9d['bookName']+':\x20'+_0x14fd9d['entryName']);break;case _0x3d832b(0x210):_0x14fd9d[_0x3d832b(0x1cd)]='manual';const _0x4f75ab=_0x46dc1f[_0x3d832b(0x265)]['match'](/\[来源:\s*([^,]+),.*第(\d+)部分\]/);_0x4f75ab&&_0x4f75ab[0x1]&&_0x4f75ab[0x2]&&(_0x14fd9d[_0x3d832b(0x1d0)]=_0x4f75ab[0x1][_0x3d832b(0x28c)](),_0x14fd9d['part']=parseInt(_0x4f75ab[0x2],0xa));break;case'小说录入':_0x14fd9d[_0x3d832b(0x1cd)]=_0x3d832b(0x1d9);const _0x3a1bea=_0x46dc1f[_0x3d832b(0x265)][_0x3d832b(0x238)](/\[来源:\s*([^,]+),\s*([^,]+),\s*([^,]+),\s*([^\]]+)\]/);_0x3a1bea&&(_0x14fd9d[_0x3d832b(0x1d0)]=_0x3a1bea[0x1][_0x3d832b(0x28c)](),_0x14fd9d['volume']=_0x3a1bea[0x2][_0x3d832b(0x28c)](),_0x14fd9d[_0x3d832b(0x19f)]=_0x3a1bea[0x3][_0x3d832b(0x28c)](),_0x14fd9d['section']=_0x3a1bea[0x4][_0x3d832b(0x28c)]());break;}return{..._0x46dc1f,'score':_0x46dc1f['score']||0x1,'metadata':_0x14fd9d};})[_0x3fa4e9(0x1cf)](Boolean);return console[_0x3fa4e9(0x232)]('[翰林院-V13\x20修复]\x20重建元数据后,知识库\x20'+_0x4e0a58[_0x3fa4e9(0x1f4)]+_0x3fa4e9(0x1e6)+_0xd2bf7[_0x3fa4e9(0x264)]+_0x3fa4e9(0x297)),_0xd2bf7;})[_0x337bb4(0x20e)](_0x203e08=>{const _0x296a67=_0x337bb4;return console[_0x296a67(0x18e)](_0x296a67(0x236)+_0x49584e+_0x296a67(0x262),_0x203e08),[];});});}),_0x58976c=await Promise['all'](_0x22a314);_0x9644f=_0x58976c[_0x170b01(0x235)](),console[_0x170b01(0x232)](_0x170b01(0x287)+_0x9644f['length']+'\x20条初步结果。');const _0x4fbdd5=[],_0x4a603e=new Set();for(const _0x466c38 of _0x9644f){if(_0x466c38&&typeof _0x466c38==='object'&&_0x466c38[_0x170b01(0x265)]&&typeof _0x466c38[_0x170b01(0x265)]===_0x170b01(0x1f0)){const _0x24e5df=_0x466c38[_0x170b01(0x265)]['trim']();_0x24e5df[_0x170b01(0x264)]>0x0&&!_0x4a603e[_0x170b01(0x187)](_0x24e5df)&&(_0x4a603e[_0x170b01(0x254)](_0x24e5df),_0x4fbdd5[_0x170b01(0x22a)](_0x466c38));}}console[_0x170b01(0x232)]('[翰林院-日志]\x20去重后剩余\x20'+_0x4fbdd5[_0x170b01(0x264)]+'\x20条结果。'),_0x4fbdd5['sort']((_0xca3a1d,_0x5262c5)=>(_0x5262c5[_0x170b01(0x192)]||0x0)-(_0xca3a1d['score']||0x0));const _0x3c8ac3=[..._0x4fbdd5];return console[_0x170b01(0x232)](_0x170b01(0x183)+_0x3c8ac3[_0x170b01(0x264)]),console[_0x170b01(0x232)](_0x170b01(0x26b),JSON[_0x170b01(0x285)](_0x3c8ac3['slice'](0x0,0x1),null,0x2)),_0x3c8ac3;}async function insertVectors(_0x2393c8,_0x2f9422=null,_0x279c29){const _0x46de9c=_0x58d31a;if(!_0x279c29)throw new Error(_0x46de9c(0x258));if(_0x2393c8['length']===0x0)return{'success':!![],'count':0x0};const _0x5476c6=_0x2393c8[_0x46de9c(0x18a)]((_0x37c82c,_0x4d68ed)=>({'hash':generateHash(_0x37c82c['text']+Date[_0x46de9c(0x1b3)]()+_0x4d68ed),'text':_0x37c82c[_0x46de9c(0x265)],'metadata':_0x37c82c[_0x46de9c(0x223)]||{'source':'unknown','timestamp':new Date()[_0x46de9c(0x280)]()}})),_0x559ae3=_0x5476c6[_0x46de9c(0x212)]((_0x11507f,_0x278ca8,_0xa75533)=>{const _0x3c5c3d=_0x46de9c;return _0x11507f[_0x278ca8[_0x3c5c3d(0x265)]]=_0x2393c8[_0xa75533][_0x3c5c3d(0x22e)],_0x11507f;},{}),_0x1b0009={'collectionId':_0x279c29,'items':_0x5476c6,'source':'webllm','embeddings':_0x559ae3},_0x2042dc=await fetch(_0x46de9c(0x1b1),{'method':'POST','headers':context[_0x46de9c(0x1ab)](),'body':JSON[_0x46de9c(0x285)](_0x1b0009),'signal':_0x2f9422});if(!_0x2042dc['ok']){const _0xa10c50=await _0x2042dc[_0x46de9c(0x265)]();console[_0x46de9c(0x18e)](_0x46de9c(0x270),_0xa10c50);throw new Error(_0x46de9c(0x203)+_0x2042dc[_0x46de9c(0x286)]+':\x20'+_0xa10c50);}return{'success':!![],'count':_0x5476c6[_0x46de9c(0x264)]};}async function getVectorCount(_0x2924cb=null,_0x15f890=_0x58d31a(0x1d6)){const _0x2e4bdf=_0x58d31a,_0x8516ab=getCharacterStableId();if(_0x2924cb){const _0x4774b3=_0x15f890===_0x2e4bdf(0x224)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x5b5ed1=_0x4774b3[_0x2924cb];if(!_0x5b5ed1)return console['warn'](_0x2e4bdf(0x19b)+_0x15f890+_0x2e4bdf(0x18d)+_0x2924cb+_0x2e4bdf(0x190)),0x0;const _0x57be13=_0x15f890===_0x2e4bdf(0x224)?_0x5b5ed1['owner']||GLOBAL_SCOPE_ID:_0x8516ab,_0xd38398=_0x57be13+'_'+_0x2924cb;return await countVectorsInCollection(_0xd38398);}else{console[_0x2e4bdf(0x232)](_0x2e4bdf(0x1ba));const _0x1a5e58=Object['values'](getLocalKnowledgeBases()),_0x37c711=Object['values'](getGlobalKnowledgeBases()),_0x154ae9=[];_0x1a5e58[_0x2e4bdf(0x1a4)](_0x3eef14=>{const _0x3c9702=_0x2e4bdf,_0x1e13b9=_0x8516ab+'_'+_0x3eef14['id'];_0x154ae9[_0x3c9702(0x22a)](countVectorsInCollection(_0x1e13b9));}),_0x37c711['forEach'](_0x52a073=>{const _0x5edfb8=_0x2e4bdf,_0x7b0c80=_0x52a073[_0x5edfb8(0x281)]||GLOBAL_SCOPE_ID,_0x55ae72=_0x7b0c80+'_'+_0x52a073['id'];_0x154ae9[_0x5edfb8(0x22a)](countVectorsInCollection(_0x55ae72));});const _0x357fd3=await _0x23dff3();_0x154ae9[_0x2e4bdf(0x22a)](countVectorsInCollection(_0x357fd3));const _0x540cf1=await Promise['all'](_0x154ae9),_0x1582a4=_0x540cf1['reduce']((_0x211a7b,_0x2dcdbe)=>_0x211a7b+_0x2dcdbe,0x0);return console[_0x2e4bdf(0x232)]('[翰林院-日志]\x20所有知识库统计完成,总向量数:\x20'+_0x1582a4),_0x1582a4;}}async function countVectorsInCollection(_0x4f6a19){const _0x1a7a8a=_0x58d31a;if(!_0x4f6a19)return 0x0;console[_0x1a7a8a(0x232)](_0x1a7a8a(0x1c9)+_0x4f6a19);const _0x1ba29d={'collectionId':_0x4f6a19,'source':_0x1a7a8a(0x207),'embeddings':{}};try{const _0x32ade5=await fetch(_0x1a7a8a(0x27d),{'method':_0x1a7a8a(0x196),'headers':context['getRequestHeaders'](),'body':JSON[_0x1a7a8a(0x285)](_0x1ba29d)});if(!_0x32ade5['ok']){if(_0x32ade5['status']===0x194)console[_0x1a7a8a(0x232)](_0x1a7a8a(0x1a2)+_0x4f6a19+_0x1a7a8a(0x1c6));else{const _0x1922bd=await _0x32ade5[_0x1a7a8a(0x265)]();console[_0x1a7a8a(0x205)](_0x1a7a8a(0x208)+_0x4f6a19+_0x1a7a8a(0x193)+_0x32ade5[_0x1a7a8a(0x286)]+'):',_0x1922bd);}return 0x0;}const _0x5ad724=await _0x32ade5[_0x1a7a8a(0x1a8)]();let _0x93c1d4=0x0;if(Array[_0x1a7a8a(0x248)](_0x5ad724))_0x93c1d4=_0x5ad724[_0x1a7a8a(0x264)];else _0x5ad724&&_0x5ad724[_0x1a7a8a(0x272)]&&(_0x93c1d4=_0x5ad724[_0x1a7a8a(0x272)][_0x1a7a8a(0x264)]);return _0x93c1d4;}catch(_0x46639a){return console[_0x1a7a8a(0x18e)](_0x1a7a8a(0x195)+_0x4f6a19+_0x1a7a8a(0x262),_0x46639a),0x0;}}async function purgeStorage(_0x2b01f1=null){const _0x5e4e4d=_0x58d31a;console[_0x5e4e4d(0x232)](_0x5e4e4d(0x1d1));const _0x2a268e=_0x2b01f1||await getCollectionId();if(!_0x2a268e)return console['error'](_0x5e4e4d(0x1bb)),toastr[_0x5e4e4d(0x18e)](_0x5e4e4d(0x26d)),![];console[_0x5e4e4d(0x232)](_0x5e4e4d(0x1b5)+_0x2a268e);const _0x379390={'collectionId':_0x2a268e};console[_0x5e4e4d(0x232)](_0x5e4e4d(0x299),JSON[_0x5e4e4d(0x285)](_0x379390,null,0x2));const _0x465409=await fetch('/api/vector/purge',{'method':_0x5e4e4d(0x196),'headers':context['getRequestHeaders'](),'body':JSON[_0x5e4e4d(0x285)](_0x379390)});console[_0x5e4e4d(0x232)](_0x5e4e4d(0x1d7)+_0x465409['status']);if(!_0x465409['ok']){const _0x4e8412=await _0x465409[_0x5e4e4d(0x265)]();console[_0x5e4e4d(0x18e)](_0x5e4e4d(0x23e),_0x4e8412);}else console[_0x5e4e4d(0x232)](_0x5e4e4d(0x18f));return _0x465409['ok'];}function getMessagesForCondensation(_0x12fc04=null){const _0x3038cd=_0x58d31a;if(!settings['condensation'][_0x3038cd(0x228)])return showNotification(_0x3038cd(0x260),_0x3038cd(0x293)),[];const {layerStart:_0x2f6bd2,layerEnd:_0x2b07dd}=settings[_0x3038cd(0x24f)],_0x23f94a=_0x12fc04||settings['condensation']['messageTypes'],_0x434730=context[_0x3038cd(0x1c7)]['length'],_0x1c73f3=Math[_0x3038cd(0x291)](0x0,_0x2f6bd2-0x1),_0xefe8c5=_0x2b07dd===0x0||_0x2b07dd>_0x434730?_0x434730:Math[_0x3038cd(0x1b8)](_0x434730,_0x2b07dd),_0x30167b=context['chat'][_0x3038cd(0x20c)](_0x1c73f3,_0xefe8c5);return _0x30167b['filter'](_0x49c70b=>{const _0x16f684=_0x3038cd,_0x35da83=_0x49c70b[_0x16f684(0x298)]===!![],_0x3a346f=_0x49c70b['is_user']===![];if(!_0x49c70b[_0x16f684(0x1be)]||!_0x49c70b[_0x16f684(0x1be)][_0x16f684(0x28c)]())return![];return _0x23f94a[_0x16f684(0x26e)]&&_0x35da83||_0x23f94a['ai']&&_0x3a346f;});}async function processCondensation(_0x6313ab,_0x58a3cc=()=>{},_0x159a26=null){const _0x2f38f4=_0x58d31a;if(!_0x6313ab||_0x6313ab[_0x2f38f4(0x264)]===0x0)return{'success':![],'error':'No\x20messages\x20to\x20process.'};try{let _0x251b5d,_0x311bf2;const _0x433547=getCharacterName()||_0x2f38f4(0x249);if(_0x159a26){const _0x29c59b=_0x159a26[_0x2f38f4(0x1a7)]??'?',_0x409d9d=_0x159a26['end']===0x0?'末':_0x159a26[_0x2f38f4(0x186)]??'?';_0x251b5d=_0x433547+':\x20'+_0x29c59b+'楼-'+_0x409d9d+'楼';}else{const _0x791d6d=new Date()[_0x2f38f4(0x1ee)](_0x2f38f4(0x241),{'hour12':![]});_0x251b5d=_0x2f38f4(0x1e5)+_0x791d6d;}const _0x1cb289=Object[_0x2f38f4(0x257)](getLocalKnowledgeBases()),_0x59c472=_0x1cb289[_0x2f38f4(0x230)](_0x54c959=>_0x54c959[_0x2f38f4(0x1f4)]===_0x251b5d);if(_0x59c472)_0x311bf2=_0x59c472['id'],_0x58a3cc('[翰林院-核心]\x20检测到同名知识库\x20\x22'+_0x251b5d+_0x2f38f4(0x19e),_0x2f38f4(0x1c4));else{_0x58a3cc(_0x2f38f4(0x25c)+_0x251b5d+_0x2f38f4(0x1c1),'info');const _0x1a1f76=addKnowledgeBase(_0x251b5d,'chat_history');_0x311bf2=_0x1a1f76['id'];}const _0x11a666=getCharacterStableId(),_0x501776=_0x11a666+'_'+_0x311bf2;_0x58a3cc(_0x2f38f4(0x294)+_0x251b5d+_0x2f38f4(0x1bd)+_0x501776+')',_0x2f38f4(0x27c));const _0x55e7ae=[],_0x581bae=context['chat'];for(const _0x5a16c9 of _0x6313ab){const _0x372902=(_0x5a16c9['mes']||'')[_0x2f38f4(0x237)](/<[^>]*>/g,'')[_0x2f38f4(0x28c)]();if(_0x372902['length']===0x0)continue;let _0x38cc9c;if(_0x5a16c9[_0x2f38f4(0x296)]!==undefined&&_0x5a16c9[_0x2f38f4(0x296)]!==null)_0x38cc9c=_0x5a16c9[_0x2f38f4(0x296)];else{const _0x75c47=_0x581bae[_0x2f38f4(0x274)](_0x3cbc5d=>_0x3cbc5d===_0x5a16c9);_0x38cc9c=_0x75c47!==-0x1?_0x75c47+0x1:-0x1;}const _0x388638=new Date(_0x5a16c9['send_date']),_0x2afbc5=isNaN(_0x388638[_0x2f38f4(0x20f)]())?new Date()['toISOString']():_0x388638[_0x2f38f4(0x280)](),_0xe17f52=splitIntoChunks(_0x372902,_0x2f38f4(0x1dd),{'floor':_0x38cc9c,'is_user':_0x5a16c9[_0x2f38f4(0x298)],'timestamp':_0x2afbc5});_0x55e7ae[_0x2f38f4(0x22a)](..._0xe17f52);}if(_0x55e7ae[_0x2f38f4(0x264)]===0x0)return{'success':!![],'count':0x0};_0x58a3cc(_0x2f38f4(0x184)+_0x6313ab[_0x2f38f4(0x264)]+_0x2f38f4(0x1c2)+_0x55e7ae[_0x2f38f4(0x264)]+_0x2f38f4(0x1e8),_0x2f38f4(0x1c4));const _0x5f45d6=settings[_0x2f38f4(0x219)][_0x2f38f4(0x1e9)]||0x5;let _0x33fd55=0x0;for(let _0x2766ea=0x0;_0x2766ea<_0x55e7ae[_0x2f38f4(0x264)];_0x2766ea+=_0x5f45d6){const _0x229b3f=_0x55e7ae[_0x2f38f4(0x20c)](_0x2766ea,_0x2766ea+_0x5f45d6),_0x434277=_0x229b3f[_0x2f38f4(0x18a)](_0x1e97bc=>_0x1e97bc[_0x2f38f4(0x265)]),_0x5ca940=await getEmbeddings(_0x434277);if(_0x229b3f[_0x2f38f4(0x264)]!==_0x5ca940[_0x2f38f4(0x264)])throw new Error('文本块和向量数量不匹配');const _0x438587=_0x229b3f[_0x2f38f4(0x18a)]((_0x3d9f58,_0x3709e6)=>({..._0x3d9f58,'vector':_0x5ca940[_0x3709e6]}));await insertVectors(_0x438587,null,_0x501776),_0x33fd55+=_0x229b3f[_0x2f38f4(0x264)];}if(_0x159a26){const _0x38e75e=_0x159a26['end']===0x0?context[_0x2f38f4(0x1c7)]['length']:_0x159a26[_0x2f38f4(0x186)],_0x1624d6=getCharacterStableId();!settings['condensationHistory'][_0x1624d6]&&(settings[_0x2f38f4(0x20a)][_0x1624d6]={}),settings[_0x2f38f4(0x20a)][_0x1624d6][_0x501776]={'start':_0x159a26[_0x2f38f4(0x1a7)],'end':_0x38e75e,'timestamp':new Date()['toISOString']()},saveSettings(),_0x58a3cc('[翰林院-核心]\x20已为宝库\x20'+_0x501776+_0x2f38f4(0x288)+_0x159a26[_0x2f38f4(0x1a7)]+'-'+_0x38e75e,'info');}_0x58a3cc('[翰林院-核心]\x20聊天记录凝识完成,成功插入\x20'+_0x33fd55+_0x2f38f4(0x214),_0x2f38f4(0x27c));const _0x45ae17=_0x6313ab[_0x2f38f4(0x18a)](_0x299cf0=>{const _0x2ac38b=_0x2f38f4,_0x4b71b5=_0x581bae[_0x2ac38b(0x274)](_0x424a7a=>_0x424a7a===_0x299cf0),_0x35e87a=_0x4b71b5!==-0x1?_0x4b71b5+0x1:-0x1,_0x1993de=_0x299cf0[_0x2ac38b(0x298)]?'用户':getCharacterName()||'AI';return'['+_0x1993de+'\x20-\x20楼层\x20#'+_0x35e87a+']\x20的消息已成功凝识。';});return{'success':!![],'count':_0x33fd55,'messages':_0x45ae17};}catch(_0x137f0a){return console[_0x2f38f4(0x18e)]('[翰林院-核心]\x20processCondensation\x20失败:',_0x137f0a),_0x58a3cc(_0x2f38f4(0x247)+_0x137f0a['message'],_0x2f38f4(0x18e)),{'success':![],'error':_0x137f0a[_0x2f38f4(0x17c)]};}}async function rerankResults(_0x58e66b,_0x30b6fa,_0x3ee856){const _0x436bf6=_0x58d31a;let _0x5de8f4=_0x58e66b,_0x3f6895=![];if(_0x3ee856[_0x436bf6(0x1f7)][_0x436bf6(0x228)]&&_0x58e66b[_0x436bf6(0x264)]>0x0){console['log']('[翰林院-Rerank]\x20开始外部API重排序...');try{const _0x4735b4=_0x58e66b[_0x436bf6(0x18a)](_0x27254b=>_0x27254b[_0x436bf6(0x265)]),_0x18e43e=await executeRerank(_0x30b6fa,_0x4735b4,_0x3ee856[_0x436bf6(0x1f7)]),_0x125b00=_0x58e66b['map']((_0x533aea,_0x2afe5b)=>({..._0x533aea,'original_index':_0x2afe5b}));_0x5de8f4=_0x125b00['map'](_0x45c143=>{const _0x451db7=_0x436bf6,_0x5449f3=_0x18e43e[_0x451db7(0x250)][_0x451db7(0x230)](_0xc9db83=>_0xc9db83[_0x451db7(0x1f9)]===_0x45c143[_0x451db7(0x211)]),_0x27ec4b=_0x5449f3?_0x5449f3[_0x451db7(0x1dc)]:0x0;return{..._0x45c143,'rerank_score':_0x27ec4b};}),_0x3f6895=!![];}catch(_0x39e614){console['error'](_0x436bf6(0x259),_0x39e614);if(_0x3ee856[_0x436bf6(0x1f7)][_0x436bf6(0x263)])showNotification(_0x436bf6(0x1a5)+_0x39e614[_0x436bf6(0x17c)],'error');_0x5de8f4['forEach'](_0x40252f=>_0x40252f[_0x436bf6(0x284)]=0x0);}}else _0x5de8f4['forEach'](_0x14c6fb=>_0x14c6fb[_0x436bf6(0x284)]=0x0);console['log']('[翰林院-Rerank]\x20开始元数据加权最终排序...');const _0x1b8db9=context[_0x436bf6(0x1c7)][_0x436bf6(0x264)],_0x456e8b=_0x3ee856[_0x436bf6(0x1f7)]['hybrid_alpha'],_0x232b10=_0x5de8f4['map'](_0x2d0371=>{const _0x558802=_0x436bf6;let _0x23baec=0x1;const _0x16c444=_0x2d0371[_0x558802(0x223)]||{};switch(_0x16c444[_0x558802(0x1cd)]){case _0x558802(0x231):_0x23baec*=1.2;break;case'manual':_0x23baec*=1.1;break;case _0x558802(0x1dd):if(_0x16c444[_0x558802(0x296)]&&_0x1b8db9>0x0){const _0x1f6ec8=_0x16c444[_0x558802(0x296)]/_0x1b8db9;_0x23baec*=0x1+_0x1f6ec8;}break;}const _0x271b5d=_0x2d0371[_0x558802(0x284)]*_0x456e8b+(_0x2d0371[_0x558802(0x192)]||0x0)*(0x1-_0x456e8b),_0x2b59d4=_0x271b5d*_0x23baec;return{'text':_0x2d0371['text'],'score':_0x2d0371[_0x558802(0x192)],'rerank_score':_0x2d0371[_0x558802(0x284)],'final_score':_0x2b59d4,'metadata':_0x2d0371['metadata']};});_0x232b10['sort']((_0x30f276,_0x341703)=>(_0x341703[_0x436bf6(0x267)]||0x0)-(_0x30f276[_0x436bf6(0x267)]||0x0)),console[_0x436bf6(0x232)](_0x436bf6(0x202));let _0x4327bd=_0x232b10;return _0x3ee856['rerank']['superSortEnabled']&&(_0x4327bd=superSort(_0x232b10)),{'results':_0x4327bd[_0x436bf6(0x20c)](0x0,_0x3ee856[_0x436bf6(0x1f7)]['top_n']),'reranked':_0x3f6895};}async function rearrangeChat(_0x45c500,_0xf9b68d,_0x241a53,_0x164386){const _0x4d59e1=_0x58d31a,_0x248b6a={'novel':_0x4d59e1(0x201),'chat_history':_0x4d59e1(0x1aa),'lorebook':_0x4d59e1(0x181),'manual':_0x4d59e1(0x215)};Object['values'](_0x248b6a)[_0x4d59e1(0x1a4)](_0x5bd74e=>setExtensionPrompt(_0x5bd74e,'',0x0,0x0,![],0x0));if(_0x164386===_0x4d59e1(0x1fa)||!settings[_0x4d59e1(0x219)]['enabled'])return;const _0x581fc3=_0x45c500[_0x4d59e1(0x20c)](-settings[_0x4d59e1(0x22c)][_0x4d59e1(0x282)]);if(_0x581fc3['length']===0x0)return;const _0x4d242c=_0x581fc3[_0x4d59e1(0x18a)](_0x26a0f4=>_0x26a0f4['mes'])['join']('\x20')['replace'](/<[^>]*>/g,'')[_0x4d59e1(0x28c)]();if(!_0x4d242c)return;try{const _0x2fabc2=0x2,_0x5006dd=settings[_0x4d59e1(0x275)]||0x1;let _0x4fd481=![];if(_0x5006dd<_0x2fabc2){console[_0x4d59e1(0x232)](_0x4d59e1(0x1de)+_0x5006dd+'),开始强制重分类所有知识库...'),toastr[_0x4d59e1(0x1c4)](_0x4d59e1(0x18b),_0x4d59e1(0x27a));const _0xd5363c=getKnowledgeBases();for(const _0x2e1271 of Object[_0x4d59e1(0x257)](_0xd5363c)){const _0x5d4d7e=_0x2e1271[_0x4d59e1(0x1f4)],_0x238567=_0x2e1271[_0x4d59e1(0x1cd)];if(_0x5d4d7e[_0x4d59e1(0x1f8)](_0x4d59e1(0x1ac)))_0x2e1271[_0x4d59e1(0x1cd)]=_0x4d59e1(0x242);else{if(_0x5d4d7e[_0x4d59e1(0x1f8)](_0x4d59e1(0x290)))_0x2e1271[_0x4d59e1(0x1cd)]=_0x4d59e1(0x1d9);else _0x5d4d7e[_0x4d59e1(0x28f)]('楼-')&&_0x5d4d7e[_0x4d59e1(0x28f)]('楼')&&_0x5d4d7e[_0x4d59e1(0x28f)](':')?_0x2e1271['source']=_0x4d59e1(0x1dd):_0x2e1271[_0x4d59e1(0x1cd)]=_0x4d59e1(0x231);}_0x238567!==_0x2e1271['source']&&console[_0x4d59e1(0x232)](_0x4d59e1(0x28b)+_0x5d4d7e+_0x4d59e1(0x24c)+(_0x238567||'无')+_0x4d59e1(0x27e)+_0x2e1271['source']+']');}settings['settingsVersion']=_0x2fabc2,_0x4fd481=!![];}_0x4fd481&&(console['log']('[翰林院-户口普查]\x20普查完成,正在保存更新后的户籍...'),saveSettings());let _0x4aa626=[];const _0x4bef35=settings['rerank'][_0x4d59e1(0x25d)];if(_0x4bef35[_0x4d59e1(0x228)]){console[_0x4d59e1(0x232)](_0x4d59e1(0x1df));const _0x25026a=Object[_0x4d59e1(0x257)](getKnowledgeBases())[_0x4d59e1(0x1cf)](_0x854ff7=>_0x854ff7[_0x4d59e1(0x228)]),_0xdfac65=Object[_0x4d59e1(0x1a1)](_0x4bef35['sources'])[_0x4d59e1(0x1cf)](_0x575633=>_0x4bef35[_0x4d59e1(0x1f3)][_0x575633]&&_0x4bef35[_0x4d59e1(0x1f3)][_0x575633]['enabled']),_0x1e1416=[];let _0xc07318=[..._0x25026a];for(const _0x13b55f of _0xdfac65){const _0x45e21b=_0x4bef35['sources'][_0x13b55f],_0x505b8e=_0xc07318[_0x4d59e1(0x1cf)](_0x2bb751=>_0x2bb751[_0x4d59e1(0x1cd)]===_0x13b55f);_0xc07318=_0xc07318[_0x4d59e1(0x1cf)](_0x2b291b=>!_0x505b8e['includes'](_0x2b291b));if(_0x505b8e[_0x4d59e1(0x264)]>0x0){console[_0x4d59e1(0x232)](_0x4d59e1(0x21e)+_0x13b55f+'\x20('+_0x505b8e[_0x4d59e1(0x264)]+_0x4d59e1(0x222));const _0x3b3449=queryVectors(_0x4d242c,{'includeBases':_0x505b8e})[_0x4d59e1(0x1cb)](_0x1dc450=>{const _0x4c5aee=_0x4d59e1;console[_0x4c5aee(0x232)](_0x4c5aee(0x1ec)+_0x13b55f+'\x20返回\x20'+_0x1dc450['length']+_0x4c5aee(0x297));let _0x53d206=_0x1dc450['filter'](_0x39ff3d=>_0x39ff3d[_0x4c5aee(0x223)]?.['source']===_0x13b55f);return _0x53d206=_0x53d206[_0x4c5aee(0x20c)](0x0,_0x45e21b['count']),console[_0x4c5aee(0x232)](_0x4c5aee(0x1b2)+_0x13b55f+_0x4c5aee(0x255)+_0x53d206[_0x4c5aee(0x264)]+_0x4c5aee(0x297)),settings[_0x4c5aee(0x1f7)][_0x4c5aee(0x200)]&&(_0x53d206=superSort(_0x53d206)),_0x53d206;});_0x1e1416['push'](_0x3b3449);}}const _0x2f9ee9=_0xc07318;if(_0x2f9ee9[_0x4d59e1(0x264)]>0x0){console['log'](_0x4d59e1(0x21c)+_0x2f9ee9[_0x4d59e1(0x264)]+'个库)');const _0x113620=queryVectors(_0x4d242c,{'includeBases':_0x2f9ee9})[_0x4d59e1(0x1cb)](async _0x41dcf5=>{const _0xdb6d46=_0x4d59e1;console[_0xdb6d46(0x232)](_0xdb6d46(0x276)+_0x41dcf5[_0xdb6d46(0x264)]+_0xdb6d46(0x297)),console[_0xdb6d46(0x232)]('[翰林院]\x20开始处理常规池...');const _0x215a98=await rerankResults(_0x41dcf5,_0x4d242c,settings),_0x18e181=_0x215a98[_0xdb6d46(0x250)];return console['log'](_0xdb6d46(0x1ca)+(_0x18e181||[])[_0xdb6d46(0x264)]+_0xdb6d46(0x297)),_0x215a98[_0xdb6d46(0x1b7)]&&settings['rerank'][_0xdb6d46(0x263)]&&showNotification(_0xdb6d46(0x243),_0xdb6d46(0x27c)),_0x18e181;});_0x1e1416[_0x4d59e1(0x22a)](_0x113620);}const _0x176c00=await Promise['all'](_0x1e1416);_0x4aa626=_0x176c00[_0x4d59e1(0x235)]();}else{console['log']('[翰林院]\x20进入传统处理流程...');const _0x2e29c9=await queryVectors(_0x4d242c),_0x14465b=await rerankResults(_0x2e29c9,_0x4d242c,settings);_0x4aa626=_0x14465b['results'],_0x14465b['reranked']&&settings[_0x4d59e1(0x1f7)][_0x4d59e1(0x263)]&&showNotification(_0x4d59e1(0x188),'success');}if(!_0x4aa626||_0x4aa626[_0x4d59e1(0x264)]===0x0){console[_0x4d59e1(0x232)](_0x4d59e1(0x1ae));return;}console['log'](_0x4d59e1(0x268)+_0x4aa626[_0x4d59e1(0x264)]+_0x4d59e1(0x297));const _0x208924={'novel':[],'chat_history':[],'lorebook':[],'manual':[]};_0x4aa626[_0x4d59e1(0x1a4)](_0x2a0be3=>{const _0x167af7=_0x4d59e1,_0x360970=_0x2a0be3[_0x167af7(0x223)]?.[_0x167af7(0x1cd)];_0x360970&&_0x208924[_0x167af7(0x1af)](_0x360970)&&_0x208924[_0x360970][_0x167af7(0x22a)](_0x2a0be3);});for(const _0x354748 in _0x208924){const _0x30aea7=_0x208924[_0x354748];if(_0x30aea7[_0x4d59e1(0x264)]===0x0)continue;const _0x58761d=settings[_0x4d59e1(0x19d)+_0x354748[_0x4d59e1(0x237)](_0x4d59e1(0x1ea),'')];if(!_0x58761d){console[_0x4d59e1(0x205)]('[翰林院]\x20未找到来源\x20\x27'+_0x354748+_0x4d59e1(0x1fe));continue;}const _0x82bdb0=_0x30aea7[_0x4d59e1(0x18a)](_0x184620=>_0x184620[_0x4d59e1(0x265)])['join']('\x0a\x0a'),_0x3ad659='{{'+_0x354748[_0x4d59e1(0x237)]('_history','')+_0x4d59e1(0x218);let _0x429dcd=_0x58761d['template'][_0x4d59e1(0x237)](_0x3ad659,_0x82bdb0);_0x429dcd[_0x4d59e1(0x28c)]()&&(_0x429dcd='%%'+_0x248b6a[_0x354748]+'%%'+_0x429dcd),setExtensionPrompt(_0x248b6a[_0x354748],_0x429dcd,_0x58761d[_0x4d59e1(0x1c5)],_0x58761d[_0x4d59e1(0x1e7)],![],_0x58761d[_0x4d59e1(0x1ed)]),console['log']('[翰林院]\x20已为来源\x20\x27'+_0x354748+_0x4d59e1(0x256)+_0x30aea7['length']+'\x20条内容。');}}catch(_0x160d92){console[_0x4d59e1(0x18e)]('[翰林院]\x20检索或注入时发生错误:',_0x160d92);if(settings[_0x4d59e1(0x219)]['notify'])showNotification(_0x4d59e1(0x1fb)+_0x160d92[_0x4d59e1(0x17c)],_0x4d59e1(0x18e));}}async function moveKnowledgeBase(_0x4df7d9,_0x47d52d){const _0x32baae=_0x58d31a,_0x2700ee=_0x47d52d===_0x32baae(0x224)?_0x32baae(0x1d6):_0x32baae(0x224),_0x312456=getCharacterStableId();if(!_0x312456&&_0x2700ee===_0x32baae(0x1d6)){toastr[_0x32baae(0x18e)](_0x32baae(0x21f));return;}const _0x1c73bf=_0x47d52d==='global'?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x73f86a=_0x2700ee===_0x32baae(0x224)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x5a6198=_0x1c73bf[_0x4df7d9];if(!_0x5a6198){const _0x41e453=_0x32baae(0x283)+_0x47d52d+_0x32baae(0x18d)+_0x4df7d9+_0x32baae(0x190);console['error'](_0x32baae(0x1fd)+_0x41e453),toastr[_0x32baae(0x18e)](_0x32baae(0x266));return;}_0x47d52d===_0x32baae(0x1d6)&&_0x2700ee==='global'&&!_0x5a6198['owner']&&(console[_0x32baae(0x232)](_0x32baae(0x24a)+_0x4df7d9+'\x20补充所有者ID:\x20'+_0x312456),_0x5a6198[_0x32baae(0x281)]=_0x312456);delete _0x1c73bf[_0x4df7d9],_0x73f86a[_0x4df7d9]=_0x5a6198,saveSettings();const _0x1fe0d9='知识库【'+_0x5a6198[_0x32baae(0x1f4)]+_0x32baae(0x26a)+(_0x2700ee===_0x32baae(0x224)?'全局':'局部')+'。';console[_0x32baae(0x232)](_0x32baae(0x1fd)+_0x1fe0d9);}async function getAllVectorsFromCollection(_0x5df398){const _0x40b2b8=_0x58d31a,_0x6a88f9='*',_0x54f283={'collectionId':_0x5df398,'searchText':_0x6a88f9,'topK':0x2710,'threshold':0x0,'source':_0x40b2b8(0x207),'embeddings':{}},_0xb12183=(await getEmbeddings([_0x6a88f9]))[0x0];_0x54f283['embeddings']={[_0x6a88f9]:_0xb12183};const _0x5c9147=await fetch('/api/vector/query',{'method':_0x40b2b8(0x196),'headers':context[_0x40b2b8(0x1ab)](),'body':JSON['stringify'](_0x54f283)});if(!_0x5c9147['ok']){if(_0x5c9147[_0x40b2b8(0x286)]===0x194)return console[_0x40b2b8(0x232)](_0x40b2b8(0x25f)+_0x5df398+_0x40b2b8(0x1fc)),[];const _0x435b36=await _0x5c9147[_0x40b2b8(0x265)]();throw new Error(_0x40b2b8(0x1d2)+_0x5df398+_0x40b2b8(0x26c)+_0x435b36);}const _0x5cc50b=await _0x5c9147[_0x40b2b8(0x1a8)]();return _0x5cc50b['metadata']||_0x5cc50b[_0x40b2b8(0x250)]||_0x5cc50b[_0x40b2b8(0x197)]||[];} +'use strict';const _0x1b9b83=_0x3f8a;(function(_0x54c676,_0x509f83){const _0x22a8a0=_0x3f8a,_0x2f0332=_0x54c676();while(!![]){try{const _0x54e0cf=-parseInt(_0x22a8a0(0x26c))/0x1+parseInt(_0x22a8a0(0x2f6))/0x2*(parseInt(_0x22a8a0(0x21c))/0x3)+-parseInt(_0x22a8a0(0x260))/0x4+parseInt(_0x22a8a0(0x2ec))/0x5*(-parseInt(_0x22a8a0(0x2a2))/0x6)+parseInt(_0x22a8a0(0x304))/0x7+parseInt(_0x22a8a0(0x229))/0x8+parseInt(_0x22a8a0(0x2fb))/0x9*(parseInt(_0x22a8a0(0x270))/0xa);if(_0x54e0cf===_0x509f83)break;else _0x2f0332['push'](_0x2f0332['shift']());}catch(_0x182821){_0x2f0332['push'](_0x2f0332['shift']());}}}(_0x7481,0x2b7c1));import{extension_prompt_roles,setExtensionPrompt}from'/script.js';function _0x7481(){const _0x5057a4=['count','\x20条结果。','[翰林院-核心]\x20成功删除知识库\x20','\x20的知识库。','\x20个块。','tags','keys','[翰林院-核心]\x20ingestTextToHanlinyuan\x20失败:','scope','sourceName','[翰林院-核心]\x20知识库\x20','[翰林院-日志]\x20统一角色卡模式开启...','reduce','\x22\x20已从\x20[','extensionSettings','success','part','[翰林院-户口普查]\x20检测到旧版设置\x20(V','Rerank失败:\x20','[翰林院-日志]\x20统计目标集合ID:\x20','hanlinyuanRagProcessor','[翰林院-修复]\x20最终返回数组样本:','substring','relevance_score','聊天记录\x20#','[来源:\x20','error','add','[翰林院]\x20经过预处理后,最终检索文本为空,注入中止。','[翰林院-日志]\x20清空目标集合ID:\x20','\x20失败,删除操作中止。','metadata','condensation','sources','push','[翰林院-日志]\x20忆识存入API错误:','对话记录大总结','\x20条初步结果。','[来源:\x20聊天记录,\x20楼层:\x20#','priorityRetrieval','[翰林院-户口普查]\x20普查完成,正在保存更新后的户籍...','HANLINYUAN_RAG_NOVEL','翰林院忆识核心已启动\x20(V5.2-集成版),已注册到全局\x20hanlinyuanRagProcessor\x20对象。','tagExtractionEnabled','legacy','手动录入:\x20','删除知识库失败,未能清空后端数据。','[翰林院-分块]\x20未知的来源类型\x20\x27','HANLINYUAN_RAG_LOREBOOK','在源作用域\x20\x27','[翰林院-核心]\x20已为宝库\x20','[翰林院-迁移]\x20旧宝库已清空。','is_user','join','指定知识库','values','rerank_score','[翰林院-核心]\x20文本录入失败:\x20','[翰林院]\x20最终准备注入\x20','[翰林院-核心]\x20文本录入任务被用户中止。','then','score','凝识之权未开启','[翰林院-核心]\x20检测到同名知识库\x20\x22','小说:','_global','hashes','[翰林院-日志]\x20没有启用的新知识库,尝试查询旧版单体宝库...','chat_history','[翰林院-日志]\x20去重后剩余\x20','HANLINYUAN_RAG_CHAT','vectors_rearrangeChat','[翰林院-日志]\x20所有知识库查询完毕,共获得\x20','matchThreshold','当前聊天\x20(','78867VrHMmx','$1','queryPreprocessing','\x20失败:','original_index','[翰林院-配置]\x20','文本块和向量数量不匹配','independentChatMemoryEnabled','[翰林院-日志]\x20查询白名单已提供,将查询\x20','sousuo','message','[翰林院-核心]\x20聊天记录凝识失败:\x20','hanlinyuan-rag-core','949592mwdSqg','index','\x20个向量条目。','enabled','(已锁定:\x20','AbortError','[翰林院-日志]\x20集合\x20','text','\x27\x20注入\x20','reranked','findIndex','chat','\x22\x20已成功重命名为\x20\x22','zh-CN','\x20列表API时出现问题\x20(状态:\x20','slice','[翰林院-Rerank]\x20元数据加权排序完成。','[翰林院-核心]\x20凝识任务已锁定知识库:\x20','retrieval','\x20不存在,返回空数组。','[翰林院-户口普查]\x20知识库\x20\x22',',\x20向量化录入时间:\x20','isArray','\x20个特定知识库。','owner','string','send_date',',\x20第','世界书','bianzhuan','unknown','用户取消了迁移操作','[翰林院-日志]\x20/api/vector/purge\x20响应状态:\x20','toISOString','lorebook','hybrid_alpha','POST','[翰林院-日志]\x20独立聊天记忆模式开启...','stringify','final_score','toString','find','toLocaleString','\x5c$&','[翰林院-日志]\x20无法获取当前聊天ID,跳过聊天宝库。','[翰林院]\x20创建优先查询组:\x20','[翰林院-日志]\x20清空宝库API错误:','depth','\x20(范围:\x20','正在处理\x20','clearJob','知识库名称不能为空。','log','task_','info','1329952QoRweI','batchSize','position','local','操作已取消。','\x27,使用通用分块逻辑。','第1卷','messageTypes','initialized','[翰林院-迁移]\x20用户确认迁移,正在处理旧宝库:\x20','未知角色','/api/vector/query','118995qZMiKu','startsWith','未知条目','forEach','20QokdaF','[翰林院-日志]\x20获取集合\x20','map','[翰林院]\x20常规池处理完毕,产出\x20','HANLINYUAN_RAG_MANUAL','oldId','[翰林院]\x20最终无可用结果,注入中止。','微言录总结','bookName','知识库【','random','\x20个知识块,准备入库。','[翰林院-核心]\x20清空向量集合\x20','warn','source','range','[翰林院-日志]\x20添加\x20','max','忆识存入API错误\x20','[翰林院-核心]\x20聊天记录凝识完成,成功插入\x20','\x20不存在,计为\x200。','abs','toLowerCase','[翰林院-日志]\x20发送到\x20/api/vector/purge\x20的请求体:','maxResults','宏史卷总结','[翰林院-Rerank]\x20外部Rerank失败,将仅使用内部加权。','min','小说:\x20','[翰林院-日志]\x20开始获取所有知识库的向量总数...','saveSettingsDebounced','condensationHistory','saveProgress','start','\x22\x20创建专属知识库...','[翰林院-日志]\x20查询知识库\x20','key','exclusionRules','[翰林院-日志]\x20开始清空宝库...','rerank','\x27\x20的注入设置,跳过处理。','\x20添加新知识库:\x20','all','tiaomu','floor','getContext','[翰林院-修复]\x20最终返回数组长度:\x20','\x22,将数据合并入库。','replace','match','6PbCqBr','injection_','对话记录小总结','[翰林院-日志]\x20统计集合\x20','object','queryMessageCount','status',']\x20的消息已成功凝识。','[翰林院-迁移]\x20用户取消了迁移操作。','[翰林院]\x20常规组返回\x20','[翰林院-核心]\x20尝试删除一个不存在的知识库:\x20','[翰林院-核心]\x20准备为任务\x20\x22','[翰林院-核心]\x20准备删除知识库\x20','comment','检测到旧版数据,正在进行一次性户口普查...','_history','[翰林院-核心]\x20已将\x20','manual','end','embeddings','[翰林院]\x20优先组\x20','[翰林院-配置]\x20为旧版知识库\x20','_text}}',')\x20的状态已切换为:\x20','\x20个条目。','split','includes','quiet','\x20返回\x20','\x27\x20中未找到ID为\x20','hasOwnProperty','data','[翰林院-预处理]\x20原始检索文本:\x20\x22','[翰林院-日志]\x20未能为知识库\x20','[翰林院-预处理]\x20处理后检索文本:\x20\x22','查询集合\x20','length','getTime','未分类世界书',',\x20第1卷,\x20第1章,\x20第','sort','),开始强制重分类所有知识库...','[翰林院-迁移]\x20集合\x20','[翰林院]\x20开始处理常规池...','notify','vector','无法确定要清空的目标宝库。','正在智能分块...','\x20-\x20楼层\x20#','旧版宝库\x20(Legacy)','\x22\x20已删除。','未能生成查询向量。','filter','\x20条内容。','知识库\x20\x22','newId','global','知识库名称不能为空','knowledgeBases','getRequestHeaders','世界书条目','输入文本为空','[翰林院-Rerank]\x20开始外部API重排序...','\x20(集合ID:\x20','advanced','novel','手动录入','[翰林院]\x20创建常规查询组\x20(',',将清空集合:\x20','[翰林院-日志]\x20所有知识库统计完成,总向量数:\x20','[翰林院-核心]\x20已锁定忆识宝库ID:\x20','json','[翰林院-日志]\x20开始向量查询...\x20(目标:\x20','results','830690EuPakq','[翰林院-日志]\x20无法确定要清空的目标集合ID。','在作用域\x20\x27','[翰林院-核心]\x20processCondensation\x20失败:','[翰林院-核心]\x20已为角色\x20',',\x20条目:\x20','\x20的向量总数:\x20','\x20及其向量数据。','mes','第1章','14vzNSzC','entryName','rearrangeChat','trim','has','1871406lBICTW','重命名失败:未找到知识库条目。','/api/vector/list','\x27的文本分割成\x20','\x20记录凝识范围:\x20','user','superSortEnabled','\x20条消息分解为\x20','/api/vector/purge','540008wlwjQP','webllm','aborted','\x0a{const _0x166dc0=_0xb8bc3a;return _0x56f619[_0x166dc0(0x286)]()[_0x166dc0(0x2bc)](_0x343394)||containsPinyinMatch(_0x56f619,_0x343394);});}function filterWorldbookEntries(_0x56df26,_0x54996a){const _0x37488f=_0x1b9b83;if(!_0x56df26||!_0x56df26['trim']())return _0x54996a;const _0x1b59bc=_0x56df26[_0x37488f(0x286)]()[_0x37488f(0x2f9)]();return _0x54996a['filter'](_0x126c26=>{const _0x5ad8b3=_0x37488f,_0x48a9a8=[_0x126c26['comment']||'',_0x126c26[_0x5ad8b3(0x294)]||'',_0x126c26['content']||''][_0x5ad8b3(0x206)]('\x20')['toLowerCase']();return _0x48a9a8['includes'](_0x1b59bc)||containsPinyinMatch(_0x126c26[_0x5ad8b3(0x2af)]||'',_0x1b59bc);});}function containsPinyinMatch(_0x28b283,_0x1f8378){const _0x571320=_0x1b9b83,_0x3bf41b={'世界书':'sjshu','条目':_0x571320(0x29b),'编纂':_0x571320(0x246),'搜索':_0x571320(0x225)},_0x46d35e=_0x3bf41b[_0x28b283];return _0x46d35e&&_0x46d35e[_0x571320(0x2bc)](_0x1f8378);}function highlightSearchMatch(_0x125485,_0x27e3df){const _0x205032=_0x1b9b83;if(!_0x27e3df||!_0x27e3df[_0x205032(0x2f9)]())return _0x125485;const _0x170cc0=new RegExp('('+_0x27e3df[_0x205032(0x2a0)](/[.*+?^${}()|[\]\\]/g,_0x205032(0x254))+')','gi');return _0x125485[_0x205032(0x2a0)](_0x170cc0,_0x205032(0x21d));}function _0x3f8a(_0x167646,_0x55d937){const _0x748139=_0x7481();return _0x3f8a=function(_0x3f8aa8,_0x22de2b){_0x3f8aa8=_0x3f8aa8-0x1ed;let _0x51c572=_0x748139[_0x3f8aa8];return _0x51c572;},_0x3f8a(_0x167646,_0x55d937);}function debounce(_0x4a8276,_0x5aef79){let _0x273690;return function _0x5b16fe(..._0x57144d){const _0x510a60=()=>{clearTimeout(_0x273690),_0x4a8276(..._0x57144d);};clearTimeout(_0x273690),_0x273690=setTimeout(_0x510a60,_0x5aef79);};}export{initialize,getSettings,saveSettings,resetSettings,_0x5c5f1d as testApiConnection,_0x1ca542 as fetchEmbeddingModels,_0x2e4363 as fetchRerankModels,getVectorCount,purgeStorage,getMessagesForCondensation,processCondensation,ingestTextToHanlinyuan,getCollectionId,toggleSessionLock,isSessionLocked,getLockedSessionInfo,addKnowledgeBase,removeKnowledgeBase,getLocalKnowledgeBases,getGlobalKnowledgeBases,toggleKnowledgeBase,moveKnowledgeBase,filterWorldbooks,filterWorldbookEntries,highlightSearchMatch,debounce,renameKnowledgeBase};function initialize(){const _0x347410=_0x1b9b83;context=SillyTavern[_0x347410(0x29d)]();if(!context){console[_0x347410(0x325)]('[翰林院]\x20未能获取SillyTavern上下文,初始化失败。');return;}settings=getSettings(),!window['hanlinyuanRagProcessor']&&(window[_0x347410(0x31f)]={}),window['hanlinyuanRagProcessor'][_0x347410(0x2f8)]=rearrangeChat,window[_0x347410(0x31f)][_0x347410(0x268)]=!![],console[_0x347410(0x25d)](_0x347410(0x1fb));}async function ingestTextToHanlinyuan(_0x62fcd6,_0x3b4031=_0x1b9b83(0x2b3),_0x1e7154={},_0x41d20f=()=>{},_0x3a2583=null,_0x5cd49e=()=>{},_0x48b6a4=()=>{},_0x1d4b3c=null,_0x5e4618=0x0){const _0xf0f773=_0x1b9b83;if(!_0x62fcd6||!_0x62fcd6[_0xf0f773(0x2f9)]())return{'success':![],'error':_0xf0f773(0x2df)};if(!settings)return{'success':![],'error':'核心未初始化'};try{const _0x4439a2=getCollectionIdInfo(),_0x4402c0=await _0x33e1dc();if(_0x4439a2[_0xf0f773(0x275)]&&_0x4439a2['oldId']===_0x4402c0&&_0x4439a2['oldId']!==_0x4439a2[_0xf0f773(0x2d9)]){const _0x16523d=confirm('检测到旧版数据。此操作将把旧数据迁移到新格式,过程不可逆,是否继续?');if(_0x16523d)_0x5cd49e(_0xf0f773(0x269)+_0x4439a2[_0xf0f773(0x275)],_0xf0f773(0x27d)),await purgeStorage(_0x4439a2[_0xf0f773(0x275)]),_0x5cd49e(_0xf0f773(0x204),_0xf0f773(0x31a));else return _0x5cd49e(_0xf0f773(0x2aa),_0xf0f773(0x25f)),toastr['info'](_0xf0f773(0x264)),{'success':![],'error':_0xf0f773(0x248)};}let _0x116e64,_0x2bcb2c;const _0x5b1854=new Date()[_0xf0f773(0x253)](_0xf0f773(0x236),{'hour12':![]}),_0xe4837=getCharacterName()||_0xf0f773(0x26a);switch(_0x3b4031){case _0xf0f773(0x215):const _0x4e597e=_0x1e7154[_0xf0f773(0x27f)]||{},_0x1972be=_0x4e597e['start']??'?',_0x588227=_0x4e597e[_0xf0f773(0x2b4)]===0x0?'末':_0x4e597e['end']??'?';_0x116e64=_0xe4837+':\x20'+_0x1972be+'楼-'+_0x588227+'楼';break;case _0xf0f773(0x24b):const _0x1a41bc=_0x1e7154['bookName']||_0xf0f773(0x2c8);if(_0x1e7154[_0xf0f773(0x2f7)]&&_0x1e7154[_0xf0f773(0x2f7)][_0xf0f773(0x2bc)](_0xf0f773(0x277)))_0x1e7154[_0xf0f773(0x2f7)]=_0xf0f773(0x2a4);else _0x1e7154[_0xf0f773(0x2f7)]&&_0x1e7154[_0xf0f773(0x2f7)]['includes'](_0xf0f773(0x289))&&(_0x1e7154[_0xf0f773(0x2f7)]=_0xf0f773(0x1f5));const _0x1c17aa=_0x1e7154[_0xf0f773(0x2f7)]||_0xf0f773(0x26e);_0x116e64=_0x1a41bc+':\x20'+_0x1c17aa;break;case _0xf0f773(0x2e3):_0x116e64=_0xf0f773(0x28c)+(_0x1e7154[_0xf0f773(0x314)]||'未知小说');break;case _0xf0f773(0x2b3):default:_0x116e64='手动录入:\x20'+_0x5b1854;break;}const _0x1e0f95=Object[_0xf0f773(0x208)](getKnowledgeBases()),_0x37232c=_0x1e0f95[_0xf0f773(0x252)](_0x4018e9=>_0x4018e9[_0xf0f773(0x309)]===_0x116e64);if(_0x37232c)_0x2bcb2c=_0x37232c['id'],_0x5cd49e(_0xf0f773(0x210)+_0x116e64+_0xf0f773(0x29f),_0xf0f773(0x25f));else{_0x5cd49e(_0xf0f773(0x2ad)+_0x116e64+'\x22\x20创建专属知识库...',_0xf0f773(0x25f));const _0x517b9d=addKnowledgeBase(_0x116e64,_0x3b4031);_0x2bcb2c=_0x517b9d['id'];}const _0x3239e7=getCharacterStableId(),_0x3f76e0=_0x3239e7+'_'+_0x2bcb2c;_0x5cd49e('[翰林院-核心]\x20已创建并锁定知识库:\x20'+_0x116e64+_0xf0f773(0x2e1)+_0x3f76e0+')',_0xf0f773(0x31a)),_0x5cd49e(_0xf0f773(0x2e8)+_0x3f76e0,'info'),_0x41d20f({'message':_0xf0f773(0x2d1),'processed':0x0,'total':0x1});const _0x1ddc72=splitIntoChunks(_0x62fcd6,_0x3b4031,_0x1e7154),_0x4ced4a=_0x1ddc72['length'];if(_0x3a2583?.[_0xf0f773(0x306)])throw new Error('AbortError');_0x5cd49e('[翰林院-核心]\x20将来源\x27'+_0x116e64+_0xf0f773(0x2fe)+_0x4ced4a+_0xf0f773(0x30f),_0xf0f773(0x25f));if(_0x4ced4a===0x0)return{'success':!![],'count':0x0};const _0x3db141=settings[_0xf0f773(0x23b)][_0xf0f773(0x261)]||0x5;let _0x6715e1=_0x5e4618;for(let _0x421a26=_0x5e4618;_0x421a26<_0x4ced4a;_0x421a26+=_0x3db141){if(_0x3a2583?.[_0xf0f773(0x306)])throw new Error(_0xf0f773(0x22e));const _0x4f13ef=_0x1ddc72[_0xf0f773(0x238)](_0x421a26,_0x421a26+_0x3db141);_0x41d20f({'message':_0xf0f773(0x25a)+(_0x421a26+0x1)+'-'+(_0x421a26+_0x4f13ef['length'])+'\x20块','processed':_0x421a26,'total':_0x4ced4a});const _0x2d1bbe=_0x4f13ef[_0xf0f773(0x272)](_0x42c875=>_0x42c875[_0xf0f773(0x230)]),_0x4c8123=await getEmbeddings(_0x2d1bbe,_0x3a2583);if(_0x3a2583?.[_0xf0f773(0x306)])throw new Error('AbortError');if(_0x4f13ef[_0xf0f773(0x2c6)]!==_0x4c8123['length'])throw new Error(_0xf0f773(0x222));const _0x3d3d10=_0x4f13ef[_0xf0f773(0x272)]((_0x2e1067,_0x2f2213)=>({..._0x2e1067,'vector':_0x4c8123[_0x2f2213]}));await insertVectors(_0x3d3d10,_0x3a2583,_0x3f76e0),_0x6715e1+=_0x4f13ef['length'],_0x1d4b3c&&_0x3ebb05[_0xf0f773(0x290)](_0x1d4b3c,_0x6715e1,_0x4ced4a),await _0x48b6a4();}return _0x1d4b3c&&_0x3ebb05[_0xf0f773(0x25b)](_0x1d4b3c),_0x5cd49e('[翰林院-核心]\x20成功插入\x20'+_0x6715e1+_0xf0f773(0x22b),_0xf0f773(0x31a)),{'success':!![],'count':_0x6715e1};}catch(_0x3ca1ff){if(_0x3ca1ff[_0xf0f773(0x309)]===_0xf0f773(0x22e)){_0x5cd49e(_0xf0f773(0x20c),_0xf0f773(0x27d));throw _0x3ca1ff;}return console[_0xf0f773(0x325)](_0xf0f773(0x312),_0x3ca1ff),_0x5cd49e(_0xf0f773(0x20a)+_0x3ca1ff[_0xf0f773(0x226)],'error'),{'success':![],'error':_0x3ca1ff[_0xf0f773(0x226)]};}}function getSettings(){const _0x3257dc=_0x1b9b83;if(!context||!context['extensionSettings'])return structuredClone(_0x584004);let _0x2424b7=context[_0x3257dc(0x319)][MODULE_NAME];!_0x2424b7&&(_0x2424b7={},context[_0x3257dc(0x319)][MODULE_NAME]=_0x2424b7);_0x2424b7[_0x3257dc(0x28f)]===undefined&&(_0x2424b7['condensationHistory']={});_0x2424b7['knowledgeBases']===undefined&&(_0x2424b7[_0x3257dc(0x2dc)]={});_0x2424b7[_0x3257dc(0x21e)]===undefined&&(_0x2424b7[_0x3257dc(0x21e)]={'enabled':![],'tagExtractionEnabled':![],'tags':'content,details,摘要','exclusionRules':[]});for(const _0x5503c2 in _0x584004){if(_0x2424b7[_0x5503c2]===undefined)_0x2424b7[_0x5503c2]=structuredClone(_0x584004[_0x5503c2]);else{if(typeof _0x584004[_0x5503c2]===_0x3257dc(0x2a6)&&!Array[_0x3257dc(0x23f)](_0x584004[_0x5503c2])&&_0x584004[_0x5503c2]!==null)for(const _0x54fe2f in _0x584004[_0x5503c2]){_0x2424b7[_0x5503c2][_0x54fe2f]===undefined&&(_0x2424b7[_0x5503c2][_0x54fe2f]=_0x584004[_0x5503c2][_0x54fe2f]);}}}return _0x2424b7;}function saveSettings(){const _0x55f3c4=_0x1b9b83;if(context)context[_0x55f3c4(0x28e)]();}function resetSettings(){const _0x282815=_0x1b9b83;context&&(context[_0x282815(0x319)][MODULE_NAME]=structuredClone(_0x584004),saveSettings());}function showNotification(_0x149bc0,_0x569634='info'){toastr[_0x569634](_0x149bc0);}function getTagForSource(_0x54110d){const _0x5dc775=_0x1b9b83;switch(_0x54110d){case _0x5dc775(0x215):return'聊天记录';case'lorebook':return _0x5dc775(0x245);case'manual':return'手动录入';case _0x5dc775(0x2e3):return'小说录入';default:return'资料';}}function splitIntoChunks(_0x4d87f1,_0x5ac227,_0x94d6cb={}){const _0x5074a8=_0x1b9b83;switch(_0x5ac227){case'novel':return _chunkForNovel(_0x4d87f1,_0x94d6cb);case'chat_history':return _chunkForChatHistory(_0x4d87f1,_0x94d6cb);case'lorebook':return _chunkForLorebook(_0x4d87f1,_0x94d6cb);case'manual':return _chunkForManual(_0x4d87f1,_0x94d6cb);default:console['warn'](_0x5074a8(0x200)+_0x5ac227+_0x5074a8(0x265));return _chunkForManual(_0x4d87f1,{..._0x94d6cb,'sourceName':_0x94d6cb['sourceName']||'未知来源'});}}function _chunkForNovel(_0x344f4e,_0x4d249f){const _0x41b3a0=_0x1b9b83,{chunkSize:_0x357bf1,overlap:_0x59fb01}=settings[_0x41b3a0(0x2e2)],{sourceName:sourceName='小说'}=_0x4d249f,_0x164e6e=[];if(!_0x344f4e||_0x357bf1<=0x0)return _0x164e6e;const _0x27a776=/(第\s*[一二三四五六七八九十百千万零\d]+\s*卷)/gim,_0x19290d=/(第\s*[一二三四五六七八九十百千万零\d]+\s*[章回节部])|^(Chapter\s+\d+)/gim;let _0x4f56d2=0x0;const _0x50a1db=_0x344f4e['split']('\x0a');let _0x2b8aad=_0x41b3a0(0x266),_0x573c15='第1章',_0x444893=[];function _0x54779c(){const _0x4d4dc9=_0x41b3a0;if(_0x444893[_0x4d4dc9(0x2c6)]===0x0)return;const _0x6ec278=_0x444893[_0x4d4dc9(0x206)]('\x0a');let _0x1b34f4=0x0,_0x563d13=0x1;while(_0x1b34f4<_0x6ec278[_0x4d4dc9(0x2c6)]){const _0x39762=Math[_0x4d4dc9(0x28b)](_0x1b34f4+_0x357bf1,_0x6ec278[_0x4d4dc9(0x2c6)]),_0x52c0a6=_0x6ec278[_0x4d4dc9(0x321)](_0x1b34f4,_0x39762);if(_0x52c0a6['trim']()[_0x4d4dc9(0x2c6)]>0x0){const _0x36ebfc={'source':_0x4d4dc9(0x2e3),'sourceName':sourceName,'timestamp':new Date()['toISOString'](),'globalIndex':_0x4f56d2++,'volume':_0x2b8aad,'chapter':_0x573c15,'section':_0x563d13},_0x13e2f9=getTagForSource(_0x4d4dc9(0x2e3)),_0x3967ce=_0x4d4dc9(0x324)+sourceName+',\x20'+_0x2b8aad+',\x20'+_0x573c15+_0x4d4dc9(0x244)+_0x563d13+'节]',_0x23a854='<'+_0x13e2f9+'>\x0a'+_0x3967ce+'\x0a'+_0x52c0a6+_0x4d4dc9(0x307)+_0x13e2f9+'>';_0x164e6e[_0x4d4dc9(0x1f3)]({'text':_0x23a854,'metadata':_0x36ebfc}),_0x563d13++;}_0x1b34f4+=_0x357bf1-_0x59fb01;if(_0x1b34f4>=_0x6ec278[_0x4d4dc9(0x2c6)])break;}_0x444893=[];}for(const _0x525d4f of _0x50a1db){const _0x4eb88d=_0x525d4f['trim']();if(_0x27a776['test'](_0x4eb88d))_0x54779c(),_0x2b8aad=_0x4eb88d,_0x573c15=_0x41b3a0(0x2f5);else _0x19290d['test'](_0x4eb88d)?(_0x54779c(),_0x573c15=_0x4eb88d):_0x444893[_0x41b3a0(0x1f3)](_0x525d4f);}_0x54779c();if(_0x164e6e[_0x41b3a0(0x2c6)]===0x0&&_0x344f4e['length']>0x0){let _0x432d1d=0x0,_0x3d2563=0x1;while(_0x432d1d<_0x344f4e[_0x41b3a0(0x2c6)]){const _0x17c50b=Math[_0x41b3a0(0x28b)](_0x432d1d+_0x357bf1,_0x344f4e['length']),_0x377b68=_0x344f4e[_0x41b3a0(0x321)](_0x432d1d,_0x17c50b),_0x4a85c9={'source':_0x41b3a0(0x2e3),'sourceName':sourceName,'timestamp':new Date()['toISOString'](),'globalIndex':_0x164e6e[_0x41b3a0(0x2c6)],'volume':_0x41b3a0(0x266),'chapter':_0x41b3a0(0x2f5),'section':_0x3d2563},_0x546c6a=getTagForSource('novel'),_0xdaa32d=_0x41b3a0(0x324)+sourceName+_0x41b3a0(0x2c9)+_0x3d2563+'节]',_0x29e46b='<'+_0x546c6a+'>\x0a'+_0xdaa32d+'\x0a'+_0x377b68+_0x41b3a0(0x307)+_0x546c6a+'>';_0x164e6e['push']({'text':_0x29e46b,'metadata':_0x4a85c9}),_0x3d2563++,_0x432d1d+=_0x357bf1-_0x59fb01;}}return _0x164e6e;}function _chunkForChatHistory(_0x11282a,_0x54fbb3){const _0x8bcd40=_0x1b9b83,{chunkSize:_0x216a1d,overlap:_0x1959ea}=settings[_0x8bcd40(0x2e2)],{floor:_0x331238,is_user:_0x13fc72,timestamp:_0x3e925b}=_0x54fbb3,_0x5b8a02=[];if(!_0x11282a||_0x216a1d<=0x0)return _0x5b8a02;let _0x3a6a57=0x1,_0x360422=0x0;while(_0x360422<_0x11282a[_0x8bcd40(0x2c6)]){const _0xfde49f=Math[_0x8bcd40(0x28b)](_0x360422+_0x216a1d,_0x11282a['length']),_0x4a3b2d=_0x11282a['substring'](_0x360422,_0xfde49f),_0x17bf14=_0x8bcd40(0x1f7)+_0x331238+_0x8bcd40(0x244)+_0x3a6a57+_0x8bcd40(0x30a),_0x13e4c2=getTagForSource('chat_history'),_0x41764a='<'+_0x13e4c2+'>\x0a'+_0x17bf14+'\x0a'+_0x4a3b2d+_0x8bcd40(0x307)+_0x13e4c2+'>';_0x5b8a02[_0x8bcd40(0x1f3)]({'text':_0x41764a,'metadata':{'source':_0x8bcd40(0x215),'sourceName':'聊天记录\x20#'+_0x331238,'floor':_0x331238,'part':_0x3a6a57,'is_user':_0x13fc72,'timestamp':_0x3e925b}}),_0x3a6a57++,_0x360422+=_0x216a1d-_0x1959ea;if(_0x360422>=_0x11282a[_0x8bcd40(0x2c6)])break;}return _0x5b8a02;}function _chunkForLorebook(_0x9054de,_0x5b4823){const _0x37195a=_0x1b9b83,{chunkSize:_0x221df0,overlap:_0x3bd45f}=settings['advanced'],{bookName:bookName=_0x37195a(0x245),entryName:entryName=_0x37195a(0x2de)}=_0x5b4823,_0x42c29d=[];if(!_0x9054de||_0x221df0<=0x0)return _0x42c29d;let _0x3ed1cd=0x1,_0x4d7bda=0x0;while(_0x4d7bda<_0x9054de[_0x37195a(0x2c6)]){const _0x518e4e=Math[_0x37195a(0x28b)](_0x4d7bda+_0x221df0,_0x9054de[_0x37195a(0x2c6)]),_0x56e951=_0x9054de[_0x37195a(0x321)](_0x4d7bda,_0x518e4e),_0x49ea92=_0x37195a(0x324)+bookName+_0x37195a(0x2f1)+entryName+_0x37195a(0x244)+_0x3ed1cd+_0x37195a(0x30a),_0x76daec=getTagForSource(_0x37195a(0x24b)),_0x1f1385='<'+_0x76daec+'>\x0a'+_0x49ea92+'\x0a'+_0x56e951+_0x37195a(0x307)+_0x76daec+'>';_0x42c29d['push']({'text':_0x1f1385,'metadata':{'source':'lorebook','sourceName':bookName+':\x20'+entryName,'bookName':bookName,'entryName':entryName,'part':_0x3ed1cd,'timestamp':new Date()[_0x37195a(0x24a)]()}}),_0x3ed1cd++,_0x4d7bda+=_0x221df0-_0x3bd45f;if(_0x4d7bda>=_0x9054de[_0x37195a(0x2c6)])break;}return _0x42c29d;}function _chunkForManual(_0x25f125,_0x597ec6){const _0x12175c=_0x1b9b83,{chunkSize:_0x669ac9,overlap:_0x49e587}=settings[_0x12175c(0x2e2)],{sourceName:sourceName=_0x12175c(0x2e4)}=_0x597ec6,_0x3be22f=[];if(!_0x25f125||_0x669ac9<=0x0)return _0x3be22f;const _0x196110=new Date(),_0x1972b5=_0x196110[_0x12175c(0x253)]('zh-CN');let _0x56a667=0x1,_0x444a8f=0x0;while(_0x444a8f<_0x25f125[_0x12175c(0x2c6)]){const _0x142788=Math[_0x12175c(0x28b)](_0x444a8f+_0x669ac9,_0x25f125[_0x12175c(0x2c6)]),_0x444fc0=_0x25f125[_0x12175c(0x321)](_0x444a8f,_0x142788),_0x18a992=_0x12175c(0x324)+sourceName+_0x12175c(0x23e)+_0x1972b5+_0x12175c(0x244)+_0x56a667+'部分]',_0x4dbbed=getTagForSource(_0x12175c(0x2b3)),_0x469f14='<'+_0x4dbbed+'>\x0a'+_0x18a992+'\x0a'+_0x444fc0+'\x0a';_0x3be22f[_0x12175c(0x1f3)]({'text':_0x469f14,'metadata':{'source':_0x12175c(0x2b3),'sourceName':sourceName,'part':_0x56a667,'timestamp':_0x196110[_0x12175c(0x24a)]()}}),_0x56a667++,_0x444a8f+=_0x669ac9-_0x49e587;if(_0x444a8f>=_0x25f125[_0x12175c(0x2c6)])break;}return _0x3be22f;}import{getCollectionId as _0x33e1dc,getCharacterName,getChatId}from'./utils/context-utils.js';async function getCollectionId(){const _0x231b92=_0x1b9b83;if(lockedCollectionId)return lockedCollectionId;const _0x43eda9=settings['retrieval'][_0x231b92(0x223)];return _0x43eda9?getChatId():await _0x33e1dc();}async function toggleSessionLock(){return lockedCollectionId?(lockedCollectionId=null,![]):(lockedCollectionId=await _0x33e1dc(),!![]);}function isSessionLocked(){return lockedCollectionId!==null;}function getLockedSessionInfo(){const _0x1bbc96=_0x1b9b83;if(!lockedCollectionId)return null;return{'id':lockedCollectionId,'name':_0x1bbc96(0x22d)+lockedCollectionId[_0x1bbc96(0x321)](0x0,0x8)+'...)'};}function getLocalKnowledgeBases(){const _0x1a3b1e=_0x1b9b83,_0x33dd6c=getCharacterStableId();return!settings['knowledgeBases'][_0x33dd6c]&&(settings[_0x1a3b1e(0x2dc)][_0x33dd6c]={}),settings[_0x1a3b1e(0x2dc)][_0x33dd6c];}function getGlobalKnowledgeBases(){const _0x191758=_0x1b9b83;return!settings[_0x191758(0x2dc)][GLOBAL_SCOPE_ID]&&(settings[_0x191758(0x2dc)][GLOBAL_SCOPE_ID]={}),settings[_0x191758(0x2dc)][GLOBAL_SCOPE_ID];}function getKnowledgeBases(){const _0x596f68=getLocalKnowledgeBases(),_0x2b3b4f=getGlobalKnowledgeBases();return{..._0x2b3b4f,..._0x596f68};}function addKnowledgeBase(_0x496691,_0xcfd421=_0x1b9b83(0x2b3)){const _0x3d5f55=_0x1b9b83;if(!_0x496691||!_0x496691[_0x3d5f55(0x2f9)]())throw new Error(_0x3d5f55(0x2db));const _0x3545f7=getCharacterStableId(),_0x12a384=getLocalKnowledgeBases(),_0x4c135c=_0x3d5f55(0x25e)+Date[_0x3d5f55(0x308)]()+'_'+Math[_0x3d5f55(0x27a)]()[_0x3d5f55(0x251)](0x24)['substring'](0x2,0x9),_0x1ec54d={'id':_0x4c135c,'name':_0x496691[_0x3d5f55(0x2f9)](),'enabled':!![],'createdAt':new Date()[_0x3d5f55(0x24a)](),'owner':_0x3545f7,'source':_0xcfd421};return _0x12a384[_0x4c135c]=_0x1ec54d,saveSettings(),console['log'](_0x3d5f55(0x2f0)+_0x3545f7+_0x3d5f55(0x299)+_0x496691+'\x20(ID:\x20'+_0x4c135c+')'),_0x1ec54d;}async function removeKnowledgeBase(_0x22bf6a,_0x455b51){const _0x562f68=_0x1b9b83,_0x45e7a7=getCharacterStableId(),_0xbe7173=_0x455b51===_0x562f68(0x2da)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0xd235f9=_0xbe7173[_0x22bf6a],_0x444f76=_0xd235f9?.[_0x562f68(0x309)]||_0x22bf6a;if(!_0xd235f9){console[_0x562f68(0x27d)](_0x562f68(0x2ac)+_0x22bf6a+_0x562f68(0x259)+_0x455b51+')');return;}const _0x9aee4b=_0x455b51==='global'?_0xd235f9[_0x562f68(0x241)]||GLOBAL_SCOPE_ID:_0x45e7a7,_0xc3242c=_0x9aee4b+'_'+_0x22bf6a;console[_0x562f68(0x25d)](_0x562f68(0x2ae)+_0x22bf6a+_0x562f68(0x2e6)+_0xc3242c);const _0x80e4c4=await purgeStorage(_0xc3242c);_0x80e4c4?(delete _0xbe7173[_0x22bf6a],saveSettings(),console[_0x562f68(0x25d)](_0x562f68(0x30d)+_0x22bf6a+_0x562f68(0x2f3)),toastr[_0x562f68(0x31a)](_0x562f68(0x2d8)+_0x444f76+_0x562f68(0x2d4))):(console['error'](_0x562f68(0x27c)+_0xc3242c+_0x562f68(0x1ef)),toastr[_0x562f68(0x325)](_0x562f68(0x1ff)));}function toggleKnowledgeBase(_0x9b7b71,_0x19c75a){const _0x4dec0d=_0x1b9b83,_0x54a8fd=_0x19c75a===_0x4dec0d(0x2da)?getGlobalKnowledgeBases():getLocalKnowledgeBases();_0x54a8fd[_0x9b7b71]&&(_0x54a8fd[_0x9b7b71]['enabled']=!_0x54a8fd[_0x9b7b71][_0x4dec0d(0x22c)],saveSettings(),console['log'](_0x4dec0d(0x315)+_0x9b7b71+_0x4dec0d(0x259)+_0x19c75a+_0x4dec0d(0x2b9)+(_0x54a8fd[_0x9b7b71]['enabled']?'启用':'禁用')));}function generateHash(_0x51685c){const _0x2f30d2=_0x1b9b83;let _0x4a599b=0x0;for(let _0x149eb4=0x0;_0x149eb4<_0x51685c[_0x2f30d2(0x2c6)];_0x149eb4++){const _0x27762e=_0x51685c['charCodeAt'](_0x149eb4);_0x4a599b=(_0x4a599b<<0x5)-_0x4a599b+_0x27762e,_0x4a599b=_0x4a599b&_0x4a599b;}return Math[_0x2f30d2(0x285)](_0x4a599b)[_0x2f30d2(0x251)](0x24);}async function queryVectors(_0x40c5eb,_0x4ba096={}){const _0x265d5a=_0x1b9b83,{includeBases:includeBases=null}=_0x4ba096;let _0x8c4480=[];console[_0x265d5a(0x25d)](_0x265d5a(0x2ea)+(includeBases?_0x265d5a(0x207):'所有启用库')+')');if(includeBases)_0x8c4480=includeBases,console[_0x265d5a(0x25d)](_0x265d5a(0x224)+_0x8c4480['length']+_0x265d5a(0x240));else{if(settings[_0x265d5a(0x23b)][_0x265d5a(0x223)]){console['log'](_0x265d5a(0x24e));const _0x4f2ad6=getChatId();_0x4f2ad6?(console[_0x265d5a(0x25d)]('[翰林院-日志]\x20添加当前聊天宝库:\x20'+_0x4f2ad6),_0x8c4480['push']({'id':_0x4f2ad6,'name':_0x265d5a(0x21b)+_0x4f2ad6+')','scope':_0x265d5a(0x234)})):console['warn'](_0x265d5a(0x255));const _0x536a26=getGlobalKnowledgeBases(),_0x4f6170=Object[_0x265d5a(0x208)](_0x536a26)[_0x265d5a(0x2d6)](_0x42228c=>_0x42228c[_0x265d5a(0x22c)]);_0x4f6170[_0x265d5a(0x2c6)]>0x0&&(console[_0x265d5a(0x25d)](_0x265d5a(0x280)+_0x4f6170[_0x265d5a(0x2c6)]+'\x20个已启用的全局知识库。'),_0x8c4480[_0x265d5a(0x1f3)](..._0x4f6170[_0x265d5a(0x272)](_0x57042a=>({..._0x57042a,'scope':_0x265d5a(0x2da)}))));}else{console[_0x265d5a(0x25d)](_0x265d5a(0x316));const _0x213a91=getLocalKnowledgeBases(),_0x422147=getGlobalKnowledgeBases(),_0x2e8c1c=Object[_0x265d5a(0x208)](_0x213a91)['filter'](_0x4c3d94=>_0x4c3d94['enabled']),_0x108dd0=Object[_0x265d5a(0x208)](_0x422147)['filter'](_0x2b7bdf=>_0x2b7bdf['enabled']);_0x8c4480[_0x265d5a(0x1f3)](..._0x2e8c1c['map'](_0x2c8217=>({..._0x2c8217,'scope':_0x265d5a(0x263)}))),_0x8c4480[_0x265d5a(0x1f3)](..._0x108dd0['map'](_0x9d9da7=>({..._0x9d9da7,'scope':_0x265d5a(0x2da)})));if(_0x8c4480[_0x265d5a(0x2c6)]===0x0){console['log'](_0x265d5a(0x214));const _0x2ca9aa=await _0x33e1dc();_0x2ca9aa&&_0x8c4480[_0x265d5a(0x1f3)]({'id':null,'name':_0x265d5a(0x2d3),'scope':_0x265d5a(0x1fd)});}}}if(_0x8c4480[_0x265d5a(0x2c6)]===0x0)return console[_0x265d5a(0x25d)]('[翰林院-日志]\x20没有可供查询的知识库,查询中止。'),[];const _0x254933=(await getEmbeddings([_0x40c5eb]))[0x0];if(!_0x254933)throw new Error(_0x265d5a(0x2d5));const _0x290cb7=_0x8c4480[_0x265d5a(0x272)](_0x58bffa=>_executeQueryForBase(_0x58bffa,_0x40c5eb,_0x254933)),_0x232b46=await Promise[_0x265d5a(0x29a)](_0x290cb7);let _0x16be22=_0x232b46['flat']();console[_0x265d5a(0x25d)](_0x265d5a(0x219)+_0x16be22[_0x265d5a(0x2c6)]+_0x265d5a(0x1f6));const _0x2beddf=[],_0x2129a1=new Set();for(const _0x15bfe7 of _0x16be22){if(_0x15bfe7&&typeof _0x15bfe7===_0x265d5a(0x2a6)&&_0x15bfe7['text']&&typeof _0x15bfe7[_0x265d5a(0x230)]===_0x265d5a(0x242)){const _0x59b3bb=_0x15bfe7[_0x265d5a(0x230)]['trim']();_0x59b3bb['length']>0x0&&!_0x2129a1[_0x265d5a(0x2fa)](_0x59b3bb)&&(_0x2129a1[_0x265d5a(0x326)](_0x59b3bb),_0x2beddf[_0x265d5a(0x1f3)](_0x15bfe7));}}console[_0x265d5a(0x25d)](_0x265d5a(0x216)+_0x2beddf[_0x265d5a(0x2c6)]+_0x265d5a(0x30c)),_0x2beddf[_0x265d5a(0x2ca)]((_0x1e6097,_0x238e39)=>(_0x238e39[_0x265d5a(0x20e)]||0x0)-(_0x1e6097[_0x265d5a(0x20e)]||0x0));const _0xf69f8f=[..._0x2beddf];return console[_0x265d5a(0x25d)](_0x265d5a(0x29e)+_0xf69f8f['length']),console[_0x265d5a(0x25d)](_0x265d5a(0x320),JSON['stringify'](_0xf69f8f[_0x265d5a(0x238)](0x0,0x1),null,0x2)),_0xf69f8f;}async function _executeQueryForBase(_0x232d2d,_0x4e0bc4,_0x50c327=null){const _0x9cdbbb=_0x1b9b83,_0x1214c2=getCharacterStableId();let _0xb563f;switch(_0x232d2d[_0x9cdbbb(0x313)]){case _0x9cdbbb(0x1fd):_0xb563f=await _0x33e1dc();break;case'chat':_0xb563f=_0x232d2d['id'];break;case _0x9cdbbb(0x2da):const _0x9f050c=_0x232d2d[_0x9cdbbb(0x241)]||GLOBAL_SCOPE_ID;_0xb563f=_0x9f050c+'_'+_0x232d2d['id'];break;case _0x9cdbbb(0x263):default:_0xb563f=_0x1214c2+'_'+_0x232d2d['id'];break;}if(!_0xb563f)return[];console[_0x9cdbbb(0x25d)]('[翰林院-日志]\x20正在查询知识库:\x20'+_0x232d2d[_0x9cdbbb(0x309)]+'\x20(ID:\x20'+_0xb563f+')');const _0xb01d51=_0x50c327||(await getEmbeddings([_0x4e0bc4]))[0x0];if(!_0xb01d51)return console[_0x9cdbbb(0x325)](_0x9cdbbb(0x2c3)+_0xb563f+'\x20生成查询向量。'),[];const _0x37f99f={'collectionId':_0xb563f,'searchText':_0x4e0bc4,'topK':settings[_0x9cdbbb(0x2e2)][_0x9cdbbb(0x288)],'threshold':settings[_0x9cdbbb(0x2e2)][_0x9cdbbb(0x21a)],'source':_0x9cdbbb(0x305),'embeddings':{[_0x4e0bc4]:_0xb01d51}};try{const _0x17b01d=await fetch(_0x9cdbbb(0x26b),{'method':_0x9cdbbb(0x24d),'headers':context[_0x9cdbbb(0x2dd)](),'body':JSON[_0x9cdbbb(0x24f)](_0x37f99f)});if(!_0x17b01d['ok']){const _0x554835=await _0x17b01d[_0x9cdbbb(0x230)]();return console[_0x9cdbbb(0x325)](_0x9cdbbb(0x293)+_0xb563f+_0x9cdbbb(0x21f),_0x554835),[];}const _0x150c25=await _0x17b01d[_0x9cdbbb(0x2e9)]();let _0x54c265=[];if(Array[_0x9cdbbb(0x23f)](_0x150c25))_0x54c265=_0x150c25;else{if(_0x150c25&&_0x150c25[_0x9cdbbb(0x1f0)]&&Array[_0x9cdbbb(0x23f)](_0x150c25[_0x9cdbbb(0x1f0)]))_0x54c265=_0x150c25[_0x9cdbbb(0x1f0)];else{if(_0x150c25&&_0x150c25['results']&&Array[_0x9cdbbb(0x23f)](_0x150c25['results']))_0x54c265=_0x150c25[_0x9cdbbb(0x2eb)];else _0x150c25&&_0x150c25[_0x9cdbbb(0x2c1)]&&Array[_0x9cdbbb(0x23f)](_0x150c25['data'])&&(_0x54c265=_0x150c25[_0x9cdbbb(0x2c1)]);}}const _0xc3e541=_0x54c265[_0x9cdbbb(0x272)](_0x14e5f9=>{const _0x1533cb=_0x9cdbbb;if(!_0x14e5f9||typeof _0x14e5f9[_0x1533cb(0x230)]!==_0x1533cb(0x242))return null;const _0x20a6aa={'source':_0x1533cb(0x247),'sourceName':'未知'},_0x39938a=_0x14e5f9[_0x1533cb(0x230)][_0x1533cb(0x2a1)](/^<([^>]+)>/),_0x1089a5=_0x39938a?_0x39938a[0x1]:'';switch(_0x1089a5){case'聊天记录':_0x20a6aa[_0x1533cb(0x27e)]=_0x1533cb(0x215);const _0x277b1a=_0x14e5f9[_0x1533cb(0x230)][_0x1533cb(0x2a1)](/楼层:\s*#(\d+),\s*第(\d+)部分/);_0x277b1a&&_0x277b1a[0x1]&&_0x277b1a[0x2]&&(_0x20a6aa[_0x1533cb(0x29c)]=parseInt(_0x277b1a[0x1],0xa),_0x20a6aa[_0x1533cb(0x31b)]=parseInt(_0x277b1a[0x2],0xa),_0x20a6aa[_0x1533cb(0x314)]=_0x1533cb(0x323)+_0x20a6aa[_0x1533cb(0x29c)]);break;case _0x1533cb(0x245):_0x20a6aa[_0x1533cb(0x27e)]='lorebook';const _0xc1eaaa=_0x14e5f9[_0x1533cb(0x230)][_0x1533cb(0x2a1)](/\[来源:\s*([^,]+),\s*条目:\s*([^,]+),\s*第(\d+)部分\]/);_0xc1eaaa&&_0xc1eaaa[0x1]&&_0xc1eaaa[0x2]&&_0xc1eaaa[0x3]&&(_0x20a6aa['bookName']=_0xc1eaaa[0x1][_0x1533cb(0x2f9)](),_0x20a6aa[_0x1533cb(0x2f7)]=_0xc1eaaa[0x2][_0x1533cb(0x2f9)](),_0x20a6aa['part']=parseInt(_0xc1eaaa[0x3],0xa),_0x20a6aa[_0x1533cb(0x314)]=_0x20a6aa[_0x1533cb(0x278)]+':\x20'+_0x20a6aa[_0x1533cb(0x2f7)]);break;case'手动录入':_0x20a6aa[_0x1533cb(0x27e)]=_0x1533cb(0x2b3);const _0x32f2e0=_0x14e5f9[_0x1533cb(0x230)][_0x1533cb(0x2a1)](/\[来源:\s*([^,]+),.*第(\d+)部分\]/);_0x32f2e0&&_0x32f2e0[0x1]&&_0x32f2e0[0x2]&&(_0x20a6aa[_0x1533cb(0x314)]=_0x32f2e0[0x1][_0x1533cb(0x2f9)](),_0x20a6aa['part']=parseInt(_0x32f2e0[0x2],0xa));break;case'小说录入':_0x20a6aa[_0x1533cb(0x27e)]=_0x1533cb(0x2e3);const _0x53ad34=_0x14e5f9[_0x1533cb(0x230)][_0x1533cb(0x2a1)](/\[来源:\s*([^,]+),\s*([^,]+),\s*([^,]+),\s*([^\]]+)\]/);_0x53ad34&&(_0x20a6aa[_0x1533cb(0x314)]=_0x53ad34[0x1][_0x1533cb(0x2f9)](),_0x20a6aa['volume']=_0x53ad34[0x2][_0x1533cb(0x2f9)](),_0x20a6aa['chapter']=_0x53ad34[0x3][_0x1533cb(0x2f9)](),_0x20a6aa['section']=_0x53ad34[0x4][_0x1533cb(0x2f9)]());break;}return{..._0x14e5f9,'score':_0x14e5f9[_0x1533cb(0x20e)]||0x1,'metadata':_0x20a6aa};})['filter'](Boolean);return console['log']('[翰林院-V13\x20修复]\x20重建元数据后,知识库\x20'+_0x232d2d[_0x9cdbbb(0x309)]+_0x9cdbbb(0x2be)+_0xc3e541['length']+_0x9cdbbb(0x30c)),_0xc3e541;}catch(_0x18f69a){return console[_0x9cdbbb(0x325)](_0x9cdbbb(0x293)+_0xb563f+'\x20时发生网络错误:',_0x18f69a),[];}}async function insertVectors(_0x33e906,_0x1429e7=null,_0x42f8b9){const _0x401441=_0x1b9b83;if(!_0x42f8b9)throw new Error('insertVectors\x20必须接收一个有效的\x20collectionId\x20参数。');if(_0x33e906[_0x401441(0x2c6)]===0x0)return{'success':!![],'count':0x0};const _0x317201=_0x33e906[_0x401441(0x272)]((_0x662daa,_0x135d46)=>({'hash':generateHash(_0x662daa[_0x401441(0x230)]+Date['now']()+_0x135d46),'text':_0x662daa[_0x401441(0x230)],'metadata':_0x662daa[_0x401441(0x1f0)]||{'source':_0x401441(0x247),'timestamp':new Date()[_0x401441(0x24a)]()}})),_0xf427a8=_0x317201[_0x401441(0x317)]((_0x1c97f0,_0x12aa67,_0xcd192b)=>{const _0x2e3b93=_0x401441;return _0x1c97f0[_0x12aa67['text']]=_0x33e906[_0xcd192b][_0x2e3b93(0x2cf)],_0x1c97f0;},{}),_0x188314={'collectionId':_0x42f8b9,'items':_0x317201,'source':_0x401441(0x305),'embeddings':_0xf427a8},_0x239b9a=await fetch('/api/vector/insert',{'method':'POST','headers':context[_0x401441(0x2dd)](),'body':JSON[_0x401441(0x24f)](_0x188314),'signal':_0x1429e7});if(!_0x239b9a['ok']){const _0x39eb17=await _0x239b9a[_0x401441(0x230)]();console[_0x401441(0x325)](_0x401441(0x1f4),_0x39eb17);throw new Error(_0x401441(0x282)+_0x239b9a[_0x401441(0x2a8)]+':\x20'+_0x39eb17);}return{'success':!![],'count':_0x317201['length']};}async function getVectorCount(_0x4dfabc=null,_0x5690b5=_0x1b9b83(0x263)){const _0x34acb2=_0x1b9b83,_0x4ff071=getCharacterStableId();if(_0x4dfabc){const _0x46d73f=_0x5690b5===_0x34acb2(0x2da)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x2563a5=_0x46d73f[_0x4dfabc];if(!_0x2563a5)return console[_0x34acb2(0x27d)]('[翰林院-计数]\x20在作用域\x20\x27'+_0x5690b5+_0x34acb2(0x2bf)+_0x4dfabc+_0x34acb2(0x30e)),0x0;const _0x110858=_0x5690b5===_0x34acb2(0x2da)?_0x2563a5[_0x34acb2(0x241)]||GLOBAL_SCOPE_ID:_0x4ff071,_0x5e617a=_0x110858+'_'+_0x4dfabc;return await countVectorsInCollection(_0x5e617a);}else{if(settings['retrieval']['independentChatMemoryEnabled']){const _0x440dc3=getChatId();if(!_0x440dc3)return 0x0;const _0x1fb5ce=await countVectorsInCollection(_0x440dc3);return console[_0x34acb2(0x25d)]('[翰林院-日志]\x20独立聊天记忆模式开启,聊天\x20'+_0x440dc3+_0x34acb2(0x2f2)+_0x1fb5ce),_0x1fb5ce;}console['log'](_0x34acb2(0x28d));const _0x339955=Object[_0x34acb2(0x208)](getLocalKnowledgeBases()),_0xbf88b0=Object[_0x34acb2(0x208)](getGlobalKnowledgeBases()),_0x4c0bc3=[];_0x339955[_0x34acb2(0x26f)](_0x3b7f93=>{const _0x474030=_0x4ff071+'_'+_0x3b7f93['id'];_0x4c0bc3['push'](countVectorsInCollection(_0x474030));}),_0xbf88b0[_0x34acb2(0x26f)](_0x5617fa=>{const _0x718549=_0x34acb2,_0x2b4679=_0x5617fa[_0x718549(0x241)]||GLOBAL_SCOPE_ID,_0x550991=_0x2b4679+'_'+_0x5617fa['id'];_0x4c0bc3[_0x718549(0x1f3)](countVectorsInCollection(_0x550991));});const _0x5b139d=await _0x33e1dc();_0x4c0bc3[_0x34acb2(0x1f3)](countVectorsInCollection(_0x5b139d));const _0x854521=await Promise[_0x34acb2(0x29a)](_0x4c0bc3),_0x22c663=_0x854521[_0x34acb2(0x317)]((_0x374e5f,_0x277cf3)=>_0x374e5f+_0x277cf3,0x0);return console['log'](_0x34acb2(0x2e7)+_0x22c663),_0x22c663;}}async function countVectorsInCollection(_0xdccc8a){const _0x145a60=_0x1b9b83;if(!_0xdccc8a)return 0x0;console[_0x145a60(0x25d)](_0x145a60(0x31e)+_0xdccc8a);const _0xe3060={'collectionId':_0xdccc8a,'source':_0x145a60(0x305),'embeddings':{}};try{const _0x1263b1=await fetch(_0x145a60(0x2fd),{'method':'POST','headers':context['getRequestHeaders'](),'body':JSON[_0x145a60(0x24f)](_0xe3060)});if(!_0x1263b1['ok']){if(_0x1263b1[_0x145a60(0x2a8)]===0x194)console[_0x145a60(0x25d)](_0x145a60(0x22f)+_0xdccc8a+_0x145a60(0x284));else{const _0x24ed21=await _0x1263b1[_0x145a60(0x230)]();console[_0x145a60(0x27d)](_0x145a60(0x271)+_0xdccc8a+_0x145a60(0x237)+_0x1263b1[_0x145a60(0x2a8)]+'):',_0x24ed21);}return 0x0;}const _0x51560a=await _0x1263b1['json']();let _0x2296d0=0x0;if(Array[_0x145a60(0x23f)](_0x51560a))_0x2296d0=_0x51560a[_0x145a60(0x2c6)];else _0x51560a&&_0x51560a[_0x145a60(0x213)]&&(_0x2296d0=_0x51560a[_0x145a60(0x213)][_0x145a60(0x2c6)]);return _0x2296d0;}catch(_0x340a5d){return console['error'](_0x145a60(0x2a5)+_0xdccc8a+'\x20时发生网络错误:',_0x340a5d),0x0;}}async function purgeStorage(_0x51659e=null){const _0x3e2bd4=_0x1b9b83;console[_0x3e2bd4(0x25d)](_0x3e2bd4(0x296));const _0x408f19=_0x51659e||await getCollectionId();if(!_0x408f19)return console[_0x3e2bd4(0x325)](_0x3e2bd4(0x2ed)),toastr['error'](_0x3e2bd4(0x2d0)),![];console['log'](_0x3e2bd4(0x1ee)+_0x408f19);const _0x1cb105={'collectionId':_0x408f19};console[_0x3e2bd4(0x25d)](_0x3e2bd4(0x287),JSON[_0x3e2bd4(0x24f)](_0x1cb105,null,0x2));const _0xf08ba9=await fetch(_0x3e2bd4(0x303),{'method':_0x3e2bd4(0x24d),'headers':context[_0x3e2bd4(0x2dd)](),'body':JSON[_0x3e2bd4(0x24f)](_0x1cb105)});console[_0x3e2bd4(0x25d)](_0x3e2bd4(0x249)+_0xf08ba9[_0x3e2bd4(0x2a8)]);if(!_0xf08ba9['ok']){const _0x443a27=await _0xf08ba9[_0x3e2bd4(0x230)]();console[_0x3e2bd4(0x325)](_0x3e2bd4(0x257),_0x443a27);}else console['log']('[翰林院-日志]\x20清空宝库API调用成功。');return _0xf08ba9['ok'];}function getMessagesForCondensation(_0x389f4c=null){const _0x59b343=_0x1b9b83;if(!settings[_0x59b343(0x1f1)][_0x59b343(0x22c)])return showNotification(_0x59b343(0x20f),'warning'),[];const {layerStart:_0x1946de,layerEnd:_0x2714b0}=settings[_0x59b343(0x1f1)],_0x8a55c5=_0x389f4c||settings[_0x59b343(0x1f1)][_0x59b343(0x267)],_0x29590f=context[_0x59b343(0x234)][_0x59b343(0x2c6)],_0x466711=Math[_0x59b343(0x281)](0x0,_0x1946de-0x1),_0x12cff4=_0x2714b0===0x0||_0x2714b0>_0x29590f?_0x29590f:Math[_0x59b343(0x28b)](_0x29590f,_0x2714b0),_0x39b6fd=context[_0x59b343(0x234)]['slice'](_0x466711,_0x12cff4);return _0x39b6fd[_0x59b343(0x2d6)](_0x2941e6=>{const _0x14ba98=_0x59b343,_0x440a67=_0x2941e6[_0x14ba98(0x205)]===!![],_0xe05d50=_0x2941e6[_0x14ba98(0x205)]===![];if(!_0x2941e6[_0x14ba98(0x2f4)]||!_0x2941e6[_0x14ba98(0x2f4)]['trim']())return![];return _0x8a55c5[_0x14ba98(0x300)]&&_0x440a67||_0x8a55c5['ai']&&_0xe05d50;});}async function processCondensation(_0x1b633d,_0x165b69=()=>{},_0x2348d1=null){const _0x120a47=_0x1b9b83;if(!_0x1b633d||_0x1b633d[_0x120a47(0x2c6)]===0x0)return{'success':![],'error':'No\x20messages\x20to\x20process.'};try{let _0x10224b,_0x27bdc8;const _0x566c96=getCharacterName()||_0x120a47(0x26a);if(_0x2348d1){const _0x1d4b2e=_0x2348d1[_0x120a47(0x291)]??'?',_0x32cc8a=_0x2348d1[_0x120a47(0x2b4)]===0x0?'末':_0x2348d1[_0x120a47(0x2b4)]??'?';_0x10224b=_0x566c96+':\x20'+_0x1d4b2e+'楼-'+_0x32cc8a+'楼';}else{const _0x4669e6=new Date()[_0x120a47(0x253)](_0x120a47(0x236),{'hour12':![]});_0x10224b='聊天记录:\x20'+_0x4669e6;}const _0x4c0422=Object[_0x120a47(0x208)](getLocalKnowledgeBases()),_0x25f204=_0x4c0422['find'](_0x478507=>_0x478507[_0x120a47(0x309)]===_0x10224b);if(_0x25f204)_0x27bdc8=_0x25f204['id'],_0x165b69(_0x120a47(0x210)+_0x10224b+_0x120a47(0x29f),_0x120a47(0x25f));else{_0x165b69(_0x120a47(0x2ad)+_0x10224b+_0x120a47(0x292),'info');const _0x1636ee=addKnowledgeBase(_0x10224b,_0x120a47(0x215));_0x27bdc8=_0x1636ee['id'];}const _0x5221af=getCharacterStableId(),_0x2cab6d=_0x5221af+'_'+_0x27bdc8;_0x165b69(_0x120a47(0x23a)+_0x10224b+_0x120a47(0x2e1)+_0x2cab6d+')',_0x120a47(0x31a));const _0x4760f5=[],_0x458741=context[_0x120a47(0x234)];for(const _0x4d1b7f of _0x1b633d){const _0x2f320a=(_0x4d1b7f['mes']||'')[_0x120a47(0x2a0)](/<[^>]*>/g,'')['trim']();if(_0x2f320a[_0x120a47(0x2c6)]===0x0)continue;let _0x399d4f;if(_0x4d1b7f[_0x120a47(0x29c)]!==undefined&&_0x4d1b7f[_0x120a47(0x29c)]!==null)_0x399d4f=_0x4d1b7f[_0x120a47(0x29c)];else{const _0x119962=_0x458741[_0x120a47(0x233)](_0x15aa0c=>_0x15aa0c===_0x4d1b7f);_0x399d4f=_0x119962!==-0x1?_0x119962+0x1:-0x1;}const _0x253582=new Date(_0x4d1b7f[_0x120a47(0x243)]),_0x5b6f1d=isNaN(_0x253582[_0x120a47(0x2c7)]())?new Date()[_0x120a47(0x24a)]():_0x253582[_0x120a47(0x24a)](),_0xa4d23=splitIntoChunks(_0x2f320a,'chat_history',{'floor':_0x399d4f,'is_user':_0x4d1b7f['is_user'],'timestamp':_0x5b6f1d});_0x4760f5[_0x120a47(0x1f3)](..._0xa4d23);}if(_0x4760f5['length']===0x0)return{'success':!![],'count':0x0};_0x165b69(_0x120a47(0x2b2)+_0x1b633d[_0x120a47(0x2c6)]+_0x120a47(0x302)+_0x4760f5['length']+_0x120a47(0x27b),'info');const _0x58fbcb=settings['retrieval']['batchSize']||0x5;let _0x521703=0x0;for(let _0x5a05aa=0x0;_0x5a05aa<_0x4760f5[_0x120a47(0x2c6)];_0x5a05aa+=_0x58fbcb){const _0x24e072=_0x4760f5[_0x120a47(0x238)](_0x5a05aa,_0x5a05aa+_0x58fbcb),_0xefd61a=_0x24e072[_0x120a47(0x272)](_0x3f267a=>_0x3f267a[_0x120a47(0x230)]),_0x124dd1=await getEmbeddings(_0xefd61a);if(_0x24e072[_0x120a47(0x2c6)]!==_0x124dd1[_0x120a47(0x2c6)])throw new Error(_0x120a47(0x222));const _0x41b532=_0x24e072[_0x120a47(0x272)]((_0x5388c5,_0x2724a4)=>({..._0x5388c5,'vector':_0x124dd1[_0x2724a4]}));await insertVectors(_0x41b532,null,_0x2cab6d),_0x521703+=_0x24e072[_0x120a47(0x2c6)];}if(_0x2348d1){const _0x155d88=_0x2348d1['end']===0x0?context[_0x120a47(0x234)]['length']:_0x2348d1[_0x120a47(0x2b4)],_0x38bd49=getCharacterStableId();!settings['condensationHistory'][_0x38bd49]&&(settings[_0x120a47(0x28f)][_0x38bd49]={}),settings['condensationHistory'][_0x38bd49][_0x2cab6d]={'start':_0x2348d1[_0x120a47(0x291)],'end':_0x155d88,'timestamp':new Date()[_0x120a47(0x24a)]()},saveSettings(),_0x165b69(_0x120a47(0x203)+_0x2cab6d+_0x120a47(0x2ff)+_0x2348d1[_0x120a47(0x291)]+'-'+_0x155d88,'info');}_0x165b69(_0x120a47(0x283)+_0x521703+_0x120a47(0x2ba),_0x120a47(0x31a));const _0x33a90f=_0x1b633d['map'](_0x273e77=>{const _0x41d45c=_0x120a47,_0x460082=_0x458741[_0x41d45c(0x233)](_0x542006=>_0x542006===_0x273e77),_0x5830d0=_0x460082!==-0x1?_0x460082+0x1:-0x1,_0xc8fb9c=_0x273e77[_0x41d45c(0x205)]?'用户':getCharacterName()||'AI';return'['+_0xc8fb9c+_0x41d45c(0x2d2)+_0x5830d0+_0x41d45c(0x2a9);});return{'success':!![],'count':_0x521703,'messages':_0x33a90f};}catch(_0x2326c7){return console[_0x120a47(0x325)](_0x120a47(0x2ef),_0x2326c7),_0x165b69(_0x120a47(0x227)+_0x2326c7[_0x120a47(0x226)],_0x120a47(0x325)),{'success':![],'error':_0x2326c7[_0x120a47(0x226)]};}}function preprocessQueryText(_0x44623b){const _0x2e4fbd=_0x1b9b83;if(!settings[_0x2e4fbd(0x21e)]['enabled'])return _0x44623b;let _0x18927d=_0x44623b;const {tagExtractionEnabled:_0x3c3a4f,tags:_0x4bdf2c,exclusionRules:_0xb22d8d}=settings[_0x2e4fbd(0x21e)];if(_0x3c3a4f&&_0x4bdf2c){const _0x4e35c7=_0x4bdf2c[_0x2e4fbd(0x2bb)](',')[_0x2e4fbd(0x272)](_0x519dd9=>_0x519dd9[_0x2e4fbd(0x2f9)]())[_0x2e4fbd(0x2d6)](Boolean);if(_0x4e35c7[_0x2e4fbd(0x2c6)]>0x0){const _0x4b97d7=extractBlocksByTags(_0x18927d,_0x4e35c7);_0x18927d=_0x4b97d7[_0x2e4fbd(0x206)]('\x0a\x0a');}}_0xb22d8d&&_0xb22d8d['length']>0x0&&(_0x18927d=applyExclusionRules(_0x18927d,_0xb22d8d));const _0x579862=_0x18927d[_0x2e4fbd(0x2f9)]();return _0x44623b!==_0x579862&&(console[_0x2e4fbd(0x25d)](_0x2e4fbd(0x2c2)+_0x44623b+'\x22'),console[_0x2e4fbd(0x25d)](_0x2e4fbd(0x2c4)+_0x579862+'\x22')),_0x579862;}async function rerankResults(_0x231da9,_0x367f85,_0x1c7108){const _0x59bfd7=_0x1b9b83;let _0x505796=_0x231da9,_0x111492=![];if(_0x1c7108['rerank'][_0x59bfd7(0x22c)]&&_0x231da9[_0x59bfd7(0x2c6)]>0x0){console[_0x59bfd7(0x25d)](_0x59bfd7(0x2e0));try{const _0x535a6f=_0x231da9[_0x59bfd7(0x272)](_0x444109=>_0x444109[_0x59bfd7(0x230)]),_0x2ce7f1=await executeRerank(_0x367f85,_0x535a6f,_0x1c7108[_0x59bfd7(0x297)]),_0x227e60=_0x231da9['map']((_0x1995e8,_0x5bb313)=>({..._0x1995e8,'original_index':_0x5bb313}));_0x505796=_0x227e60[_0x59bfd7(0x272)](_0x1cfe51=>{const _0xbb7801=_0x59bfd7,_0x129901=_0x2ce7f1[_0xbb7801(0x2eb)]['find'](_0x1971c7=>_0x1971c7[_0xbb7801(0x22a)]===_0x1cfe51[_0xbb7801(0x220)]),_0x4d850e=_0x129901?_0x129901[_0xbb7801(0x322)]:0x0;return{..._0x1cfe51,'rerank_score':_0x4d850e};}),_0x111492=!![];}catch(_0x538e78){console[_0x59bfd7(0x325)](_0x59bfd7(0x28a),_0x538e78);if(_0x1c7108[_0x59bfd7(0x297)][_0x59bfd7(0x2ce)])showNotification(_0x59bfd7(0x31d)+_0x538e78[_0x59bfd7(0x226)],_0x59bfd7(0x325));_0x505796[_0x59bfd7(0x26f)](_0x1bce65=>_0x1bce65[_0x59bfd7(0x209)]=0x0);}}else _0x505796[_0x59bfd7(0x26f)](_0x450a42=>_0x450a42[_0x59bfd7(0x209)]=0x0);console[_0x59bfd7(0x25d)]('[翰林院-Rerank]\x20开始元数据加权最终排序...');const _0x485d91=context[_0x59bfd7(0x234)]['length'],_0x335e52=_0x1c7108[_0x59bfd7(0x297)][_0x59bfd7(0x24c)],_0x4ed74e=_0x505796[_0x59bfd7(0x272)](_0x27a7ee=>{const _0x492952=_0x59bfd7;let _0x592591=0x1;const _0x22641d=_0x27a7ee[_0x492952(0x1f0)]||{};switch(_0x22641d[_0x492952(0x27e)]){case _0x492952(0x24b):_0x592591*=1.2;break;case'manual':_0x592591*=1.1;break;case _0x492952(0x215):if(_0x22641d['floor']&&_0x485d91>0x0){const _0x84c190=_0x22641d['floor']/_0x485d91;_0x592591*=0x1+_0x84c190;}break;}const _0x469347=_0x27a7ee['rerank_score']*_0x335e52+(_0x27a7ee['score']||0x0)*(0x1-_0x335e52),_0x3180f6=_0x469347*_0x592591;return{'text':_0x27a7ee[_0x492952(0x230)],'score':_0x27a7ee[_0x492952(0x20e)],'rerank_score':_0x27a7ee[_0x492952(0x209)],'final_score':_0x3180f6,'metadata':_0x27a7ee['metadata']};});_0x4ed74e['sort']((_0x41fa53,_0x3682a0)=>(_0x3682a0[_0x59bfd7(0x250)]||0x0)-(_0x41fa53[_0x59bfd7(0x250)]||0x0)),console[_0x59bfd7(0x25d)](_0x59bfd7(0x239));let _0x247b0a=_0x4ed74e;return _0x1c7108['rerank'][_0x59bfd7(0x301)]&&(_0x247b0a=superSort(_0x4ed74e)),{'results':_0x247b0a['slice'](0x0,_0x1c7108[_0x59bfd7(0x297)]['top_n']),'reranked':_0x111492};}async function rearrangeChat(_0xd72adc,_0x84ed7e,_0x2462f3,_0x5f464f){const _0x3aacff=_0x1b9b83,_0x4c083d={'novel':_0x3aacff(0x1fa),'chat_history':_0x3aacff(0x217),'lorebook':_0x3aacff(0x201),'manual':_0x3aacff(0x274)};Object['values'](_0x4c083d)[_0x3aacff(0x26f)](_0x39226d=>setExtensionPrompt(_0x39226d,'',0x0,0x0,![],0x0));if(_0x5f464f===_0x3aacff(0x2bd)||!settings[_0x3aacff(0x23b)][_0x3aacff(0x22c)])return;const _0x333411=_0xd72adc[_0x3aacff(0x238)](-settings[_0x3aacff(0x2e2)][_0x3aacff(0x2a7)]);if(_0x333411['length']===0x0)return;const _0x22ea4d=settings[_0x3aacff(0x21e)];let _0x184067='';const _0x21ce02=[];for(const _0xa491c8 of _0x333411){if(_0xa491c8['is_user']){_0x21ce02[_0x3aacff(0x1f3)](_0xa491c8[_0x3aacff(0x2f4)]);continue;}if(_0x22ea4d['enabled']&&_0x22ea4d[_0x3aacff(0x1fc)]){const _0x2bfb06=(_0x22ea4d[_0x3aacff(0x310)]||'')[_0x3aacff(0x2bb)](',')[_0x3aacff(0x272)](_0x2444e9=>_0x2444e9['trim']())[_0x3aacff(0x2d6)](Boolean);if(_0x2bfb06['length']>0x0){const _0x364986=extractBlocksByTags(_0xa491c8[_0x3aacff(0x2f4)],_0x2bfb06);if(_0x364986['length']>0x0){const _0x29c873=_0x364986[_0x3aacff(0x272)](_0xd1066e=>{const _0x231876=_0x3aacff,_0x3f72cd=_0xd1066e[_0x231876(0x2a1)](/<[^>]+>([\s\S]*?)<\/[^>]+>/);return _0x3f72cd?_0x3f72cd[0x1]['trim']():'';});_0x21ce02[_0x3aacff(0x1f3)](_0x29c873[_0x3aacff(0x2d6)](Boolean)[_0x3aacff(0x206)]('\x0a\x0a'));}}else _0x21ce02[_0x3aacff(0x1f3)](_0xa491c8[_0x3aacff(0x2f4)]);}else _0x21ce02['push'](_0xa491c8[_0x3aacff(0x2f4)]);}_0x184067=_0x21ce02[_0x3aacff(0x2d6)](Boolean)[_0x3aacff(0x206)]('\x0a\x0a');_0x22ea4d[_0x3aacff(0x22c)]&&(_0x184067=applyExclusionRules(_0x184067,_0x22ea4d[_0x3aacff(0x295)]));_0x184067=_0x184067[_0x3aacff(0x2f9)]();if(!_0x184067){console['log'](_0x3aacff(0x1ed));return;}console[_0x3aacff(0x25d)]('[翰林院-预处理]\x20最终用于检索的文本:\x20\x22'+_0x184067+'\x22');try{const _0x1eabe1=0x2,_0x57ae26=settings['settingsVersion']||0x1;let _0x3babf3=![];if(_0x57ae26<_0x1eabe1){console['log'](_0x3aacff(0x31c)+_0x57ae26+_0x3aacff(0x2cb)),toastr[_0x3aacff(0x25f)](_0x3aacff(0x2b0),'翰林院通告');const _0x56c954=getKnowledgeBases();for(const _0x32163b of Object['values'](_0x56c954)){const _0x295d10=_0x32163b['name'],_0x2db2e5=_0x32163b[_0x3aacff(0x27e)];if(_0x295d10[_0x3aacff(0x26d)](_0x3aacff(0x1fe)))_0x32163b[_0x3aacff(0x27e)]=_0x3aacff(0x2b3);else{if(_0x295d10[_0x3aacff(0x26d)](_0x3aacff(0x211)))_0x32163b['source']=_0x3aacff(0x2e3);else _0x295d10[_0x3aacff(0x2bc)]('楼-')&&_0x295d10[_0x3aacff(0x2bc)]('楼')&&_0x295d10[_0x3aacff(0x2bc)](':')?_0x32163b[_0x3aacff(0x27e)]=_0x3aacff(0x215):_0x32163b[_0x3aacff(0x27e)]='lorebook';}_0x2db2e5!==_0x32163b[_0x3aacff(0x27e)]&&console[_0x3aacff(0x25d)](_0x3aacff(0x23d)+_0x295d10+_0x3aacff(0x318)+(_0x2db2e5||'无')+']\x20更正为\x20['+_0x32163b[_0x3aacff(0x27e)]+']');}settings['settingsVersion']=_0x1eabe1,_0x3babf3=!![];}_0x3babf3&&(console['log'](_0x3aacff(0x1f9)),saveSettings());let _0x279c3d=[];const _0x25cb09=settings['rerank'][_0x3aacff(0x1f8)];if(_0x25cb09[_0x3aacff(0x22c)]){console[_0x3aacff(0x25d)]('[翰林院]\x20进入多路并行独立检索流程...');const _0x1d3c73=Object[_0x3aacff(0x208)](getKnowledgeBases())['filter'](_0xc81fb2=>_0xc81fb2['enabled']),_0x360ae3=Object[_0x3aacff(0x311)](_0x25cb09['sources'])[_0x3aacff(0x2d6)](_0x2e015a=>_0x25cb09[_0x3aacff(0x1f2)][_0x2e015a]&&_0x25cb09['sources'][_0x2e015a]['enabled']),_0x278c80=[];let _0x4276cf=[..._0x1d3c73];for(const _0x3c3bba of _0x360ae3){const _0x204ee2=_0x25cb09['sources'][_0x3c3bba],_0x4fc3a4=_0x4276cf['filter'](_0x58c9aa=>_0x58c9aa[_0x3aacff(0x27e)]===_0x3c3bba);_0x4276cf=_0x4276cf[_0x3aacff(0x2d6)](_0x22706b=>!_0x4fc3a4['includes'](_0x22706b));if(_0x4fc3a4[_0x3aacff(0x2c6)]>0x0){console['log'](_0x3aacff(0x256)+_0x3c3bba+'\x20('+_0x4fc3a4['length']+'个库)');const _0x301adf=queryVectors(_0x184067,{'includeBases':_0x4fc3a4})[_0x3aacff(0x20d)](_0x45ff2b=>{const _0x51fe0b=_0x3aacff;console[_0x51fe0b(0x25d)](_0x51fe0b(0x2b6)+_0x3c3bba+_0x51fe0b(0x2be)+_0x45ff2b['length']+_0x51fe0b(0x30c));let _0x107fe0=_0x45ff2b['filter'](_0x207ace=>_0x207ace[_0x51fe0b(0x1f0)]?.[_0x51fe0b(0x27e)]===_0x3c3bba);return _0x107fe0=_0x107fe0[_0x51fe0b(0x238)](0x0,_0x204ee2[_0x51fe0b(0x30b)]),console[_0x51fe0b(0x25d)]('[翰林院]\x20已从\x20'+_0x3c3bba+'\x20池精确提取\x20'+_0x107fe0[_0x51fe0b(0x2c6)]+_0x51fe0b(0x30c)),settings[_0x51fe0b(0x297)]['superSortEnabled']&&(_0x107fe0=superSort(_0x107fe0)),_0x107fe0;});_0x278c80[_0x3aacff(0x1f3)](_0x301adf);}}const _0x1e3a23=_0x4276cf;if(_0x1e3a23['length']>0x0){console[_0x3aacff(0x25d)](_0x3aacff(0x2e5)+_0x1e3a23[_0x3aacff(0x2c6)]+'个库)');const _0x57dc89=queryVectors(_0x184067,{'includeBases':_0x1e3a23})[_0x3aacff(0x20d)](async _0x3c86c7=>{const _0x1539db=_0x3aacff;console[_0x1539db(0x25d)](_0x1539db(0x2ab)+_0x3c86c7[_0x1539db(0x2c6)]+_0x1539db(0x30c)),console['log'](_0x1539db(0x2cd));const _0x2cd62e=await rerankResults(_0x3c86c7,_0x184067,settings),_0x446637=_0x2cd62e[_0x1539db(0x2eb)];return console['log'](_0x1539db(0x273)+(_0x446637||[])[_0x1539db(0x2c6)]+'\x20条结果。'),_0x2cd62e[_0x1539db(0x232)]&&settings[_0x1539db(0x297)]['notify']&&showNotification('统一检索部分的Rerank已完成',_0x1539db(0x31a)),_0x446637;});_0x278c80[_0x3aacff(0x1f3)](_0x57dc89);}const _0x3f9069=await Promise[_0x3aacff(0x29a)](_0x278c80);_0x279c3d=_0x3f9069['flat']();}else{console[_0x3aacff(0x25d)]('[翰林院]\x20进入传统处理流程...');const _0x1c726b=await queryVectors(_0x184067),_0xd08076=await rerankResults(_0x1c726b,_0x184067,settings);_0x279c3d=_0xd08076[_0x3aacff(0x2eb)],_0xd08076[_0x3aacff(0x232)]&&settings[_0x3aacff(0x297)][_0x3aacff(0x2ce)]&&showNotification('外部Rerank完成','success');}if(!_0x279c3d||_0x279c3d[_0x3aacff(0x2c6)]===0x0){console[_0x3aacff(0x25d)](_0x3aacff(0x276));return;}console[_0x3aacff(0x25d)](_0x3aacff(0x20b)+_0x279c3d['length']+'\x20条结果。');const _0x40a447={'novel':[],'chat_history':[],'lorebook':[],'manual':[]};_0x279c3d[_0x3aacff(0x26f)](_0x430a33=>{const _0x30c31f=_0x3aacff,_0x26be00=_0x430a33[_0x30c31f(0x1f0)]?.['source'];_0x26be00&&_0x40a447[_0x30c31f(0x2c0)](_0x26be00)&&_0x40a447[_0x26be00][_0x30c31f(0x1f3)](_0x430a33);});for(const _0x35b1b3 in _0x40a447){const _0x15d3e3=_0x40a447[_0x35b1b3];if(_0x15d3e3['length']===0x0)continue;const _0x3ac963=settings[_0x3aacff(0x2a3)+_0x35b1b3[_0x3aacff(0x2a0)](_0x3aacff(0x2b1),'')];if(!_0x3ac963){console[_0x3aacff(0x27d)]('[翰林院]\x20未找到来源\x20\x27'+_0x35b1b3+_0x3aacff(0x298));continue;}const _0x370363=_0x15d3e3[_0x3aacff(0x272)](_0x57e7fe=>_0x57e7fe[_0x3aacff(0x230)])[_0x3aacff(0x206)]('\x0a\x0a'),_0x406f70='{{'+_0x35b1b3[_0x3aacff(0x2a0)](_0x3aacff(0x2b1),'')+_0x3aacff(0x2b8);let _0x5a9983=_0x3ac963['template']['replace'](_0x406f70,_0x370363);_0x5a9983[_0x3aacff(0x2f9)]()&&(_0x5a9983='%%'+_0x4c083d[_0x35b1b3]+'%%'+_0x5a9983),setExtensionPrompt(_0x4c083d[_0x35b1b3],_0x5a9983,_0x3ac963[_0x3aacff(0x262)],_0x3ac963[_0x3aacff(0x258)],![],_0x3ac963['depth_role']),console[_0x3aacff(0x25d)]('[翰林院]\x20已为来源\x20\x27'+_0x35b1b3+_0x3aacff(0x231)+_0x15d3e3['length']+_0x3aacff(0x2d7));}}catch(_0x54a11a){console[_0x3aacff(0x325)]('[翰林院]\x20检索或注入时发生错误:',_0x54a11a);if(settings[_0x3aacff(0x23b)][_0x3aacff(0x2ce)])showNotification('忆识检索失败:\x20'+_0x54a11a[_0x3aacff(0x226)],_0x3aacff(0x325));}}async function moveKnowledgeBase(_0x4ae700,_0x20e059){const _0x144333=_0x1b9b83,_0x509ba6=_0x20e059===_0x144333(0x2da)?_0x144333(0x263):_0x144333(0x2da),_0xb65599=getCharacterStableId();if(!_0xb65599&&_0x509ba6===_0x144333(0x263)){toastr[_0x144333(0x325)]('移动失败:没有当前角色,无法移入局部知识库。');return;}const _0x546ec7=_0x20e059==='global'?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x4d567f=_0x509ba6===_0x144333(0x2da)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x14d839=_0x546ec7[_0x4ae700];if(!_0x14d839){const _0x593564=_0x144333(0x202)+_0x20e059+_0x144333(0x2bf)+_0x4ae700+_0x144333(0x30e);console[_0x144333(0x325)](_0x144333(0x221)+_0x593564),toastr['error']('移动失败:未找到源条目。');return;}_0x20e059==='local'&&_0x509ba6===_0x144333(0x2da)&&!_0x14d839[_0x144333(0x241)]&&(console[_0x144333(0x25d)](_0x144333(0x2b7)+_0x4ae700+'\x20补充所有者ID:\x20'+_0xb65599),_0x14d839[_0x144333(0x241)]=_0xb65599);delete _0x546ec7[_0x4ae700],_0x4d567f[_0x4ae700]=_0x14d839,saveSettings();const _0x53c09d=_0x144333(0x279)+_0x14d839['name']+'】已成功移动到'+(_0x509ba6===_0x144333(0x2da)?'全局':'局部')+'。';console['log'](_0x144333(0x221)+_0x53c09d);}function renameKnowledgeBase(_0x2f229a,_0x418d82,_0x365afb){const _0x41ab9e=_0x1b9b83;if(!_0x418d82||!_0x418d82[_0x41ab9e(0x2f9)]()){toastr[_0x41ab9e(0x325)](_0x41ab9e(0x25c));throw new Error('知识库名称不能为空');}const _0x4a319a=_0x365afb===_0x41ab9e(0x2da)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x3ff675=_0x4a319a[_0x2f229a];if(!_0x3ff675){const _0xd53043=_0x41ab9e(0x2ee)+_0x365afb+_0x41ab9e(0x2bf)+_0x2f229a+_0x41ab9e(0x30e);console['error'](_0x41ab9e(0x221)+_0xd53043),toastr['error'](_0x41ab9e(0x2fc));throw new Error(_0xd53043);}const _0x46acf8=_0x3ff675[_0x41ab9e(0x309)];_0x3ff675[_0x41ab9e(0x309)]=_0x418d82[_0x41ab9e(0x2f9)](),saveSettings();const _0x2b9060=_0x41ab9e(0x2d8)+_0x46acf8+_0x41ab9e(0x235)+_0x3ff675[_0x41ab9e(0x309)]+'\x22。';console[_0x41ab9e(0x25d)](_0x41ab9e(0x221)+_0x2b9060),toastr[_0x41ab9e(0x31a)](_0x2b9060);}async function getAllVectorsFromCollection(_0x38ae0f){const _0x1fb67c=_0x1b9b83,_0x196688='*',_0x4978fc={'collectionId':_0x38ae0f,'searchText':_0x196688,'topK':0x2710,'threshold':0x0,'source':_0x1fb67c(0x305),'embeddings':{}},_0x1383c7=(await getEmbeddings([_0x196688]))[0x0];_0x4978fc[_0x1fb67c(0x2b5)]={[_0x196688]:_0x1383c7};const _0x23ed4e=await fetch(_0x1fb67c(0x26b),{'method':_0x1fb67c(0x24d),'headers':context['getRequestHeaders'](),'body':JSON[_0x1fb67c(0x24f)](_0x4978fc)});if(!_0x23ed4e['ok']){if(_0x23ed4e[_0x1fb67c(0x2a8)]===0x194)return console['log'](_0x1fb67c(0x2cc)+_0x38ae0f+_0x1fb67c(0x23c)),[];const _0x46975e=await _0x23ed4e[_0x1fb67c(0x230)]();throw new Error(_0x1fb67c(0x2c5)+_0x38ae0f+'\x20失败:\x20'+_0x46975e);}const _0x471fc3=await _0x23ed4e[_0x1fb67c(0x2e9)]();return _0x471fc3[_0x1fb67c(0x1f0)]||_0x471fc3[_0x1fb67c(0x2eb)]||_0x471fc3['data']||[];}