'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']||[];}