Files
ST-Amily2-Chat-Optimisation…/core/rag-processor.js
2025-10-12 15:56:10 +08:00

2 lines
53 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'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</','info','position','\x20不存在计为\x200。','chat','hanlinyuanRagProcessor','[翰林院-日志]\x20统计目标集合ID:\x20','[翰林院]\x20常规池处理完毕产出\x20','then','输入文本为空','source','[来源:\x20聊天记录,\x20楼层:\x20#','filter','sourceName','[翰林院-日志]\x20开始清空宝库...','查询集合\x20','[翰林院-核心]\x20成功插入\x20','newId','17115MIIeVx','local','[翰林院-日志]\x20/api/vector/purge\x20响应状态:\x20','[翰林院-日志]\x20正在查询知识库:\x20','novel','[翰林院-核心]\x20文本录入任务被用户中止。','[翰林院-核心]\x20成功删除知识库\x20','relevance_score','chat_history','[翰林院-户口普查]\x20检测到旧版设置\x20(V','[翰林院]\x20进入多路并行独立检索流程...','知识库\x20\x22','检测到旧版数据。此操作将把旧数据迁移到新格式,过程不可逆,是否继续?','对话记录小总结','正在处理\x20','\x27的文本分割成\x20','聊天记录:\x20','\x20返回\x20','depth','\x20个知识块准备入库。','batchSize','_history','saveSettingsDebounced','[翰林院]\x20优先组\x20','depth_role','toLocaleString','5dCRGyr','string','tiaomu','entryName','sources','name','[翰林院-核心]\x20已锁定忆识宝库ID:\x20','[翰林院-核心]\x20已为角色\x20','rerank','startsWith','index','quiet','忆识检索失败:\x20','\x20不存在返回空数组。','[翰林院-配置]\x20','\x27\x20的注入设置跳过处理。','\x20(ID:\x20','superSortEnabled','HANLINYUAN_RAG_NOVEL','[翰林院-Rerank]\x20元数据加权排序完成。','忆识存入API错误\x20','[翰林院]\x20未能获取SillyTavern上下文初始化失败。','warn','963918nHZCuH','webllm','[翰林院-日志]\x20获取集合\x20','[翰林院-核心]\x20文本录入失败:\x20','condensationHistory','clearJob','slice','bookName','catch','getTime','手动录入','original_index','reduce',',\x20条目:\x20','\x20个条目。','HANLINYUAN_RAG_MANUAL','hanlinyuan-rag-core','[翰林院-日志]\x20没有启用的新知识库尝试查询旧版单体宝库...','_text}}','retrieval','bianzhuan','[翰林院-核心]\x20知识库\x20','[翰林院]\x20创建常规查询组\x20(','<mark\x20class=\x22search-highlight\x22>$1</mark>','[翰林院]\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</'+_0x4a6e44+'>';_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</'+_0x33434e+'>';_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)]||[];}