From 1f13e8ea7b1e7c12240149efbea3fd40b68f7c32 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Fri, 10 Oct 2025 22:04:54 +0800 Subject: [PATCH 01/29] Update rag-processor.js --- core/rag-processor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/rag-processor.js b/core/rag-processor.js index b1724b4..0d1db69 100644 --- a/core/rag-processor.js +++ b/core/rag-processor.js @@ -1 +1 @@ -'use strict';const _0x4826de=_0x2dc8;(function(_0x5275b7,_0x2624d9){const _0x46f463=_0x2dc8,_0x53a934=_0x5275b7();while(!![]){try{const _0x5209ee=-parseInt(_0x46f463(0x156))/0x1*(-parseInt(_0x46f463(0x16a))/0x2)+parseInt(_0x46f463(0xfe))/0x3*(parseInt(_0x46f463(0x18e))/0x4)+parseInt(_0x46f463(0x1a8))/0x5*(-parseInt(_0x46f463(0x13b))/0x6)+parseInt(_0x46f463(0x151))/0x7*(parseInt(_0x46f463(0x113))/0x8)+-parseInt(_0x46f463(0x1d0))/0x9*(-parseInt(_0x46f463(0x1b8))/0xa)+-parseInt(_0x46f463(0x106))/0xb*(parseInt(_0x46f463(0x1b2))/0xc)+parseInt(_0x46f463(0x143))/0xd;if(_0x5209ee===_0x2624d9)break;else _0x53a934['push'](_0x53a934['shift']());}catch(_0x427fd4){_0x53a934['push'](_0x53a934['shift']());}}}(_0x4d15,0xb0da3));import{extension_prompt_roles,setExtensionPrompt}from'/script.js';import*as _0xfd5dee from'./utils/context-utils.js';import{getCollectionIdInfo,getCharacterId,getCharacterStableId}from'./utils/context-utils.js';import{defaultSettings as _0xd3e1e}from'./rag-settings.js';import*as _0x9fe58b from'./ingestion-manager.js';import{getEmbeddings,fetchEmbeddingModels as _0x3f19f5,fetchRerankModels as _0x40ae91,executeRerank,testApiConnection as _0x23d63}from'./rag-api.js';import{superSort}from'./super-sorter.js';const MODULE_NAME='hanlinyuan-rag-core',OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME='vectors_rearrangeChat',GLOBAL_SCOPE_ID='_global';let context=null,settings=null,lockedCollectionId=null;function filterWorldbooks(_0x4f92a8,_0x2ffda8){const _0x4552c1=_0x2dc8;if(!_0x4f92a8||!_0x4f92a8['trim']())return _0x2ffda8;const _0x500500=_0x4f92a8[_0x4552c1(0x163)]()['trim']();return _0x2ffda8[_0x4552c1(0x150)](_0x13cad5=>{const _0x35cb1a=_0x4552c1;return _0x13cad5[_0x35cb1a(0x163)]()[_0x35cb1a(0x10e)](_0x500500)||containsPinyinMatch(_0x13cad5,_0x500500);});}function filterWorldbookEntries(_0x5ab25f,_0x4962d8){const _0x521ad9=_0x2dc8;if(!_0x5ab25f||!_0x5ab25f[_0x521ad9(0x1e5)]())return _0x4962d8;const _0xae5ff6=_0x5ab25f[_0x521ad9(0x163)]()[_0x521ad9(0x1e5)]();return _0x4962d8['filter'](_0x49ad8c=>{const _0x2bb3d7=_0x521ad9,_0x41bfea=[_0x49ad8c[_0x2bb3d7(0x102)]||'',_0x49ad8c[_0x2bb3d7(0x1bf)]||'',_0x49ad8c[_0x2bb3d7(0x1aa)]||''][_0x2bb3d7(0x161)]('\x20')[_0x2bb3d7(0x163)]();return _0x41bfea['includes'](_0xae5ff6)||containsPinyinMatch(_0x49ad8c[_0x2bb3d7(0x102)]||'',_0xae5ff6);});}function containsPinyinMatch(_0x1df0fa,_0xe9309c){const _0x450b8f=_0x2dc8,_0x11cf2e={'世界书':_0x450b8f(0x15b),'条目':_0x450b8f(0x18b),'编纂':_0x450b8f(0x169),'搜索':'sousuo'},_0x1eac1d=_0x11cf2e[_0x1df0fa];return _0x1eac1d&&_0x1eac1d[_0x450b8f(0x10e)](_0xe9309c);}function highlightSearchMatch(_0x53a086,_0x33348d){const _0x49b6ab=_0x2dc8;if(!_0x33348d||!_0x33348d[_0x49b6ab(0x1e5)]())return _0x53a086;const _0xdc935d=new RegExp('('+_0x33348d[_0x49b6ab(0x14e)](/[.*+?^${}()|[\]\\]/g,'\x5c$&')+')','gi');return _0x53a086['replace'](_0xdc935d,_0x49b6ab(0x1da));}function debounce(_0x3c23c9,_0x154f00){let _0xb42760;return function _0xea990c(..._0x1529c7){const _0x218c70=()=>{clearTimeout(_0xb42760),_0x3c23c9(..._0x1529c7);};clearTimeout(_0xb42760),_0xb42760=setTimeout(_0x218c70,_0x154f00);};}export{initialize,getSettings,saveSettings,resetSettings,_0x23d63 as testApiConnection,_0x3f19f5 as fetchEmbeddingModels,_0x40ae91 as fetchRerankModels,getVectorCount,purgeStorage,getMessagesForCondensation,processCondensation,ingestTextToHanlinyuan,getCollectionId,toggleSessionLock,isSessionLocked,getLockedSessionInfo,addKnowledgeBase,removeKnowledgeBase,getLocalKnowledgeBases,getGlobalKnowledgeBases,toggleKnowledgeBase,moveKnowledgeBase,filterWorldbooks,filterWorldbookEntries,highlightSearchMatch,debounce};function initialize(){const _0x3a75b4=_0x2dc8;context=SillyTavern[_0x3a75b4(0x1c7)]();if(!context){console['error'](_0x3a75b4(0xf4));return;}settings=getSettings(),!window['hanlinyuanRagProcessor']&&(window['hanlinyuanRagProcessor']={}),window[_0x3a75b4(0x1a6)][_0x3a75b4(0x1ec)]=rearrangeChat,window[_0x3a75b4(0x1a6)][_0x3a75b4(0x1c6)]=!![],console[_0x3a75b4(0xff)]('翰林院忆识核心已启动\x20(V5.2-集成版),已注册到全局\x20hanlinyuanRagProcessor\x20对象。');}async function ingestTextToHanlinyuan(_0x779204,_0x1164b6='manual',_0x16568b={},_0x13daed=()=>{},_0x455cbd=null,_0x43464a=()=>{},_0x3645e7=()=>{},_0x2d9e5f=null,_0x35b44a=0x0){const _0x516d7a=_0x2dc8;if(!_0x779204||!_0x779204[_0x516d7a(0x1e5)]())return{'success':![],'error':_0x516d7a(0xe8)};if(!settings)return{'success':![],'error':'核心未初始化'};try{const _0x3b1c71=getCollectionIdInfo(),_0x5ccff3=await _0x47c456();if(_0x3b1c71[_0x516d7a(0xf2)]&&_0x3b1c71[_0x516d7a(0xf2)]===_0x5ccff3&&_0x3b1c71[_0x516d7a(0xf2)]!==_0x3b1c71[_0x516d7a(0x12d)]){const _0x36e697=confirm(_0x516d7a(0x10d));if(_0x36e697)_0x43464a(_0x516d7a(0x168)+_0x3b1c71[_0x516d7a(0xf2)],_0x516d7a(0x1ae)),await purgeStorage(_0x3b1c71['oldId']),_0x43464a(_0x516d7a(0x182),_0x516d7a(0x148));else return _0x43464a(_0x516d7a(0x14a),_0x516d7a(0x196)),toastr[_0x516d7a(0x196)](_0x516d7a(0x15f)),{'success':![],'error':_0x516d7a(0x1ef)};}let _0x39ebab,_0x5eddb2;const _0x2667f4=new Date()[_0x516d7a(0x153)](_0x516d7a(0x176),{'hour12':![]}),_0x1a310f=getCharacterName()||_0x516d7a(0x10f);switch(_0x1164b6){case _0x516d7a(0x1c3):const _0x51be02=_0x16568b[_0x516d7a(0x12e)]||{},_0x26ccfa=_0x51be02[_0x516d7a(0x1c5)]??'?',_0x254943=_0x51be02[_0x516d7a(0x1f0)]===0x0?'末':_0x51be02[_0x516d7a(0x1f0)]??'?';_0x39ebab=_0x1a310f+':\x20'+_0x26ccfa+'楼-'+_0x254943+'楼';break;case'lorebook':const _0x5ee52f=_0x16568b[_0x516d7a(0xed)]||_0x516d7a(0x1d8);if(_0x16568b[_0x516d7a(0x178)]&&_0x16568b['entryName']['includes'](_0x516d7a(0x139)))_0x16568b[_0x516d7a(0x178)]=_0x516d7a(0x1a9);else _0x16568b['entryName']&&_0x16568b[_0x516d7a(0x178)][_0x516d7a(0x10e)](_0x516d7a(0x19b))&&(_0x16568b[_0x516d7a(0x178)]=_0x516d7a(0x117));const _0x34b684=_0x16568b[_0x516d7a(0x178)]||'未知条目';_0x39ebab=_0x5ee52f+':\x20'+_0x34b684;break;case'novel':_0x39ebab=_0x516d7a(0x137)+(_0x16568b[_0x516d7a(0x1a4)]||'未知小说');break;case'manual':default:_0x39ebab=_0x516d7a(0x14f)+_0x2667f4;break;}const _0x5eb899=Object[_0x516d7a(0x18f)](getKnowledgeBases()),_0x40313c=_0x5eb899[_0x516d7a(0x107)](_0xf0885d=>_0xf0885d[_0x516d7a(0x185)]===_0x39ebab);if(_0x40313c)_0x5eddb2=_0x40313c['id'],_0x43464a(_0x516d7a(0x154)+_0x39ebab+_0x516d7a(0x13f),'info');else{_0x43464a(_0x516d7a(0x1e9)+_0x39ebab+_0x516d7a(0x183),_0x516d7a(0x196));const _0x2af7be=addKnowledgeBase(_0x39ebab);_0x5eddb2=_0x2af7be['id'];}const _0x156fbf=getCharacterStableId(),_0x1d9667=_0x156fbf+'_'+_0x5eddb2;_0x43464a(_0x516d7a(0x13c)+_0x39ebab+_0x516d7a(0x155)+_0x1d9667+')',_0x516d7a(0x148)),_0x43464a(_0x516d7a(0x131)+_0x1d9667,'info'),_0x13daed({'message':'正在智能分块...','processed':0x0,'total':0x1});const _0x57a68e=splitIntoChunks(_0x779204,_0x1164b6,_0x16568b),_0x32a3ad=_0x57a68e['length'];if(_0x455cbd?.[_0x516d7a(0x127)])throw new Error(_0x516d7a(0x11a));_0x43464a('[翰林院-核心]\x20将来源\x27'+_0x39ebab+_0x516d7a(0xee)+_0x32a3ad+_0x516d7a(0xf0),'info');if(_0x32a3ad===0x0)return{'success':!![],'count':0x0};const _0x592c75=settings[_0x516d7a(0x16f)][_0x516d7a(0x1b1)]||0x5;let _0x30bb50=_0x35b44a;for(let _0x3ffcb1=_0x35b44a;_0x3ffcb1<_0x32a3ad;_0x3ffcb1+=_0x592c75){if(_0x455cbd?.[_0x516d7a(0x127)])throw new Error(_0x516d7a(0x11a));const _0xe82546=_0x57a68e[_0x516d7a(0x1d6)](_0x3ffcb1,_0x3ffcb1+_0x592c75);_0x13daed({'message':'正在处理\x20'+(_0x3ffcb1+0x1)+'-'+(_0x3ffcb1+_0xe82546['length'])+'\x20块','processed':_0x3ffcb1,'total':_0x32a3ad});const _0x597f47=_0xe82546['map'](_0x3fbd4b=>_0x3fbd4b['text']),_0x32b5dc=await getEmbeddings(_0x597f47,_0x455cbd);if(_0x455cbd?.[_0x516d7a(0x127)])throw new Error('AbortError');if(_0xe82546['length']!==_0x32b5dc[_0x516d7a(0x145)])throw new Error('文本块和向量数量不匹配');const _0x37c03d=_0xe82546[_0x516d7a(0x19f)]((_0x44a5ac,_0x48cfef)=>({..._0x44a5ac,'vector':_0x32b5dc[_0x48cfef]}));await insertVectors(_0x37c03d,_0x455cbd,_0x1d9667),_0x30bb50+=_0xe82546[_0x516d7a(0x145)],_0x2d9e5f&&_0x9fe58b[_0x516d7a(0x1ac)](_0x2d9e5f,_0x30bb50,_0x32a3ad),await _0x3645e7();}return _0x2d9e5f&&_0x9fe58b[_0x516d7a(0x1e7)](_0x2d9e5f),_0x43464a('[翰林院-核心]\x20成功插入\x20'+_0x30bb50+_0x516d7a(0x1eb),_0x516d7a(0x148)),{'success':!![],'count':_0x30bb50};}catch(_0x64f4ac){if(_0x64f4ac['name']===_0x516d7a(0x11a)){_0x43464a(_0x516d7a(0x19e),_0x516d7a(0x1ae));throw _0x64f4ac;}return console[_0x516d7a(0x135)]('[翰林院-核心]\x20ingestTextToHanlinyuan\x20失败:',_0x64f4ac),_0x43464a(_0x516d7a(0x1cd)+_0x64f4ac[_0x516d7a(0x181)],_0x516d7a(0x135)),{'success':![],'error':_0x64f4ac[_0x516d7a(0x181)]};}}function getSettings(){const _0x26fe37=_0x2dc8;if(!context||!context[_0x26fe37(0x1e8)])return structuredClone(_0xd3e1e);let _0x4322d3=context[_0x26fe37(0x1e8)][MODULE_NAME];!_0x4322d3&&(_0x4322d3={},context['extensionSettings'][MODULE_NAME]=_0x4322d3);_0x4322d3[_0x26fe37(0xf5)]===undefined&&(_0x4322d3[_0x26fe37(0xf5)]={});_0x4322d3['knowledgeBases']===undefined&&(_0x4322d3[_0x26fe37(0x11c)]={});for(const _0x44cd2c in _0xd3e1e){if(_0x4322d3[_0x44cd2c]===undefined)_0x4322d3[_0x44cd2c]=structuredClone(_0xd3e1e[_0x44cd2c]);else{if(typeof _0xd3e1e[_0x44cd2c]===_0x26fe37(0x12b)&&!Array[_0x26fe37(0x1d3)](_0xd3e1e[_0x44cd2c])&&_0xd3e1e[_0x44cd2c]!==null)for(const _0x5cdf63 in _0xd3e1e[_0x44cd2c]){_0x4322d3[_0x44cd2c][_0x5cdf63]===undefined&&(_0x4322d3[_0x44cd2c][_0x5cdf63]=_0xd3e1e[_0x44cd2c][_0x5cdf63]);}}}return _0x4322d3;}function saveSettings(){const _0x44c042=_0x2dc8;if(context)context[_0x44c042(0x16c)]();}function resetSettings(){const _0x482d6a=_0x2dc8;context&&(context[_0x482d6a(0x1e8)][MODULE_NAME]=structuredClone(_0xd3e1e),saveSettings());}function showNotification(_0x1e95cd,_0x504f21=_0x4826de(0x196)){toastr[_0x504f21](_0x1e95cd);}function getTagForSource(_0x2a97e1){const _0x37997b=_0x4826de;switch(_0x2a97e1){case _0x37997b(0x1c3):return _0x37997b(0x125);case _0x37997b(0x103):return _0x37997b(0x1ba);case _0x37997b(0x1d4):return _0x37997b(0x18c);case _0x37997b(0xfd):return _0x37997b(0x1a7);default:return'资料';}}function splitIntoChunks(_0x5ea746,_0x24f062,_0x174e30={}){const _0x4b02ca=_0x4826de;switch(_0x24f062){case _0x4b02ca(0xfd):return _chunkForNovel(_0x5ea746,_0x174e30);case _0x4b02ca(0x1c3):return _chunkForChatHistory(_0x5ea746,_0x174e30);case'lorebook':return _chunkForLorebook(_0x5ea746,_0x174e30);case _0x4b02ca(0x1d4):return _chunkForManual(_0x5ea746,_0x174e30);default:console[_0x4b02ca(0x1ae)]('[翰林院-分块]\x20未知的来源类型\x20\x27'+_0x24f062+_0x4b02ca(0x15c));return _chunkForManual(_0x5ea746,{..._0x174e30,'sourceName':_0x174e30['sourceName']||'未知来源'});}}function _chunkForNovel(_0x116afb,_0x337863){const _0x2c4d67=_0x4826de,{chunkSize:_0x1712c7,overlap:_0x4be31a}=settings['advanced'],{sourceName:sourceName='小说'}=_0x337863,_0x318296=[];if(!_0x116afb||_0x1712c7<=0x0)return _0x318296;const _0xd97e9a=/(第\s*[一二三四五六七八九十百千万零\d]+\s*卷)/gim,_0xbd20e9=/(第\s*[一二三四五六七八九十百千万零\d]+\s*[章回节部])|^(Chapter\s+\d+)/gim;let _0x6ce44=0x0;const _0x5ddb70=_0x116afb['split']('\x0a');let _0x20c2c4=_0x2c4d67(0x1ca),_0x2d4d2b=_0x2c4d67(0x141),_0x63d565=[];function _0x238c65(){const _0x363591=_0x2c4d67;if(_0x63d565[_0x363591(0x145)]===0x0)return;const _0x546835=_0x63d565[_0x363591(0x161)]('\x0a');let _0x2556e4=0x0,_0x32e358=0x1;while(_0x2556e4<_0x546835['length']){const _0x50d006=Math[_0x363591(0x1cc)](_0x2556e4+_0x1712c7,_0x546835[_0x363591(0x145)]),_0xc09843=_0x546835[_0x363591(0x1bd)](_0x2556e4,_0x50d006);if(_0xc09843[_0x363591(0x1e5)]()['length']>0x0){const _0x41e955={'source':_0x363591(0xfd),'sourceName':sourceName,'timestamp':new Date()['toISOString'](),'globalIndex':_0x6ce44++,'volume':_0x20c2c4,'chapter':_0x2d4d2b,'section':_0x32e358},_0x37611e=getTagForSource(_0x363591(0xfd)),_0x5f0844=_0x363591(0x149)+sourceName+',\x20'+_0x20c2c4+',\x20'+_0x2d4d2b+_0x363591(0x115)+_0x32e358+'节]',_0x397cf3='<'+_0x37611e+'>\x0a'+_0x5f0844+'\x0a'+_0xc09843+_0x363591(0x114)+_0x37611e+'>';_0x318296[_0x363591(0x16e)]({'text':_0x397cf3,'metadata':_0x41e955}),_0x32e358++;}_0x2556e4+=_0x1712c7-_0x4be31a;if(_0x2556e4>=_0x546835[_0x363591(0x145)])break;}_0x63d565=[];}for(const _0xf751f1 of _0x5ddb70){const _0x541642=_0xf751f1[_0x2c4d67(0x1e5)]();if(_0xd97e9a[_0x2c4d67(0x126)](_0x541642))_0x238c65(),_0x20c2c4=_0x541642,_0x2d4d2b=_0x2c4d67(0x141);else _0xbd20e9[_0x2c4d67(0x126)](_0x541642)?(_0x238c65(),_0x2d4d2b=_0x541642):_0x63d565['push'](_0xf751f1);}_0x238c65();if(_0x318296[_0x2c4d67(0x145)]===0x0&&_0x116afb[_0x2c4d67(0x145)]>0x0){let _0x3445be=0x0,_0x449fab=0x1;while(_0x3445be<_0x116afb[_0x2c4d67(0x145)]){const _0x38dc7c=Math[_0x2c4d67(0x1cc)](_0x3445be+_0x1712c7,_0x116afb['length']),_0x406b19=_0x116afb[_0x2c4d67(0x1bd)](_0x3445be,_0x38dc7c),_0x516aa7={'source':_0x2c4d67(0xfd),'sourceName':sourceName,'timestamp':new Date()[_0x2c4d67(0x17a)](),'globalIndex':_0x318296[_0x2c4d67(0x145)],'volume':_0x2c4d67(0x1ca),'chapter':_0x2c4d67(0x141),'section':_0x449fab},_0x2eca9d=getTagForSource(_0x2c4d67(0xfd)),_0x5223c9=_0x2c4d67(0x149)+sourceName+_0x2c4d67(0x1e6)+_0x449fab+'节]',_0x33e8e3='<'+_0x2eca9d+'>\x0a'+_0x5223c9+'\x0a'+_0x406b19+_0x2c4d67(0x114)+_0x2eca9d+'>';_0x318296[_0x2c4d67(0x16e)]({'text':_0x33e8e3,'metadata':_0x516aa7}),_0x449fab++,_0x3445be+=_0x1712c7-_0x4be31a;}}return _0x318296;}function _chunkForChatHistory(_0x2dec30,_0x18ae7e){const _0x5413ca=_0x4826de,{chunkSize:_0x1078c6,overlap:_0x502e29}=settings[_0x5413ca(0x1a1)],{floor:_0x1432ca,is_user:_0x2862a4,timestamp:_0x5c556b}=_0x18ae7e,_0x5752e3=[];if(!_0x2dec30||_0x1078c6<=0x0)return _0x5752e3;let _0x30a474=0x1,_0x22b9df=0x0;while(_0x22b9df<_0x2dec30[_0x5413ca(0x145)]){const _0x219e31=Math['min'](_0x22b9df+_0x1078c6,_0x2dec30[_0x5413ca(0x145)]),_0x4062c7=_0x2dec30['substring'](_0x22b9df,_0x219e31),_0x3a7129=_0x5413ca(0x1bc)+_0x1432ca+_0x5413ca(0x115)+_0x30a474+_0x5413ca(0x1d1),_0x2c61b6=getTagForSource(_0x5413ca(0x1c3)),_0x5109ec='<'+_0x2c61b6+'>\x0a'+_0x3a7129+'\x0a'+_0x4062c7+_0x5413ca(0x114)+_0x2c61b6+'>';_0x5752e3['push']({'text':_0x5109ec,'metadata':{'source':_0x5413ca(0x1c3),'sourceName':'聊天记录\x20#'+_0x1432ca,'floor':_0x1432ca,'part':_0x30a474,'is_user':_0x2862a4,'timestamp':_0x5c556b}}),_0x30a474++,_0x22b9df+=_0x1078c6-_0x502e29;if(_0x22b9df>=_0x2dec30[_0x5413ca(0x145)])break;}return _0x5752e3;}function _chunkForLorebook(_0x9ba664,_0x143dc5){const _0x5c1696=_0x4826de,{chunkSize:_0x4014e6,overlap:_0x395489}=settings[_0x5c1696(0x1a1)],{bookName:bookName=_0x5c1696(0x1ba),entryName:entryName='世界书条目'}=_0x143dc5,_0x2a0157=[];if(!_0x9ba664||_0x4014e6<=0x0)return _0x2a0157;let _0x28d924=0x1,_0x35fbac=0x0;while(_0x35fbac<_0x9ba664[_0x5c1696(0x145)]){const _0x3edf42=Math[_0x5c1696(0x1cc)](_0x35fbac+_0x4014e6,_0x9ba664[_0x5c1696(0x145)]),_0xaf4bdd=_0x9ba664[_0x5c1696(0x1bd)](_0x35fbac,_0x3edf42),_0x3b5eb4=_0x5c1696(0x149)+bookName+_0x5c1696(0x120)+entryName+',\x20第'+_0x28d924+_0x5c1696(0x1d1),_0xbf97f8=getTagForSource(_0x5c1696(0x103)),_0x12e7e4='<'+_0xbf97f8+'>\x0a'+_0x3b5eb4+'\x0a'+_0xaf4bdd+'\x0a';_0x2a0157[_0x5c1696(0x16e)]({'text':_0x12e7e4,'metadata':{'source':_0x5c1696(0x103),'sourceName':bookName+':\x20'+entryName,'bookName':bookName,'entryName':entryName,'part':_0x28d924,'timestamp':new Date()[_0x5c1696(0x17a)]()}}),_0x28d924++,_0x35fbac+=_0x4014e6-_0x395489;if(_0x35fbac>=_0x9ba664[_0x5c1696(0x145)])break;}return _0x2a0157;}function _chunkForManual(_0x8f09a2,_0x2777ea){const _0x32f87d=_0x4826de,{chunkSize:_0x38279f,overlap:_0x1c8136}=settings[_0x32f87d(0x1a1)],{sourceName:sourceName=_0x32f87d(0x18c)}=_0x2777ea,_0x598850=[];if(!_0x8f09a2||_0x38279f<=0x0)return _0x598850;const _0xdf5bd6=new Date(),_0x13df61=_0xdf5bd6[_0x32f87d(0x153)](_0x32f87d(0x176));let _0x1a3459=0x1,_0x1b5ecb=0x0;while(_0x1b5ecb<_0x8f09a2['length']){const _0x430a5b=Math[_0x32f87d(0x1cc)](_0x1b5ecb+_0x38279f,_0x8f09a2[_0x32f87d(0x145)]),_0x2b31eb=_0x8f09a2[_0x32f87d(0x1bd)](_0x1b5ecb,_0x430a5b),_0x559e8b=_0x32f87d(0x149)+sourceName+_0x32f87d(0x12a)+_0x13df61+_0x32f87d(0x115)+_0x1a3459+'部分]',_0x3b3a7b=getTagForSource(_0x32f87d(0x1d4)),_0x1c8d9f='<'+_0x3b3a7b+'>\x0a'+_0x559e8b+'\x0a'+_0x2b31eb+_0x32f87d(0x114)+_0x3b3a7b+'>';_0x598850[_0x32f87d(0x16e)]({'text':_0x1c8d9f,'metadata':{'source':'manual','sourceName':sourceName,'part':_0x1a3459,'timestamp':_0xdf5bd6[_0x32f87d(0x17a)]()}}),_0x1a3459++,_0x1b5ecb+=_0x38279f-_0x1c8136;if(_0x1b5ecb>=_0x8f09a2['length'])break;}return _0x598850;}import{getCollectionId as _0x47c456,getCharacterName}from'./utils/context-utils.js';async function getCollectionId(){return lockedCollectionId||await _0x47c456();}function _0x4d15(){const _0x4115d6=['notify','volume','[翰林院-迁移]\x20用户确认迁移,正在处理旧宝库:\x20','bianzhuan','4hxCNQs',')\x20的状态已切换为:\x20','saveSettingsDebounced','catch','push','retrieval','chapter','[翰林院-日志]\x20获取集合\x20','\x20补充所有者ID:\x20','\x27\x20中未找到ID为\x20','getRequestHeaders','[翰林院-日志]\x20开始获取所有知识库的向量总数...','zh-CN','[翰林院-核心]\x20清空向量集合\x20','entryName','\x20条结果。','toISOString','[翰林院-日志]\x20查询知识库\x20','results','[翰林院-日志]\x20/api/vector/purge\x20响应状态:\x20','depth','rerank','聊天记录\x20#','message','[翰林院-迁移]\x20旧宝库已清空。','\x22\x20创建专属知识库...','injection_','name','[翰林院-日志]\x20清空目标集合ID:\x20','floor','final_score','getTime','score','tiaomu','手动录入','quiet','8UTInGs','values','[翰林院-Rerank]\x20元数据加权排序完成。','[翰林院-日志]\x20所有知识库查询完毕,共获得\x20','No\x20messages\x20to\x20process.','...)','[翰林院-Rerank]\x20开始外部API重排序...','stringify','info','[翰林院-日志]\x20开始多知识库向量查询...','[翰林院-配置]\x20为旧版知识库\x20','\x20-\x20楼层\x20#','condensation','宏史卷总结','[翰林院-调试]\x20步骤2\x20-\x20rerankResults返回的最终结果:','\x20个条目。','[翰林院-核心]\x20文本录入任务被用户中止。','map','hashes','advanced','legacy','[翰林院-核心]\x20已为角色\x20','sourceName','template','hanlinyuanRagProcessor','小说录入','6450965gvVPAK','对话记录小总结','content','queryMessageCount','saveProgress','hasOwnProperty','warn','外部Rerank完成','global','batchSize','36QOIaJF','add','is_user','findIndex','messageTypes','\x20时发生网络错误:','1390DIFWHh','webllm','世界书','index','[来源:\x20聊天记录,\x20楼层:\x20#','substring','旧版宝库\x20(Legacy)','key','无法确定要清空的目标宝库。','[翰林院]\x20检索或注入时发生错误:','\x20及其向量数据。','chat_history','[翰林院-核心]\x20尝试删除一个不存在的知识库:\x20','start','initialized','getContext','[翰林院-日志]\x20发送到\x20/api/vector/purge\x20的请求体:','enabled','第1卷','text','min','[翰林院-核心]\x20文本录入失败:\x20','[翰林院-日志]\x20清空宝库API错误:','删除知识库失败,未能清空后端数据。','25065nrNUjT','部分]',']\x20的消息已成功凝识。','isArray','manual','[翰林院-核心]\x20processCondensation\x20失败:','slice','position','未分类世界书','\x20失败:\x20','$1','[翰林院]\x20已为来源\x20\x27','凝识之权未开启','[翰林院-核心]\x20成功删除知识库\x20','[翰林院-日志]\x20所有知识库统计完成,总向量数:\x20','user','_text}}','[翰林院-配置]\x20','[翰林院-日志]\x20清空宝库API调用成功。','[翰林院-Rerank]\x20外部Rerank失败,将仅使用内部加权。','\x20失败:','trim',',\x20第1卷,\x20第1章,\x20第','clearJob','extensionSettings','[翰林院-核心]\x20准备为任务\x20\x22','查询集合\x20','\x20个向量条目。','rearrangeChat','has','\x22\x20已删除。','用户取消了迁移操作','end','random','[翰林院-日志]\x20统计目标集合ID:\x20','忆识存入API错误\x20','输入文本为空','[翰林院-核心]\x20准备删除知识库\x20','[翰林院-修复]\x20最终返回数组样本:','\x20条消息分解为\x20','original_index','bookName','\x27的文本分割成\x20','reduce','\x20个块。','part','oldId','metadata','[翰林院]\x20未能获取SillyTavern上下文,初始化失败。','condensationHistory','status','source','depth_role','\x20添加新知识库:\x20','/api/vector/query','HANLINYUAN_RAG_LOREBOOK','\x20(ID:\x20','novel','892767YLSOxL','log','HANLINYUAN_RAG_CHAT','(已锁定:\x20','comment','lorebook','sort','[翰林院-核心]\x20聊天记录凝识完成,成功插入\x20','4187095TYAZfM','find','\x20列表API时出现问题\x20(状态:\x20','chat','[翰林院-日志]\x20没有启用的新知识库,尝试查询旧版单体宝库...','json','文本块和向量数量不匹配','检测到旧版数据。此操作将把旧数据迁移到新格式,过程不可逆,是否继续?','includes','未知角色','\x20(范围:\x20','scope','\x20不存在,计为\x200。','966128gpyZqs','\x0a_0x55b056[_0x590775(0x1c9)]),_0xb84638=Object[_0x590775(0x18f)](_0x536258)[_0x590775(0x150)](_0x426cbd=>_0x426cbd[_0x590775(0x1c9)]),_0xee5ecd=[..._0x2faffa[_0x590775(0x19f)](_0x505f83=>({..._0x505f83,'scope':_0x590775(0x165)})),..._0xb84638[_0x590775(0x19f)](_0x5e4565=>({..._0x5e4565,'scope':'global'}))];if(_0xee5ecd['length']===0x0){console[_0x590775(0xff)](_0x590775(0x10a));const _0x24ccf0=await _0x47c456();if(!_0x24ccf0)return[];_0xee5ecd[_0x590775(0x16e)]({'id':null,'name':_0x590775(0x1be),'scope':_0x590775(0x1a2)});}const _0x1f8f11=(await getEmbeddings([_0x2af60e]))[0x0];let _0x7c9a0b=[];const _0x53e941=_0xee5ecd[_0x590775(0x19f)](_0x421cb1=>{const _0x2e354b=_0x590775;let _0x5a2717;if(_0x421cb1[_0x2e354b(0x111)]==='legacy')_0x5a2717=_0x47c456();else{const _0x472c53=_0x421cb1[_0x2e354b(0x111)]===_0x2e354b(0x1b0)?_0x421cb1[_0x2e354b(0x15e)]||GLOBAL_SCOPE_ID:_0x34f5d2;_0x5a2717=Promise['resolve'](_0x472c53+'_'+_0x421cb1['id']);}return _0x5a2717[_0x2e354b(0x138)](_0x3437e1=>{const _0x2dfadc=_0x2e354b;if(!_0x3437e1)return[];console[_0x2dfadc(0xff)]('[翰林院-日志]\x20正在查询知识库:\x20'+_0x421cb1[_0x2dfadc(0x185)]+_0x2dfadc(0xfc)+_0x3437e1+')');const _0x24ec07={'collectionId':_0x3437e1,'searchText':_0x2af60e,'topK':settings[_0x2dfadc(0x1a1)]['maxResults'],'threshold':settings[_0x2dfadc(0x1a1)]['matchThreshold'],'source':_0x2dfadc(0x1b9),'embeddings':{[_0x2af60e]:_0x1f8f11}};return fetch(_0x2dfadc(0xfa),{'method':'POST','headers':context[_0x2dfadc(0x174)](),'body':JSON[_0x2dfadc(0x195)](_0x24ec07)})[_0x2dfadc(0x138)](async _0x50ad6d=>{const _0x277db0=_0x2dfadc;if(!_0x50ad6d['ok']){const _0x31d289=await _0x50ad6d[_0x277db0(0x1cb)]();return console[_0x277db0(0x135)](_0x277db0(0x17b)+_0x3437e1+_0x277db0(0x1e4),_0x31d289),[];}const _0x3eb946=await _0x50ad6d[_0x277db0(0x10b)]();let _0x547776=[];if(Array[_0x277db0(0x1d3)](_0x3eb946))_0x547776=_0x3eb946;else{if(_0x3eb946&&_0x3eb946['metadata']&&Array[_0x277db0(0x1d3)](_0x3eb946[_0x277db0(0xf3)]))_0x547776=_0x3eb946['metadata'];else{if(_0x3eb946&&_0x3eb946[_0x277db0(0x17c)]&&Array['isArray'](_0x3eb946[_0x277db0(0x17c)]))_0x547776=_0x3eb946[_0x277db0(0x17c)];else _0x3eb946&&_0x3eb946[_0x277db0(0x14c)]&&Array[_0x277db0(0x1d3)](_0x3eb946[_0x277db0(0x14c)])&&(_0x547776=_0x3eb946[_0x277db0(0x14c)]);}}const _0x597b33=_0x547776['map'](_0x503486=>{const _0x4bea31=_0x277db0;if(!_0x503486||typeof _0x503486[_0x4bea31(0x1cb)]!==_0x4bea31(0x14b))return null;const _0x4a19b0={'source':_0x4bea31(0x11d),'sourceName':'未知'},_0x1e26f2=_0x503486[_0x4bea31(0x1cb)]['match'](/^<([^>]+)>/),_0x5b2372=_0x1e26f2?_0x1e26f2[0x1]:'';switch(_0x5b2372){case _0x4bea31(0x125):_0x4a19b0['source']=_0x4bea31(0x1c3);const _0x537e55=_0x503486[_0x4bea31(0x1cb)][_0x4bea31(0x140)](/楼层:\s*#(\d+),\s*第(\d+)部分/);_0x537e55&&_0x537e55[0x1]&&_0x537e55[0x2]&&(_0x4a19b0[_0x4bea31(0x187)]=parseInt(_0x537e55[0x1],0xa),_0x4a19b0[_0x4bea31(0xf1)]=parseInt(_0x537e55[0x2],0xa),_0x4a19b0[_0x4bea31(0x1a4)]=_0x4bea31(0x180)+_0x4a19b0[_0x4bea31(0x187)]);break;case'世界书':_0x4a19b0[_0x4bea31(0xf7)]=_0x4bea31(0x103);const _0x5a107e=_0x503486['text'][_0x4bea31(0x140)](/\[来源:\s*([^,]+),\s*条目:\s*([^,]+),\s*第(\d+)部分\]/);_0x5a107e&&_0x5a107e[0x1]&&_0x5a107e[0x2]&&_0x5a107e[0x3]&&(_0x4a19b0[_0x4bea31(0xed)]=_0x5a107e[0x1]['trim'](),_0x4a19b0[_0x4bea31(0x178)]=_0x5a107e[0x2][_0x4bea31(0x1e5)](),_0x4a19b0[_0x4bea31(0xf1)]=parseInt(_0x5a107e[0x3],0xa),_0x4a19b0[_0x4bea31(0x1a4)]=_0x4a19b0[_0x4bea31(0xed)]+':\x20'+_0x4a19b0[_0x4bea31(0x178)]);break;case _0x4bea31(0x18c):_0x4a19b0[_0x4bea31(0xf7)]=_0x4bea31(0x1d4);const _0x97199f=_0x503486[_0x4bea31(0x1cb)]['match'](/\[来源:\s*([^,]+),.*第(\d+)部分\]/);_0x97199f&&_0x97199f[0x1]&&_0x97199f[0x2]&&(_0x4a19b0['sourceName']=_0x97199f[0x1]['trim'](),_0x4a19b0[_0x4bea31(0xf1)]=parseInt(_0x97199f[0x2],0xa));break;case _0x4bea31(0x1a7):_0x4a19b0[_0x4bea31(0xf7)]=_0x4bea31(0xfd);const _0x31e01b=_0x503486[_0x4bea31(0x1cb)][_0x4bea31(0x140)](/\[来源:\s*([^,]+),\s*([^,]+),\s*([^,]+),\s*([^\]]+)\]/);_0x31e01b&&(_0x4a19b0[_0x4bea31(0x1a4)]=_0x31e01b[0x1][_0x4bea31(0x1e5)](),_0x4a19b0[_0x4bea31(0x167)]=_0x31e01b[0x2]['trim'](),_0x4a19b0[_0x4bea31(0x170)]=_0x31e01b[0x3][_0x4bea31(0x1e5)](),_0x4a19b0[_0x4bea31(0x129)]=_0x31e01b[0x4][_0x4bea31(0x1e5)]());break;}return{..._0x503486,'score':_0x503486[_0x4bea31(0x18a)]||0x1,'metadata':_0x4a19b0};})['filter'](Boolean);return console[_0x277db0(0xff)]('[翰林院-V13\x20修复]\x20重建元数据后,知识库\x20'+_0x421cb1[_0x277db0(0x185)]+'\x20返回\x20'+_0x597b33[_0x277db0(0x145)]+_0x277db0(0x179)),_0x597b33;})[_0x2dfadc(0x16d)](_0x3e6c2c=>{const _0x508190=_0x2dfadc;return console[_0x508190(0x135)](_0x508190(0x17b)+_0x3437e1+_0x508190(0x1b7),_0x3e6c2c),[];});});}),_0x1f20c4=await Promise[_0x590775(0x142)](_0x53e941);_0x7c9a0b=_0x1f20c4['flat'](),console['log'](_0x590775(0x191)+_0x7c9a0b['length']+'\x20条初步结果。');const _0x4fb4cb=[],_0x2efd6c=new Set();for(const _0x4b8d99 of _0x7c9a0b){if(_0x4b8d99&&typeof _0x4b8d99===_0x590775(0x12b)&&_0x4b8d99['text']&&typeof _0x4b8d99[_0x590775(0x1cb)]==='string'){const _0x4c376b=_0x4b8d99[_0x590775(0x1cb)][_0x590775(0x1e5)]();_0x4c376b[_0x590775(0x145)]>0x0&&!_0x2efd6c[_0x590775(0x1ed)](_0x4c376b)&&(_0x2efd6c[_0x590775(0x1b3)](_0x4c376b),_0x4fb4cb[_0x590775(0x16e)](_0x4b8d99));}}console['log']('[翰林院-日志]\x20去重后剩余\x20'+_0x4fb4cb[_0x590775(0x145)]+_0x590775(0x179)),_0x4fb4cb[_0x590775(0x104)]((_0x80f89e,_0x1c725b)=>(_0x1c725b[_0x590775(0x18a)]||0x0)-(_0x80f89e[_0x590775(0x18a)]||0x0));const _0x4ae32c=[..._0x4fb4cb];return console[_0x590775(0xff)]('[翰林院-修复]\x20最终返回数组长度:\x20'+_0x4ae32c[_0x590775(0x145)]),console[_0x590775(0xff)](_0x590775(0xea),JSON[_0x590775(0x195)](_0x4ae32c[_0x590775(0x1d6)](0x0,0x1),null,0x2)),_0x4ae32c;}async function insertVectors(_0x5967fa,_0x4ff723=null,_0x28568e){const _0x38df19=_0x4826de;if(!_0x28568e)throw new Error('insertVectors\x20必须接收一个有效的\x20collectionId\x20参数。');if(_0x5967fa[_0x38df19(0x145)]===0x0)return{'success':!![],'count':0x0};const _0xe14954=_0x5967fa[_0x38df19(0x19f)]((_0x2213d1,_0x3285fd)=>({'hash':generateHash(_0x2213d1['text']+Date[_0x38df19(0x121)]()+_0x3285fd),'text':_0x2213d1[_0x38df19(0x1cb)],'metadata':_0x2213d1[_0x38df19(0xf3)]||{'source':_0x38df19(0x11d),'timestamp':new Date()['toISOString']()}})),_0x4cb514=_0xe14954[_0x38df19(0xef)]((_0x18aec1,_0x598ff6,_0xa0bf9a)=>{return _0x18aec1[_0x598ff6['text']]=_0x5967fa[_0xa0bf9a]['vector'],_0x18aec1;},{}),_0x4bf5ee={'collectionId':_0x28568e,'items':_0xe14954,'source':_0x38df19(0x1b9),'embeddings':_0x4cb514},_0x404074=await fetch('/api/vector/insert',{'method':'POST','headers':context[_0x38df19(0x174)](),'body':JSON[_0x38df19(0x195)](_0x4bf5ee),'signal':_0x4ff723});if(!_0x404074['ok']){const _0x51d7c2=await _0x404074[_0x38df19(0x1cb)]();console[_0x38df19(0x135)](_0x38df19(0x15d),_0x51d7c2);throw new Error(_0x38df19(0xe7)+_0x404074[_0x38df19(0xf6)]+':\x20'+_0x51d7c2);}return{'success':!![],'count':_0xe14954['length']};}async function getVectorCount(_0x42d290=null,_0x427ced='local'){const _0x4bdc16=_0x4826de,_0x27c604=getCharacterStableId();if(_0x42d290){const _0x4c93b5=_0x427ced===_0x4bdc16(0x1b0)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x2d375e=_0x4c93b5[_0x42d290];if(!_0x2d375e)return console[_0x4bdc16(0x1ae)]('[翰林院-计数]\x20在作用域\x20\x27'+_0x427ced+'\x27\x20中未找到ID为\x20'+_0x42d290+_0x4bdc16(0x119)),0x0;const _0x448347=_0x427ced===_0x4bdc16(0x1b0)?_0x2d375e[_0x4bdc16(0x15e)]||GLOBAL_SCOPE_ID:_0x27c604,_0x21aec5=_0x448347+'_'+_0x42d290;return await countVectorsInCollection(_0x21aec5);}else{console[_0x4bdc16(0xff)](_0x4bdc16(0x175));const _0x5a2cc7=Object[_0x4bdc16(0x18f)](getLocalKnowledgeBases()),_0x5864cf=Object[_0x4bdc16(0x18f)](getGlobalKnowledgeBases()),_0x4c58b0=[];_0x5a2cc7[_0x4bdc16(0x147)](_0xe3d99=>{const _0xace8d=_0x4bdc16,_0x258543=_0x27c604+'_'+_0xe3d99['id'];_0x4c58b0[_0xace8d(0x16e)](countVectorsInCollection(_0x258543));}),_0x5864cf[_0x4bdc16(0x147)](_0x5bd14d=>{const _0x152d3a=_0x4bdc16,_0x5625d5=_0x5bd14d[_0x152d3a(0x15e)]||GLOBAL_SCOPE_ID,_0x51a9d9=_0x5625d5+'_'+_0x5bd14d['id'];_0x4c58b0['push'](countVectorsInCollection(_0x51a9d9));});const _0x62acbc=await _0x47c456();_0x4c58b0['push'](countVectorsInCollection(_0x62acbc));const _0x678ebe=await Promise['all'](_0x4c58b0),_0x2ec326=_0x678ebe[_0x4bdc16(0xef)]((_0x471e5e,_0x13b710)=>_0x471e5e+_0x13b710,0x0);return console['log'](_0x4bdc16(0x1de)+_0x2ec326),_0x2ec326;}}async function countVectorsInCollection(_0x3363c3){const _0x3f1ecf=_0x4826de;if(!_0x3363c3)return 0x0;console[_0x3f1ecf(0xff)](_0x3f1ecf(0xe6)+_0x3363c3);const _0x1ece6c={'collectionId':_0x3363c3,'source':_0x3f1ecf(0x1b9),'embeddings':{}};try{const _0x1664f5=await fetch(_0x3f1ecf(0x134),{'method':_0x3f1ecf(0x159),'headers':context[_0x3f1ecf(0x174)](),'body':JSON['stringify'](_0x1ece6c)});if(!_0x1664f5['ok']){if(_0x1664f5[_0x3f1ecf(0xf6)]===0x194)console[_0x3f1ecf(0xff)]('[翰林院-日志]\x20集合\x20'+_0x3363c3+_0x3f1ecf(0x112));else{const _0x3df3e6=await _0x1664f5['text']();console[_0x3f1ecf(0x1ae)](_0x3f1ecf(0x171)+_0x3363c3+_0x3f1ecf(0x108)+_0x1664f5[_0x3f1ecf(0xf6)]+'):',_0x3df3e6);}return 0x0;}const _0x38bad8=await _0x1664f5[_0x3f1ecf(0x10b)]();let _0x12138a=0x0;if(Array['isArray'](_0x38bad8))_0x12138a=_0x38bad8['length'];else _0x38bad8&&_0x38bad8['hashes']&&(_0x12138a=_0x38bad8[_0x3f1ecf(0x1a0)]['length']);return _0x12138a;}catch(_0x3848d5){return console[_0x3f1ecf(0x135)](_0x3f1ecf(0x132)+_0x3363c3+'\x20时发生网络错误:',_0x3848d5),0x0;}}async function purgeStorage(_0x2fe537=null){const _0x4d699a=_0x4826de;console[_0x4d699a(0xff)]('[翰林院-日志]\x20开始清空宝库...');const _0x331b9f=_0x2fe537||await getCollectionId();if(!_0x331b9f)return console[_0x4d699a(0x135)]('[翰林院-日志]\x20无法确定要清空的目标集合ID。'),toastr[_0x4d699a(0x135)](_0x4d699a(0x1c0)),![];console[_0x4d699a(0xff)](_0x4d699a(0x186)+_0x331b9f);const _0x22c62d={'collectionId':_0x331b9f};console[_0x4d699a(0xff)](_0x4d699a(0x1c8),JSON[_0x4d699a(0x195)](_0x22c62d,null,0x2));const _0x47e85c=await fetch('/api/vector/purge',{'method':'POST','headers':context[_0x4d699a(0x174)](),'body':JSON[_0x4d699a(0x195)](_0x22c62d)});console[_0x4d699a(0xff)](_0x4d699a(0x17d)+_0x47e85c[_0x4d699a(0xf6)]);if(!_0x47e85c['ok']){const _0x33fe37=await _0x47e85c[_0x4d699a(0x1cb)]();console[_0x4d699a(0x135)](_0x4d699a(0x1ce),_0x33fe37);}else console[_0x4d699a(0xff)](_0x4d699a(0x1e2));return _0x47e85c['ok'];}function _0x2dc8(_0x3924ff,_0xce16df){const _0x4d15af=_0x4d15();return _0x2dc8=function(_0x2dc84a,_0x42e9b7){_0x2dc84a=_0x2dc84a-0xe5;let _0x4b1052=_0x4d15af[_0x2dc84a];return _0x4b1052;},_0x2dc8(_0x3924ff,_0xce16df);}function getMessagesForCondensation(_0x423fcb=null){const _0x354069=_0x4826de;if(!settings[_0x354069(0x19a)][_0x354069(0x1c9)])return showNotification(_0x354069(0x1dc),_0x354069(0x160)),[];const {layerStart:_0x8182ed,layerEnd:_0x3aeab3}=settings[_0x354069(0x19a)],_0x38012a=_0x423fcb||settings[_0x354069(0x19a)][_0x354069(0x1b6)],_0x35dffd=context[_0x354069(0x109)][_0x354069(0x145)],_0x3bb5b6=Math[_0x354069(0x144)](0x0,_0x8182ed-0x1),_0x1d0e57=_0x3aeab3===0x0||_0x3aeab3>_0x35dffd?_0x35dffd:Math[_0x354069(0x1cc)](_0x35dffd,_0x3aeab3),_0x5d3404=context[_0x354069(0x109)][_0x354069(0x1d6)](_0x3bb5b6,_0x1d0e57);return _0x5d3404[_0x354069(0x150)](_0xb823f1=>{const _0x1a450f=_0x354069,_0x1d003e=_0xb823f1['is_user']===!![],_0x5d323f=_0xb823f1[_0x1a450f(0x1b4)]===![];if(!_0xb823f1[_0x1a450f(0x130)]||!_0xb823f1[_0x1a450f(0x130)][_0x1a450f(0x1e5)]())return![];return _0x38012a[_0x1a450f(0x1df)]&&_0x1d003e||_0x38012a['ai']&&_0x5d323f;});}async function processCondensation(_0x5da8c7,_0xdcae52=()=>{},_0x3a5dff=null){const _0x5e3354=_0x4826de;if(!_0x5da8c7||_0x5da8c7[_0x5e3354(0x145)]===0x0)return{'success':![],'error':_0x5e3354(0x192)};try{let _0x268584,_0x52f2ce;const _0x40f6b8=getCharacterName()||_0x5e3354(0x10f);if(_0x3a5dff){const _0x4aec64=_0x3a5dff[_0x5e3354(0x1c5)]??'?',_0x51daf7=_0x3a5dff['end']===0x0?'末':_0x3a5dff[_0x5e3354(0x1f0)]??'?';_0x268584=_0x40f6b8+':\x20'+_0x4aec64+'楼-'+_0x51daf7+'楼';}else{const _0x41f38f=new Date()[_0x5e3354(0x153)](_0x5e3354(0x176),{'hour12':![]});_0x268584=_0x5e3354(0x152)+_0x41f38f;}const _0x185d8e=Object['values'](getLocalKnowledgeBases()),_0x9aff85=_0x185d8e[_0x5e3354(0x107)](_0x3dfc94=>_0x3dfc94['name']===_0x268584);if(_0x9aff85)_0x52f2ce=_0x9aff85['id'],_0xdcae52(_0x5e3354(0x154)+_0x268584+_0x5e3354(0x13f),'info');else{_0xdcae52(_0x5e3354(0x1e9)+_0x268584+'\x22\x20创建专属知识库...','info');const _0x5685b8=addKnowledgeBase(_0x268584);_0x52f2ce=_0x5685b8['id'];}const _0x34bb71=getCharacterStableId(),_0x34cd15=_0x34bb71+'_'+_0x52f2ce;_0xdcae52(_0x5e3354(0x11b)+_0x268584+_0x5e3354(0x155)+_0x34cd15+')','success');const _0x54ac98=[],_0x18eeb4=context[_0x5e3354(0x109)];for(const _0x5d8b8f of _0x5da8c7){const _0x2d775c=(_0x5d8b8f[_0x5e3354(0x130)]||'')[_0x5e3354(0x14e)](/<[^>]*>/g,'')[_0x5e3354(0x1e5)]();if(_0x2d775c[_0x5e3354(0x145)]===0x0)continue;let _0x3a8f0a;if(_0x5d8b8f[_0x5e3354(0x187)]!==undefined&&_0x5d8b8f[_0x5e3354(0x187)]!==null)_0x3a8f0a=_0x5d8b8f[_0x5e3354(0x187)];else{const _0x5e651b=_0x18eeb4[_0x5e3354(0x1b5)](_0xf17715=>_0xf17715===_0x5d8b8f);_0x3a8f0a=_0x5e651b!==-0x1?_0x5e651b+0x1:-0x1;}const _0x2738=new Date(_0x5d8b8f['send_date']),_0x21e2ba=isNaN(_0x2738[_0x5e3354(0x189)]())?new Date()['toISOString']():_0x2738[_0x5e3354(0x17a)](),_0x2c0651=splitIntoChunks(_0x2d775c,'chat_history',{'floor':_0x3a8f0a,'is_user':_0x5d8b8f[_0x5e3354(0x1b4)],'timestamp':_0x21e2ba});_0x54ac98[_0x5e3354(0x16e)](..._0x2c0651);}if(_0x54ac98[_0x5e3354(0x145)]===0x0)return{'success':!![],'count':0x0};_0xdcae52(_0x5e3354(0x157)+_0x5da8c7[_0x5e3354(0x145)]+_0x5e3354(0xeb)+_0x54ac98['length']+_0x5e3354(0x133),_0x5e3354(0x196));const _0x3bd26c=settings[_0x5e3354(0x16f)][_0x5e3354(0x1b1)]||0x5;let _0x56cf1d=0x0;for(let _0x7313b4=0x0;_0x7313b4<_0x54ac98['length'];_0x7313b4+=_0x3bd26c){const _0xd09ddd=_0x54ac98[_0x5e3354(0x1d6)](_0x7313b4,_0x7313b4+_0x3bd26c),_0x27e8a3=_0xd09ddd[_0x5e3354(0x19f)](_0x4920eb=>_0x4920eb['text']),_0x8216ab=await getEmbeddings(_0x27e8a3);if(_0xd09ddd[_0x5e3354(0x145)]!==_0x8216ab[_0x5e3354(0x145)])throw new Error(_0x5e3354(0x10c));const _0x2e23e7=_0xd09ddd[_0x5e3354(0x19f)]((_0x22b775,_0x3f9363)=>({..._0x22b775,'vector':_0x8216ab[_0x3f9363]}));await insertVectors(_0x2e23e7,null,_0x34cd15),_0x56cf1d+=_0xd09ddd[_0x5e3354(0x145)];}if(_0x3a5dff){const _0x3965e7=_0x3a5dff[_0x5e3354(0x1f0)]===0x0?context[_0x5e3354(0x109)][_0x5e3354(0x145)]:_0x3a5dff[_0x5e3354(0x1f0)],_0x329476=getCharacterStableId();!settings[_0x5e3354(0xf5)][_0x329476]&&(settings[_0x5e3354(0xf5)][_0x329476]={}),settings[_0x5e3354(0xf5)][_0x329476][_0x34cd15]={'start':_0x3a5dff[_0x5e3354(0x1c5)],'end':_0x3965e7,'timestamp':new Date()[_0x5e3354(0x17a)]()},saveSettings(),_0xdcae52(_0x5e3354(0x14d)+_0x34cd15+'\x20记录凝识范围:\x20'+_0x3a5dff[_0x5e3354(0x1c5)]+'-'+_0x3965e7,_0x5e3354(0x196));}_0xdcae52(_0x5e3354(0x105)+_0x56cf1d+_0x5e3354(0x19d),_0x5e3354(0x148));const _0x30d15b=_0x5da8c7[_0x5e3354(0x19f)](_0x20cfd6=>{const _0x4e74e1=_0x5e3354,_0x5514f3=_0x18eeb4[_0x4e74e1(0x1b5)](_0x467c63=>_0x467c63===_0x20cfd6),_0x36db24=_0x5514f3!==-0x1?_0x5514f3+0x1:-0x1,_0x124beb=_0x20cfd6['is_user']?'用户':getCharacterName()||'AI';return'['+_0x124beb+_0x4e74e1(0x199)+_0x36db24+_0x4e74e1(0x1d2);});return{'success':!![],'count':_0x56cf1d,'messages':_0x30d15b};}catch(_0x45f0e6){return console[_0x5e3354(0x135)](_0x5e3354(0x1d5),_0x45f0e6),_0xdcae52(_0x5e3354(0x146)+_0x45f0e6[_0x5e3354(0x181)],'error'),{'success':![],'error':_0x45f0e6['message']};}}async function rerankResults(_0x7a5ecc,_0x350b1a,_0x2c2577){const _0x4fc55a=_0x4826de;let _0xf4a4c8=_0x7a5ecc;if(_0x2c2577[_0x4fc55a(0x17f)][_0x4fc55a(0x1c9)]&&_0x7a5ecc['length']>0x0){console[_0x4fc55a(0xff)](_0x4fc55a(0x194));try{const _0x41c6ff=_0x7a5ecc[_0x4fc55a(0x19f)](_0x4858e4=>_0x4858e4['text']),_0x3a7a09=await executeRerank(_0x350b1a,_0x41c6ff,_0x2c2577[_0x4fc55a(0x17f)]),_0x56022b=_0x7a5ecc['map']((_0x36c910,_0x7e4ef3)=>({..._0x36c910,'original_index':_0x7e4ef3}));_0xf4a4c8=_0x56022b['map'](_0x24201c=>{const _0x4f4998=_0x4fc55a,_0x4c4613=_0x3a7a09[_0x4f4998(0x17c)][_0x4f4998(0x107)](_0x2e502b=>_0x2e502b[_0x4f4998(0x1bb)]===_0x24201c[_0x4f4998(0xec)]),_0x3203ba=_0x4c4613?_0x4c4613['relevance_score']:0x0;return{..._0x24201c,'rerank_score':_0x3203ba};});if(_0x2c2577[_0x4fc55a(0x17f)][_0x4fc55a(0x166)])showNotification(_0x4fc55a(0x1af),'success');}catch(_0x4291c5){console['error'](_0x4fc55a(0x1e3),_0x4291c5);if(_0x2c2577['rerank'][_0x4fc55a(0x166)])showNotification(_0x4fc55a(0x136)+_0x4291c5[_0x4fc55a(0x181)],_0x4fc55a(0x135));_0xf4a4c8[_0x4fc55a(0x147)](_0x30e7c6=>_0x30e7c6['rerank_score']=0x0);}}else _0xf4a4c8['forEach'](_0xf221d4=>_0xf221d4[_0x4fc55a(0x12f)]=0x0);console[_0x4fc55a(0xff)](_0x4fc55a(0x164));const _0x450699=context['chat'][_0x4fc55a(0x145)],_0x1e315e=_0x2c2577[_0x4fc55a(0x17f)]['hybrid_alpha'],_0x140e7f=_0xf4a4c8[_0x4fc55a(0x19f)](_0x1dfc8e=>{const _0x116f60=_0x4fc55a;let _0x26fe77=0x1;const _0x40745c=_0x1dfc8e[_0x116f60(0xf3)]||{};switch(_0x40745c['source']){case _0x116f60(0x103):_0x26fe77*=1.2;break;case _0x116f60(0x1d4):_0x26fe77*=1.1;break;case _0x116f60(0x1c3):if(_0x40745c[_0x116f60(0x187)]&&_0x450699>0x0){const _0x41d656=_0x40745c[_0x116f60(0x187)]/_0x450699;_0x26fe77*=0x1+_0x41d656;}break;}const _0x375459=_0x1dfc8e[_0x116f60(0x12f)]*_0x1e315e+(_0x1dfc8e[_0x116f60(0x18a)]||0x0)*(0x1-_0x1e315e),_0x462330=_0x375459*_0x26fe77;return{'text':_0x1dfc8e['text'],'score':_0x1dfc8e['score'],'rerank_score':_0x1dfc8e[_0x116f60(0x12f)],'final_score':_0x462330,'metadata':_0x1dfc8e[_0x116f60(0xf3)]};});_0x140e7f[_0x4fc55a(0x104)]((_0xe3eb67,_0x1ab90a)=>(_0x1ab90a[_0x4fc55a(0x188)]||0x0)-(_0xe3eb67[_0x4fc55a(0x188)]||0x0)),console[_0x4fc55a(0xff)](_0x4fc55a(0x190));if(_0x2c2577[_0x4fc55a(0x17f)]['superSortEnabled']){const _0x478c2d=superSort(_0x140e7f);return _0x478c2d[_0x4fc55a(0x1d6)](0x0,_0x2c2577[_0x4fc55a(0x17f)][_0x4fc55a(0x123)]);}return _0x140e7f[_0x4fc55a(0x1d6)](0x0,_0x2c2577[_0x4fc55a(0x17f)][_0x4fc55a(0x123)]);}async function rearrangeChat(_0x5811a4,_0x2f7ad4,_0x50e774,_0x516482){const _0x56c2e3=_0x4826de,_0x328789={'novel':_0x56c2e3(0x13a),'chat_history':_0x56c2e3(0x100),'lorebook':_0x56c2e3(0xfb),'manual':_0x56c2e3(0x122)};Object['values'](_0x328789)['forEach'](_0x596e56=>{setExtensionPrompt(_0x596e56,'',0x0,0x0,![],0x0);});if(_0x516482===_0x56c2e3(0x18d)||!settings[_0x56c2e3(0x16f)][_0x56c2e3(0x1c9)])return;const _0x12d70d=_0x5811a4[_0x56c2e3(0x1d6)](-settings[_0x56c2e3(0x1a1)][_0x56c2e3(0x1ab)]);if(_0x12d70d[_0x56c2e3(0x145)]===0x0)return;const _0x4fc7d6=_0x12d70d[_0x56c2e3(0x19f)](_0x109e31=>_0x109e31['mes'])[_0x56c2e3(0x161)]('\x20')[_0x56c2e3(0x14e)](/<[^>]*>/g,'')[_0x56c2e3(0x1e5)]();if(!_0x4fc7d6)return;try{const _0x4f9d29=await queryVectors(_0x4fc7d6);console[_0x56c2e3(0xff)](_0x56c2e3(0x13e),JSON['stringify'](_0x4f9d29[_0x56c2e3(0x19f)](_0x4cc4b7=>_0x4cc4b7[_0x56c2e3(0xf3)]),null,0x2));if(_0x4f9d29['length']===0x0)return;const _0x231a8a=await rerankResults(_0x4f9d29,_0x4fc7d6,settings);if(_0x231a8a['length']===0x0)return;console[_0x56c2e3(0xff)](_0x56c2e3(0x19c),JSON[_0x56c2e3(0x195)](_0x231a8a[_0x56c2e3(0x19f)](_0x38033d=>_0x38033d['metadata']),null,0x2));const _0x4b2530={'novel':[],'chat_history':[],'lorebook':[],'manual':[]};_0x231a8a['forEach'](_0x5dd174=>{const _0x1410a9=_0x56c2e3,_0x445d31=_0x5dd174[_0x1410a9(0xf3)]?.[_0x1410a9(0xf7)];_0x445d31&&_0x4b2530[_0x1410a9(0x1ad)](_0x445d31)&&_0x4b2530[_0x445d31][_0x1410a9(0x16e)](_0x5dd174);}),console[_0x56c2e3(0xff)](_0x56c2e3(0x162),JSON['stringify'](Object['keys'](_0x4b2530)[_0x56c2e3(0xef)]((_0x541bed,_0x1a21d4)=>{return _0x541bed[_0x1a21d4]=_0x4b2530[_0x1a21d4]['length'],_0x541bed;},{}),null,0x2));for(const _0x19c9c7 in _0x4b2530){const _0x10e456=_0x4b2530[_0x19c9c7];if(_0x10e456[_0x56c2e3(0x145)]===0x0)continue;const _0x301ff0=settings[_0x56c2e3(0x184)+_0x19c9c7[_0x56c2e3(0x14e)](_0x56c2e3(0x11e),'')];if(!_0x301ff0){console['warn'](_0x56c2e3(0x15a)+_0x19c9c7+'\x27\x20的注入设置,跳过处理。');continue;}const _0x3b799=_0x10e456[_0x56c2e3(0x19f)](_0x5c895d=>_0x5c895d['text'])[_0x56c2e3(0x161)]('\x0a\x0a'),_0xf4f780='{{'+_0x19c9c7[_0x56c2e3(0x14e)](_0x56c2e3(0x11e),'')+_0x56c2e3(0x1e0);let _0x1a4d36=_0x301ff0[_0x56c2e3(0x1a5)][_0x56c2e3(0x14e)](_0xf4f780,_0x3b799);_0x1a4d36[_0x56c2e3(0x1e5)]()&&(_0x1a4d36='%%'+_0x328789[_0x19c9c7]+'%%'+_0x1a4d36),setExtensionPrompt(_0x328789[_0x19c9c7],_0x1a4d36,_0x301ff0[_0x56c2e3(0x1d7)],_0x301ff0[_0x56c2e3(0x17e)],![],_0x301ff0[_0x56c2e3(0xf8)]),console['log'](_0x56c2e3(0x1db)+_0x19c9c7+'\x27\x20注入\x20'+_0x10e456['length']+_0x56c2e3(0x12c));}}catch(_0x36e86f){console[_0x56c2e3(0x135)](_0x56c2e3(0x1c1),_0x36e86f);if(settings[_0x56c2e3(0x16f)][_0x56c2e3(0x166)])showNotification(_0x56c2e3(0x124)+_0x36e86f[_0x56c2e3(0x181)],_0x56c2e3(0x135));}}async function moveKnowledgeBase(_0x4c26e3,_0xcaa511){const _0x4b8edb=_0x4826de,_0x55f9fc=_0xcaa511===_0x4b8edb(0x1b0)?_0x4b8edb(0x165):_0x4b8edb(0x1b0),_0x4b3ca5=getCharacterStableId();if(!_0x4b3ca5&&_0x55f9fc===_0x4b8edb(0x165)){toastr[_0x4b8edb(0x135)](_0x4b8edb(0x11f));return;}const _0x41dd26=_0xcaa511===_0x4b8edb(0x1b0)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x1d9a8e=_0x55f9fc==='global'?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x340815=_0x41dd26[_0x4c26e3];if(!_0x340815){const _0x3d6b4d=_0x4b8edb(0x116)+_0xcaa511+_0x4b8edb(0x173)+_0x4c26e3+'\x20的知识库。';console['error'](_0x4b8edb(0x1e1)+_0x3d6b4d),toastr[_0x4b8edb(0x135)]('移动失败:未找到源条目。');return;}_0xcaa511===_0x4b8edb(0x165)&&_0x55f9fc==='global'&&!_0x340815[_0x4b8edb(0x15e)]&&(console[_0x4b8edb(0xff)](_0x4b8edb(0x198)+_0x4c26e3+_0x4b8edb(0x172)+_0x4b3ca5),_0x340815[_0x4b8edb(0x15e)]=_0x4b3ca5);delete _0x41dd26[_0x4c26e3],_0x1d9a8e[_0x4c26e3]=_0x340815,saveSettings();const _0x1ca1a2='知识库【'+_0x340815[_0x4b8edb(0x185)]+'】已成功移动到'+(_0x55f9fc===_0x4b8edb(0x1b0)?'全局':'局部')+'。';console['log'](_0x4b8edb(0x1e1)+_0x1ca1a2);}async function getAllVectorsFromCollection(_0x5d84f4){const _0x583732=_0x4826de,_0x22a122='*',_0x9a317c={'collectionId':_0x5d84f4,'searchText':_0x22a122,'topK':0x2710,'threshold':0x0,'source':_0x583732(0x1b9),'embeddings':{}},_0x402da2=(await getEmbeddings([_0x22a122]))[0x0];_0x9a317c['embeddings']={[_0x22a122]:_0x402da2};const _0x5d7fdf=await fetch(_0x583732(0xfa),{'method':'POST','headers':context[_0x583732(0x174)](),'body':JSON[_0x583732(0x195)](_0x9a317c)});if(!_0x5d7fdf['ok']){if(_0x5d7fdf[_0x583732(0xf6)]===0x194)return console[_0x583732(0xff)](_0x583732(0x118)+_0x5d84f4+'\x20不存在,返回空数组。'),[];const _0x129f83=await _0x5d7fdf[_0x583732(0x1cb)]();throw new Error(_0x583732(0x1ea)+_0x5d84f4+_0x583732(0x1d9)+_0x129f83);}const _0x6f43d0=await _0x5d7fdf['json']();return _0x6f43d0[_0x583732(0xf3)]||_0x6f43d0[_0x583732(0x17c)]||_0x6f43d0[_0x583732(0x14c)]||[];} +'use strict';const _0x1d2ea6=_0x292c;(function(_0xbc1e4f,_0x4d6bc8){const _0x280f6b=_0x292c,_0x152b1b=_0xbc1e4f();while(!![]){try{const _0x2ba4e6=parseInt(_0x280f6b(0x207))/0x1+-parseInt(_0x280f6b(0x29e))/0x2+-parseInt(_0x280f6b(0x2d0))/0x3+parseInt(_0x280f6b(0x1e5))/0x4*(parseInt(_0x280f6b(0x252))/0x5)+parseInt(_0x280f6b(0x1df))/0x6*(parseInt(_0x280f6b(0x274))/0x7)+parseInt(_0x280f6b(0x243))/0x8+-parseInt(_0x280f6b(0x242))/0x9*(parseInt(_0x280f6b(0x2cf))/0xa);if(_0x2ba4e6===_0x4d6bc8)break;else _0x152b1b['push'](_0x152b1b['shift']());}catch(_0x165e1a){_0x152b1b['push'](_0x152b1b['shift']());}}}(_0x255c,0x44e7d));function _0x255c(){const _0x117b49=['key','[翰林院-日志]\x20/api/vector/purge\x20响应状态:\x20','lorebook','未分类世界书','移动失败:没有当前角色,无法移入局部知识库。','manual','saveProgress','忆识检索失败:\x20','isArray','text','template','\x20及其向量数据。','[翰林院-日志]\x20清空目标集合ID:\x20','\x20池精确提取\x20','[翰林院-配置]\x20','在源作用域\x20\x27','/api/vector/query','[翰林院]\x20进入多路并行独立检索流程...','slice','end','message','results','[翰林院-迁移]\x20用户确认迁移,正在处理旧宝库:\x20','[翰林院-日志]\x20忆识存入API错误:','join','log','find','[翰林院-迁移]\x20集合\x20','vector','\x20-\x20楼层\x20#','length','AbortError','7zengPT','data','\x20个条目。','\x27的文本分割成\x20','[来源:\x20','global','insertVectors\x20必须接收一个有效的\x20collectionId\x20参数。','stringify','chapter','(已锁定:\x20','[翰林院-核心]\x20文本录入失败:\x20','status','第1章','对话记录大总结','metadata','[翰林院-户口普查]\x20知识库\x20\x22','),开始强制重分类所有知识库...','advanced','[翰林院]\x20检索或注入时发生错误:','map','substring','翰林院通告','error','local','小说录入','replace','[翰林院-核心]\x20尝试删除一个不存在的知识库:\x20','has','toString','[翰林院-核心]\x20已为宝库\x20','Rerank失败:\x20','bookName','\x0a$1','[翰林院]\x20最终无可用结果,注入中止。','[翰林院-迁移]\x20用户取消了迁移操作。','tiaomu','\x22\x20已删除。','[翰林院]\x20创建优先查询组:\x20','[翰林院-核心]\x20聊天记录凝识失败:\x20','\x27\x20中未找到ID为\x20','json','rerank','hasOwnProperty','extensionSettings','top_n','23245iiSaxI','sousuo'];_0x255c=function(){return _0x117b49;};return _0x255c();}import{extension_prompt_roles,setExtensionPrompt}from'/script.js';import*as _0x274781 from'./utils/context-utils.js';import{getCollectionIdInfo,getCharacterId,getCharacterStableId}from'./utils/context-utils.js';import{defaultSettings as _0x1e824f}from'./rag-settings.js';import*as _0x249d4f from'./ingestion-manager.js';import{getEmbeddings,fetchEmbeddingModels as _0xc3e478,fetchRerankModels as _0x303e64,executeRerank,testApiConnection as _0x528b44}from'./rag-api.js';import{superSort}from'./super-sorter.js';const MODULE_NAME=_0x1d2ea6(0x2d5),OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME='vectors_rearrangeChat',GLOBAL_SCOPE_ID=_0x1d2ea6(0x214);let context=null,settings=null,lockedCollectionId=null;function filterWorldbooks(_0x1d1706,_0x42b6b5){const _0x106c03=_0x1d2ea6;if(!_0x1d1706||!_0x1d1706[_0x106c03(0x2ca)]())return _0x42b6b5;const _0x32fea9=_0x1d1706[_0x106c03(0x2e3)]()['trim']();return _0x42b6b5['filter'](_0xf39df2=>{const _0x141186=_0x106c03;return _0xf39df2[_0x141186(0x2e3)]()[_0x141186(0x2a7)](_0x32fea9)||containsPinyinMatch(_0xf39df2,_0x32fea9);});}function filterWorldbookEntries(_0x32de80,_0x1a2817){const _0x46bf0f=_0x1d2ea6;if(!_0x32de80||!_0x32de80[_0x46bf0f(0x2ca)]())return _0x1a2817;const _0x4b8b62=_0x32de80['toLowerCase']()[_0x46bf0f(0x2ca)]();return _0x1a2817[_0x46bf0f(0x1e3)](_0x3e174e=>{const _0x37dbb4=_0x46bf0f,_0x15afad=[_0x3e174e[_0x37dbb4(0x2ad)]||'',_0x3e174e[_0x37dbb4(0x254)]||'',_0x3e174e[_0x37dbb4(0x2db)]||''][_0x37dbb4(0x26c)]('\x20')[_0x37dbb4(0x2e3)]();return _0x15afad[_0x37dbb4(0x2a7)](_0x4b8b62)||containsPinyinMatch(_0x3e174e[_0x37dbb4(0x2ad)]||'',_0x4b8b62);});}function containsPinyinMatch(_0x10600b,_0x137e2b){const _0x3e0b39=_0x1d2ea6,_0x3ade6b={'世界书':'sjshu','条目':_0x3e0b39(0x248),'编纂':'bianzhuan','搜索':_0x3e0b39(0x253)},_0x4dc3bd=_0x3ade6b[_0x10600b];return _0x4dc3bd&&_0x4dc3bd[_0x3e0b39(0x2a7)](_0x137e2b);}function highlightSearchMatch(_0x39e005,_0x14bf3c){const _0x25fafc=_0x1d2ea6;if(!_0x14bf3c||!_0x14bf3c['trim']())return _0x39e005;const _0x53b3c3=new RegExp('('+_0x14bf3c[_0x25fafc(0x28d)](/[.*+?^${}()|[\]\\]/g,'\x5c$&')+')','gi');return _0x39e005[_0x25fafc(0x28d)](_0x53b3c3,_0x25fafc(0x245));}function debounce(_0x464e5f,_0x58ebbf){let _0x54567c;return function _0x1f19dc(..._0x2e13a0){const _0x297501=()=>{clearTimeout(_0x54567c),_0x464e5f(..._0x2e13a0);};clearTimeout(_0x54567c),_0x54567c=setTimeout(_0x297501,_0x58ebbf);};}export{initialize,getSettings,saveSettings,resetSettings,_0x528b44 as testApiConnection,_0xc3e478 as fetchEmbeddingModels,_0x303e64 as fetchRerankModels,getVectorCount,purgeStorage,getMessagesForCondensation,processCondensation,ingestTextToHanlinyuan,getCollectionId,toggleSessionLock,isSessionLocked,getLockedSessionInfo,addKnowledgeBase,removeKnowledgeBase,getLocalKnowledgeBases,getGlobalKnowledgeBases,toggleKnowledgeBase,moveKnowledgeBase,filterWorldbooks,filterWorldbookEntries,highlightSearchMatch,debounce};function initialize(){const _0x594298=_0x1d2ea6;context=SillyTavern['getContext']();if(!context){console['error'](_0x594298(0x232));return;}settings=getSettings(),!window[_0x594298(0x2cc)]&&(window[_0x594298(0x2cc)]={}),window['hanlinyuanRagProcessor'][_0x594298(0x23a)]=rearrangeChat,window['hanlinyuanRagProcessor'][_0x594298(0x2d3)]=!![],console['log'](_0x594298(0x2b9));}async function ingestTextToHanlinyuan(_0x1f502f,_0x399b28='manual',_0x419d32={},_0x888350=()=>{},_0x48057f=null,_0x279698=()=>{},_0xf4d384=()=>{},_0x3ce809=null,_0x3619fc=0x0){const _0x4dace7=_0x1d2ea6;if(!_0x1f502f||!_0x1f502f['trim']())return{'success':![],'error':_0x4dace7(0x1d8)};if(!settings)return{'success':![],'error':_0x4dace7(0x1d9)};try{const _0x5ce1b3=getCollectionIdInfo(),_0x524ab9=await _0x2d61b9();if(_0x5ce1b3['oldId']&&_0x5ce1b3[_0x4dace7(0x2c4)]===_0x524ab9&&_0x5ce1b3['oldId']!==_0x5ce1b3[_0x4dace7(0x201)]){const _0x3302fb=confirm(_0x4dace7(0x1da));if(_0x3302fb)_0x279698(_0x4dace7(0x26a)+_0x5ce1b3[_0x4dace7(0x2c4)],_0x4dace7(0x1d5)),await purgeStorage(_0x5ce1b3['oldId']),_0x279698(_0x4dace7(0x2dc),_0x4dace7(0x218));else return _0x279698(_0x4dace7(0x247),_0x4dace7(0x213)),toastr[_0x4dace7(0x213)](_0x4dace7(0x29f)),{'success':![],'error':_0x4dace7(0x2ba)};}let _0x215b11,_0x3a34df;const _0x14c2cf=new Date()['toLocaleString'](_0x4dace7(0x227),{'hour12':![]}),_0x3a9161=getCharacterName()||_0x4dace7(0x1ee);switch(_0x399b28){case _0x4dace7(0x2ce):const _0x207241=_0x419d32['range']||{},_0x74be40=_0x207241['start']??'?',_0x37b3f4=_0x207241[_0x4dace7(0x267)]===0x0?'末':_0x207241[_0x4dace7(0x267)]??'?';_0x215b11=_0x3a9161+':\x20'+_0x74be40+'楼-'+_0x37b3f4+'楼';break;case _0x4dace7(0x256):const _0x865e9e=_0x419d32[_0x4dace7(0x293)]||_0x4dace7(0x257);if(_0x419d32[_0x4dace7(0x1e8)]&&_0x419d32[_0x4dace7(0x1e8)][_0x4dace7(0x2a7)]('微言录总结'))_0x419d32[_0x4dace7(0x1e8)]=_0x4dace7(0x2c8);else _0x419d32['entryName']&&_0x419d32[_0x4dace7(0x1e8)]['includes'](_0x4dace7(0x2a9))&&(_0x419d32[_0x4dace7(0x1e8)]=_0x4dace7(0x281));const _0x5a1545=_0x419d32[_0x4dace7(0x1e8)]||_0x4dace7(0x230);_0x215b11=_0x865e9e+':\x20'+_0x5a1545;break;case _0x4dace7(0x1d3):_0x215b11=_0x4dace7(0x236)+(_0x419d32[_0x4dace7(0x2c1)]||_0x4dace7(0x2b8));break;case _0x4dace7(0x259):default:_0x215b11=_0x4dace7(0x2df)+_0x14c2cf;break;}const _0x5e6eb6=Object[_0x4dace7(0x1f7)](getKnowledgeBases()),_0xca4c5d=_0x5e6eb6['find'](_0x4d2993=>_0x4d2993[_0x4dace7(0x2dd)]===_0x215b11);if(_0xca4c5d)_0x3a34df=_0xca4c5d['id'],_0x279698(_0x4dace7(0x224)+_0x215b11+'\x22,将数据合并入库。',_0x4dace7(0x213));else{_0x279698('[翰林院-核心]\x20准备为任务\x20\x22'+_0x215b11+_0x4dace7(0x297),_0x4dace7(0x213));const _0x9ffcbd=addKnowledgeBase(_0x215b11,_0x399b28);_0x3a34df=_0x9ffcbd['id'];}const _0xd6a3de=getCharacterStableId(),_0x2d15ee=_0xd6a3de+'_'+_0x3a34df;_0x279698(_0x4dace7(0x1f8)+_0x215b11+'\x20(集合ID:\x20'+_0x2d15ee+')',_0x4dace7(0x218)),_0x279698(_0x4dace7(0x1d0)+_0x2d15ee,_0x4dace7(0x213)),_0x888350({'message':_0x4dace7(0x1d2),'processed':0x0,'total':0x1});const _0x1d1326=splitIntoChunks(_0x1f502f,_0x399b28,_0x419d32),_0x4a03ba=_0x1d1326['length'];if(_0x48057f?.[_0x4dace7(0x1e9)])throw new Error(_0x4dace7(0x273));_0x279698(_0x4dace7(0x241)+_0x215b11+_0x4dace7(0x277)+_0x4a03ba+'\x20个块。','info');if(_0x4a03ba===0x0)return{'success':!![],'count':0x0};const _0x4892e1=settings['retrieval'][_0x4dace7(0x1f9)]||0x5;let _0x572369=_0x3619fc;for(let _0x3a9246=_0x3619fc;_0x3a9246<_0x4a03ba;_0x3a9246+=_0x4892e1){if(_0x48057f?.[_0x4dace7(0x1e9)])throw new Error('AbortError');const _0x28efdf=_0x1d1326[_0x4dace7(0x266)](_0x3a9246,_0x3a9246+_0x4892e1);_0x888350({'message':'正在处理\x20'+(_0x3a9246+0x1)+'-'+(_0x3a9246+_0x28efdf[_0x4dace7(0x272)])+'\x20块','processed':_0x3a9246,'total':_0x4a03ba});const _0x48b59f=_0x28efdf['map'](_0x4eb6db=>_0x4eb6db[_0x4dace7(0x25d)]),_0x48ff1d=await getEmbeddings(_0x48b59f,_0x48057f);if(_0x48057f?.['aborted'])throw new Error(_0x4dace7(0x273));if(_0x28efdf['length']!==_0x48ff1d[_0x4dace7(0x272)])throw new Error(_0x4dace7(0x1e2));const _0x26546f=_0x28efdf[_0x4dace7(0x287)]((_0x5c2fc0,_0x5eff83)=>({..._0x5c2fc0,'vector':_0x48ff1d[_0x5eff83]}));await insertVectors(_0x26546f,_0x48057f,_0x2d15ee),_0x572369+=_0x28efdf[_0x4dace7(0x272)],_0x3ce809&&_0x249d4f[_0x4dace7(0x25a)](_0x3ce809,_0x572369,_0x4a03ba),await _0xf4d384();}return _0x3ce809&&_0x249d4f['clearJob'](_0x3ce809),_0x279698('[翰林院-核心]\x20成功插入\x20'+_0x572369+'\x20个向量条目。',_0x4dace7(0x218)),{'success':!![],'count':_0x572369};}catch(_0x9f6acd){if(_0x9f6acd[_0x4dace7(0x2dd)]===_0x4dace7(0x273)){_0x279698('[翰林院-核心]\x20文本录入任务被用户中止。',_0x4dace7(0x1d5));throw _0x9f6acd;}return console[_0x4dace7(0x28a)]('[翰林院-核心]\x20ingestTextToHanlinyuan\x20失败:',_0x9f6acd),_0x279698(_0x4dace7(0x27e)+_0x9f6acd['message'],_0x4dace7(0x28a)),{'success':![],'error':_0x9f6acd[_0x4dace7(0x268)]};}}function getSettings(){const _0x2c78b0=_0x1d2ea6;if(!context||!context[_0x2c78b0(0x250)])return structuredClone(_0x1e824f);let _0x295228=context[_0x2c78b0(0x250)][MODULE_NAME];!_0x295228&&(_0x295228={},context[_0x2c78b0(0x250)][MODULE_NAME]=_0x295228);_0x295228[_0x2c78b0(0x2a4)]===undefined&&(_0x295228[_0x2c78b0(0x2a4)]={});_0x295228[_0x2c78b0(0x1f3)]===undefined&&(_0x295228[_0x2c78b0(0x1f3)]={});for(const _0x3f3b7b in _0x1e824f){if(_0x295228[_0x3f3b7b]===undefined)_0x295228[_0x3f3b7b]=structuredClone(_0x1e824f[_0x3f3b7b]);else{if(typeof _0x1e824f[_0x3f3b7b]===_0x2c78b0(0x212)&&!Array[_0x2c78b0(0x25c)](_0x1e824f[_0x3f3b7b])&&_0x1e824f[_0x3f3b7b]!==null)for(const _0x15c7b1 in _0x1e824f[_0x3f3b7b]){_0x295228[_0x3f3b7b][_0x15c7b1]===undefined&&(_0x295228[_0x3f3b7b][_0x15c7b1]=_0x1e824f[_0x3f3b7b][_0x15c7b1]);}}}return _0x295228;}function saveSettings(){const _0x22dc18=_0x1d2ea6;if(context)context[_0x22dc18(0x20c)]();}function resetSettings(){const _0x5dca40=_0x1d2ea6;context&&(context[_0x5dca40(0x250)][MODULE_NAME]=structuredClone(_0x1e824f),saveSettings());}function showNotification(_0x15c667,_0x2051d2=_0x1d2ea6(0x213)){toastr[_0x2051d2](_0x15c667);}function getTagForSource(_0x9cda1d){const _0x2ce6aa=_0x1d2ea6;switch(_0x9cda1d){case _0x2ce6aa(0x2ce):return _0x2ce6aa(0x1cb);case _0x2ce6aa(0x256):return'世界书';case _0x2ce6aa(0x259):return _0x2ce6aa(0x235);case _0x2ce6aa(0x1d3):return'小说录入';default:return'资料';}}function _0x292c(_0x4584ba,_0x107353){const _0x255cb2=_0x255c();return _0x292c=function(_0x292cd7,_0x3e519c){_0x292cd7=_0x292cd7-0x1ca;let _0x1c7d4c=_0x255cb2[_0x292cd7];return _0x1c7d4c;},_0x292c(_0x4584ba,_0x107353);}function splitIntoChunks(_0x427b59,_0x45965a,_0x33ef7e={}){const _0x3c4fa6=_0x1d2ea6;switch(_0x45965a){case _0x3c4fa6(0x1d3):return _chunkForNovel(_0x427b59,_0x33ef7e);case _0x3c4fa6(0x2ce):return _chunkForChatHistory(_0x427b59,_0x33ef7e);case _0x3c4fa6(0x256):return _chunkForLorebook(_0x427b59,_0x33ef7e);case'manual':return _chunkForManual(_0x427b59,_0x33ef7e);default:console[_0x3c4fa6(0x1d5)]('[翰林院-分块]\x20未知的来源类型\x20\x27'+_0x45965a+_0x3c4fa6(0x23b));return _chunkForManual(_0x427b59,{..._0x33ef7e,'sourceName':_0x33ef7e['sourceName']||_0x3c4fa6(0x2a3)});}}function _chunkForNovel(_0x336b46,_0x44efd3){const _0x56b8ba=_0x1d2ea6,{chunkSize:_0xa7e873,overlap:_0x21de6d}=settings['advanced'],{sourceName:sourceName='小说'}=_0x44efd3,_0x37e116=[];if(!_0x336b46||_0xa7e873<=0x0)return _0x37e116;const _0x1504ce=/(第\s*[一二三四五六七八九十百千万零\d]+\s*卷)/gim,_0x4e7897=/(第\s*[一二三四五六七八九十百千万零\d]+\s*[章回节部])|^(Chapter\s+\d+)/gim;let _0x30bbb5=0x0;const _0x2cc32e=_0x336b46[_0x56b8ba(0x205)]('\x0a');let _0x1fb716=_0x56b8ba(0x2b7),_0x4d71aa='第1章',_0x5bc12f=[];function _0x5421e7(){const _0x52dd14=_0x56b8ba;if(_0x5bc12f[_0x52dd14(0x272)]===0x0)return;const _0x449103=_0x5bc12f[_0x52dd14(0x26c)]('\x0a');let _0x360ca8=0x0,_0x281736=0x1;while(_0x360ca8<_0x449103[_0x52dd14(0x272)]){const _0x44f186=Math[_0x52dd14(0x21c)](_0x360ca8+_0xa7e873,_0x449103['length']),_0x2348a9=_0x449103[_0x52dd14(0x288)](_0x360ca8,_0x44f186);if(_0x2348a9[_0x52dd14(0x2ca)]()[_0x52dd14(0x272)]>0x0){const _0x4c702d={'source':_0x52dd14(0x1d3),'sourceName':sourceName,'timestamp':new Date()['toISOString'](),'globalIndex':_0x30bbb5++,'volume':_0x1fb716,'chapter':_0x4d71aa,'section':_0x281736},_0x3cdcab=getTagForSource('novel'),_0x4ab5e6=_0x52dd14(0x278)+sourceName+',\x20'+_0x1fb716+',\x20'+_0x4d71aa+',\x20第'+_0x281736+'节]',_0x916ffa='<'+_0x3cdcab+'>\x0a'+_0x4ab5e6+'\x0a'+_0x2348a9+_0x52dd14(0x294)+_0x3cdcab+'>';_0x37e116['push']({'text':_0x916ffa,'metadata':_0x4c702d}),_0x281736++;}_0x360ca8+=_0xa7e873-_0x21de6d;if(_0x360ca8>=_0x449103[_0x52dd14(0x272)])break;}_0x5bc12f=[];}for(const _0x10bead of _0x2cc32e){const _0x83b522=_0x10bead['trim']();if(_0x1504ce[_0x56b8ba(0x2bb)](_0x83b522))_0x5421e7(),_0x1fb716=_0x83b522,_0x4d71aa='第1章';else _0x4e7897[_0x56b8ba(0x2bb)](_0x83b522)?(_0x5421e7(),_0x4d71aa=_0x83b522):_0x5bc12f[_0x56b8ba(0x2a0)](_0x10bead);}_0x5421e7();if(_0x37e116[_0x56b8ba(0x272)]===0x0&&_0x336b46[_0x56b8ba(0x272)]>0x0){let _0x6b6989=0x0,_0x2be45c=0x1;while(_0x6b6989<_0x336b46['length']){const _0x4cc944=Math[_0x56b8ba(0x21c)](_0x6b6989+_0xa7e873,_0x336b46[_0x56b8ba(0x272)]),_0x5a84=_0x336b46[_0x56b8ba(0x288)](_0x6b6989,_0x4cc944),_0x18e123={'source':_0x56b8ba(0x1d3),'sourceName':sourceName,'timestamp':new Date()['toISOString'](),'globalIndex':_0x37e116['length'],'volume':_0x56b8ba(0x2b7),'chapter':_0x56b8ba(0x280),'section':_0x2be45c},_0x5a8662=getTagForSource(_0x56b8ba(0x1d3)),_0x59f77c='[来源:\x20'+sourceName+',\x20第1卷,\x20第1章,\x20第'+_0x2be45c+'节]',_0x255917='<'+_0x5a8662+'>\x0a'+_0x59f77c+'\x0a'+_0x5a84+_0x56b8ba(0x294)+_0x5a8662+'>';_0x37e116[_0x56b8ba(0x2a0)]({'text':_0x255917,'metadata':_0x18e123}),_0x2be45c++,_0x6b6989+=_0xa7e873-_0x21de6d;}}return _0x37e116;}function _chunkForChatHistory(_0x47f013,_0x478bb5){const _0x388564=_0x1d2ea6,{chunkSize:_0xfd2ee1,overlap:_0x1c5321}=settings['advanced'],{floor:_0x4af717,is_user:_0x2863c2,timestamp:_0x14ee10}=_0x478bb5,_0x4b21b0=[];if(!_0x47f013||_0xfd2ee1<=0x0)return _0x4b21b0;let _0x5d66d4=0x1,_0x2c7b2a=0x0;while(_0x2c7b2a<_0x47f013[_0x388564(0x272)]){const _0x4f3682=Math[_0x388564(0x21c)](_0x2c7b2a+_0xfd2ee1,_0x47f013[_0x388564(0x272)]),_0x5b98a0=_0x47f013[_0x388564(0x288)](_0x2c7b2a,_0x4f3682),_0x47ca9e='[来源:\x20聊天记录,\x20楼层:\x20#'+_0x4af717+_0x388564(0x228)+_0x5d66d4+_0x388564(0x296),_0x4de1f9=getTagForSource(_0x388564(0x2ce)),_0x3c3b4e='<'+_0x4de1f9+'>\x0a'+_0x47ca9e+'\x0a'+_0x5b98a0+'\x0a';_0x4b21b0[_0x388564(0x2a0)]({'text':_0x3c3b4e,'metadata':{'source':_0x388564(0x2ce),'sourceName':'聊天记录\x20#'+_0x4af717,'floor':_0x4af717,'part':_0x5d66d4,'is_user':_0x2863c2,'timestamp':_0x14ee10}}),_0x5d66d4++,_0x2c7b2a+=_0xfd2ee1-_0x1c5321;if(_0x2c7b2a>=_0x47f013[_0x388564(0x272)])break;}return _0x4b21b0;}function _chunkForLorebook(_0x2dc47e,_0x3c4926){const _0x4903e0=_0x1d2ea6,{chunkSize:_0x10e0bc,overlap:_0x3ba63c}=settings['advanced'],{bookName:bookName=_0x4903e0(0x23c),entryName:entryName='世界书条目'}=_0x3c4926,_0x3519fc=[];if(!_0x2dc47e||_0x10e0bc<=0x0)return _0x3519fc;let _0x2aac49=0x1,_0x15b95d=0x0;while(_0x15b95d<_0x2dc47e['length']){const _0x2435dc=Math[_0x4903e0(0x21c)](_0x15b95d+_0x10e0bc,_0x2dc47e[_0x4903e0(0x272)]),_0x381cdc=_0x2dc47e['substring'](_0x15b95d,_0x2435dc),_0x491afe=_0x4903e0(0x278)+bookName+_0x4903e0(0x2c3)+entryName+_0x4903e0(0x228)+_0x2aac49+_0x4903e0(0x296),_0x740191=getTagForSource(_0x4903e0(0x256)),_0x479623='<'+_0x740191+'>\x0a'+_0x491afe+'\x0a'+_0x381cdc+_0x4903e0(0x294)+_0x740191+'>';_0x3519fc['push']({'text':_0x479623,'metadata':{'source':'lorebook','sourceName':bookName+':\x20'+entryName,'bookName':bookName,'entryName':entryName,'part':_0x2aac49,'timestamp':new Date()[_0x4903e0(0x1db)]()}}),_0x2aac49++,_0x15b95d+=_0x10e0bc-_0x3ba63c;if(_0x15b95d>=_0x2dc47e[_0x4903e0(0x272)])break;}return _0x3519fc;}function _chunkForManual(_0x4e85b9,_0x4ccd32){const _0x47a778=_0x1d2ea6,{chunkSize:_0x4bbbd7,overlap:_0x6a4fa1}=settings[_0x47a778(0x285)],{sourceName:sourceName=_0x47a778(0x235)}=_0x4ccd32,_0x5a42ba=[];if(!_0x4e85b9||_0x4bbbd7<=0x0)return _0x5a42ba;const _0x4bb6fe=new Date(),_0x5ade21=_0x4bb6fe[_0x47a778(0x2a1)](_0x47a778(0x227));let _0x25b539=0x1,_0x1fd54d=0x0;while(_0x1fd54d<_0x4e85b9['length']){const _0x4a8786=Math['min'](_0x1fd54d+_0x4bbbd7,_0x4e85b9[_0x47a778(0x272)]),_0x4a596b=_0x4e85b9[_0x47a778(0x288)](_0x1fd54d,_0x4a8786),_0x247112=_0x47a778(0x278)+sourceName+_0x47a778(0x211)+_0x5ade21+_0x47a778(0x228)+_0x25b539+_0x47a778(0x296),_0x4f27a5=getTagForSource(_0x47a778(0x259)),_0x2012d3='<'+_0x4f27a5+'>\x0a'+_0x247112+'\x0a'+_0x4a596b+_0x47a778(0x294)+_0x4f27a5+'>';_0x5a42ba[_0x47a778(0x2a0)]({'text':_0x2012d3,'metadata':{'source':_0x47a778(0x259),'sourceName':sourceName,'part':_0x25b539,'timestamp':_0x4bb6fe['toISOString']()}}),_0x25b539++,_0x1fd54d+=_0x4bbbd7-_0x6a4fa1;if(_0x1fd54d>=_0x4e85b9[_0x47a778(0x272)])break;}return _0x5a42ba;}import{getCollectionId as _0x2d61b9,getCharacterName}from'./utils/context-utils.js';async function getCollectionId(){return lockedCollectionId||await _0x2d61b9();}async function toggleSessionLock(){return lockedCollectionId?(lockedCollectionId=null,![]):(lockedCollectionId=await _0x2d61b9(),!![]);}function isSessionLocked(){return lockedCollectionId!==null;}function getLockedSessionInfo(){const _0x32d6bd=_0x1d2ea6;if(!lockedCollectionId)return null;return{'id':lockedCollectionId,'name':_0x32d6bd(0x27d)+lockedCollectionId[_0x32d6bd(0x288)](0x0,0x8)+_0x32d6bd(0x1fa)};}function getLocalKnowledgeBases(){const _0x63eb6c=_0x1d2ea6,_0x202a99=getCharacterStableId();return!settings[_0x63eb6c(0x1f3)][_0x202a99]&&(settings[_0x63eb6c(0x1f3)][_0x202a99]={}),settings['knowledgeBases'][_0x202a99];}function getGlobalKnowledgeBases(){const _0x1ec62b=_0x1d2ea6;return!settings[_0x1ec62b(0x1f3)][GLOBAL_SCOPE_ID]&&(settings[_0x1ec62b(0x1f3)][GLOBAL_SCOPE_ID]={}),settings['knowledgeBases'][GLOBAL_SCOPE_ID];}function getKnowledgeBases(){const _0x1687e3=getLocalKnowledgeBases(),_0x1f6184=getGlobalKnowledgeBases();return{..._0x1f6184,..._0x1687e3};}function addKnowledgeBase(_0x2956dd,_0x125333='manual'){const _0x460b44=_0x1d2ea6;if(!_0x2956dd||!_0x2956dd[_0x460b44(0x2ca)]())throw new Error('知识库名称不能为空');const _0x2509dd=getCharacterStableId(),_0x29233d=getLocalKnowledgeBases(),_0x272144=_0x460b44(0x2e6)+Date[_0x460b44(0x1fc)]()+'_'+Math[_0x460b44(0x2ab)]()[_0x460b44(0x290)](0x24)['substring'](0x2,0x9),_0x19b731={'id':_0x272144,'name':_0x2956dd[_0x460b44(0x2ca)](),'enabled':!![],'createdAt':new Date()['toISOString'](),'owner':_0x2509dd,'source':_0x125333};return _0x29233d[_0x272144]=_0x19b731,saveSettings(),console[_0x460b44(0x26d)](_0x460b44(0x2b6)+_0x2509dd+_0x460b44(0x2c2)+_0x2956dd+'\x20(ID:\x20'+_0x272144+')'),_0x19b731;}async function removeKnowledgeBase(_0x11b78e,_0x2a77cb){const _0x564298=_0x1d2ea6,_0x523a79=getCharacterStableId(),_0x34de17=_0x2a77cb==='global'?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x4a192f=_0x34de17[_0x11b78e],_0x39d93b=_0x4a192f?.[_0x564298(0x2dd)]||_0x11b78e;if(!_0x4a192f){console[_0x564298(0x1d5)](_0x564298(0x28e)+_0x11b78e+_0x564298(0x2d6)+_0x2a77cb+')');return;}const _0x2dc988=_0x2a77cb===_0x564298(0x279)?_0x4a192f[_0x564298(0x2b4)]||GLOBAL_SCOPE_ID:_0x523a79,_0x4d2e36=_0x2dc988+'_'+_0x11b78e;console[_0x564298(0x26d)](_0x564298(0x217)+_0x11b78e+_0x564298(0x2e0)+_0x4d2e36);const _0xbf11f=await purgeStorage(_0x4d2e36);_0xbf11f?(delete _0x34de17[_0x11b78e],saveSettings(),console[_0x564298(0x26d)]('[翰林院-核心]\x20成功删除知识库\x20'+_0x11b78e+_0x564298(0x25f)),toastr[_0x564298(0x218)](_0x564298(0x240)+_0x39d93b+_0x564298(0x249))):(console[_0x564298(0x28a)]('[翰林院-核心]\x20清空向量集合\x20'+_0x4d2e36+'\x20失败,删除操作中止。'),toastr[_0x564298(0x28a)](_0x564298(0x225)));}function toggleKnowledgeBase(_0x5f5d12,_0x4d6734){const _0x25ec83=_0x1d2ea6,_0x48e158=_0x4d6734===_0x25ec83(0x279)?getGlobalKnowledgeBases():getLocalKnowledgeBases();_0x48e158[_0x5f5d12]&&(_0x48e158[_0x5f5d12]['enabled']=!_0x48e158[_0x5f5d12]['enabled'],saveSettings(),console[_0x25ec83(0x26d)](_0x25ec83(0x2e5)+_0x5f5d12+_0x25ec83(0x2d6)+_0x4d6734+_0x25ec83(0x219)+(_0x48e158[_0x5f5d12]['enabled']?'启用':'禁用')));}function generateHash(_0x20dcc3){const _0x13112a=_0x1d2ea6;let _0x242d78=0x0;for(let _0x5b3318=0x0;_0x5b3318<_0x20dcc3[_0x13112a(0x272)];_0x5b3318++){const _0x2ee60e=_0x20dcc3[_0x13112a(0x2cd)](_0x5b3318);_0x242d78=(_0x242d78<<0x5)-_0x242d78+_0x2ee60e,_0x242d78=_0x242d78&_0x242d78;}return Math[_0x13112a(0x1ea)](_0x242d78)[_0x13112a(0x290)](0x24);}async function queryVectors(_0x1a8c54,_0x396b03={}){const _0x3777ba=_0x1d2ea6,{includeBases:includeBases=null}=_0x396b03;console['log'](_0x3777ba(0x1e1)+(includeBases?'指定知识库':_0x3777ba(0x1f4))+')');const _0x523527=getCharacterStableId();let _0x1778bf;if(includeBases)_0x1778bf=includeBases,console[_0x3777ba(0x26d)](_0x3777ba(0x206)+_0x1778bf[_0x3777ba(0x272)]+_0x3777ba(0x1e4));else{const _0x2a9fbb=getLocalKnowledgeBases(),_0x16a505=getGlobalKnowledgeBases(),_0x52202a=Object['values'](_0x2a9fbb)[_0x3777ba(0x1e3)](_0x957a69=>_0x957a69['enabled']),_0x266d07=Object[_0x3777ba(0x1f7)](_0x16a505)[_0x3777ba(0x1e3)](_0xaa1caa=>_0xaa1caa[_0x3777ba(0x215)]);_0x1778bf=[..._0x52202a[_0x3777ba(0x287)](_0x2efa24=>({..._0x2efa24,'scope':'local'})),..._0x266d07[_0x3777ba(0x287)](_0x575a4d=>({..._0x575a4d,'scope':_0x3777ba(0x279)}))];}if(_0x1778bf[_0x3777ba(0x272)]===0x0&&!includeBases){console['log'](_0x3777ba(0x234));const _0x5385c2=await _0x2d61b9();if(!_0x5385c2)return[];_0x1778bf[_0x3777ba(0x2a0)]({'id':null,'name':'旧版宝库\x20(Legacy)','scope':_0x3777ba(0x23e)});}if(_0x1778bf[_0x3777ba(0x272)]===0x0)return console[_0x3777ba(0x26d)](_0x3777ba(0x1ce)),[];const _0x3d9ce9=(await getEmbeddings([_0x1a8c54]))[0x0];if(!_0x3d9ce9)throw new Error(_0x3777ba(0x1f1));let _0x42775f=[];const _0x41598e=_0x1778bf[_0x3777ba(0x287)](_0x5f315c=>{const _0x2d08e5=_0x3777ba;let _0x110adb;if(_0x5f315c[_0x2d08e5(0x21e)]===_0x2d08e5(0x23e))_0x110adb=_0x2d61b9();else{const _0x39e64f=_0x5f315c[_0x2d08e5(0x21e)]===_0x2d08e5(0x279)?_0x5f315c['owner']||GLOBAL_SCOPE_ID:_0x523527;_0x110adb=Promise['resolve'](_0x39e64f+'_'+_0x5f315c['id']);}return _0x110adb[_0x2d08e5(0x231)](_0x34a6fa=>{const _0x18dbed=_0x2d08e5;if(!_0x34a6fa)return[];console['log'](_0x18dbed(0x202)+_0x5f315c[_0x18dbed(0x2dd)]+_0x18dbed(0x2b0)+_0x34a6fa+')');const _0x143836={'collectionId':_0x34a6fa,'searchText':_0x1a8c54,'topK':settings['advanced']['maxResults'],'threshold':settings[_0x18dbed(0x285)]['matchThreshold'],'source':_0x18dbed(0x20d),'embeddings':{[_0x1a8c54]:_0x3d9ce9}};return fetch(_0x18dbed(0x264),{'method':'POST','headers':context['getRequestHeaders'](),'body':JSON[_0x18dbed(0x27b)](_0x143836)})[_0x18dbed(0x231)](async _0x52bb78=>{const _0x579880=_0x18dbed;if(!_0x52bb78['ok']){const _0xecc60=await _0x52bb78[_0x579880(0x25d)]();return console[_0x579880(0x28a)]('[翰林院-日志]\x20查询知识库\x20'+_0x34a6fa+'\x20失败:',_0xecc60),[];}const _0x4b2039=await _0x52bb78[_0x579880(0x24d)]();let _0x293383=[];if(Array[_0x579880(0x25c)](_0x4b2039))_0x293383=_0x4b2039;else{if(_0x4b2039&&_0x4b2039['metadata']&&Array[_0x579880(0x25c)](_0x4b2039[_0x579880(0x282)]))_0x293383=_0x4b2039[_0x579880(0x282)];else{if(_0x4b2039&&_0x4b2039[_0x579880(0x269)]&&Array[_0x579880(0x25c)](_0x4b2039['results']))_0x293383=_0x4b2039[_0x579880(0x269)];else _0x4b2039&&_0x4b2039['data']&&Array['isArray'](_0x4b2039[_0x579880(0x275)])&&(_0x293383=_0x4b2039['data']);}}const _0x10e337=_0x293383[_0x579880(0x287)](_0x1de2ba=>{const _0x228993=_0x579880;if(!_0x1de2ba||typeof _0x1de2ba['text']!==_0x228993(0x2de))return null;const _0x5ef717={'source':_0x228993(0x22b),'sourceName':'未知'},_0x2bb6ce=_0x1de2ba['text']['match'](/^<([^>]+)>/),_0x4a7c62=_0x2bb6ce?_0x2bb6ce[0x1]:'';switch(_0x4a7c62){case _0x228993(0x1cb):_0x5ef717[_0x228993(0x22a)]='chat_history';const _0xb1e583=_0x1de2ba[_0x228993(0x25d)][_0x228993(0x1f6)](/楼层:\s*#(\d+),\s*第(\d+)部分/);_0xb1e583&&_0xb1e583[0x1]&&_0xb1e583[0x2]&&(_0x5ef717[_0x228993(0x2b2)]=parseInt(_0xb1e583[0x1],0xa),_0x5ef717[_0x228993(0x220)]=parseInt(_0xb1e583[0x2],0xa),_0x5ef717[_0x228993(0x2c1)]=_0x228993(0x1ef)+_0x5ef717['floor']);break;case _0x228993(0x23c):_0x5ef717['source']=_0x228993(0x256);const _0x44c9f9=_0x1de2ba[_0x228993(0x25d)][_0x228993(0x1f6)](/\[来源:\s*([^,]+),\s*条目:\s*([^,]+),\s*第(\d+)部分\]/);_0x44c9f9&&_0x44c9f9[0x1]&&_0x44c9f9[0x2]&&_0x44c9f9[0x3]&&(_0x5ef717[_0x228993(0x293)]=_0x44c9f9[0x1][_0x228993(0x2ca)](),_0x5ef717['entryName']=_0x44c9f9[0x2][_0x228993(0x2ca)](),_0x5ef717[_0x228993(0x220)]=parseInt(_0x44c9f9[0x3],0xa),_0x5ef717['sourceName']=_0x5ef717[_0x228993(0x293)]+':\x20'+_0x5ef717[_0x228993(0x1e8)]);break;case _0x228993(0x235):_0x5ef717[_0x228993(0x22a)]=_0x228993(0x259);const _0x5a3b05=_0x1de2ba[_0x228993(0x25d)]['match'](/\[来源:\s*([^,]+),.*第(\d+)部分\]/);_0x5a3b05&&_0x5a3b05[0x1]&&_0x5a3b05[0x2]&&(_0x5ef717[_0x228993(0x2c1)]=_0x5a3b05[0x1][_0x228993(0x2ca)](),_0x5ef717['part']=parseInt(_0x5a3b05[0x2],0xa));break;case _0x228993(0x28c):_0x5ef717[_0x228993(0x22a)]='novel';const _0x397f91=_0x1de2ba[_0x228993(0x25d)]['match'](/\[来源:\s*([^,]+),\s*([^,]+),\s*([^,]+),\s*([^\]]+)\]/);_0x397f91&&(_0x5ef717['sourceName']=_0x397f91[0x1][_0x228993(0x2ca)](),_0x5ef717[_0x228993(0x2d7)]=_0x397f91[0x2][_0x228993(0x2ca)](),_0x5ef717[_0x228993(0x27c)]=_0x397f91[0x3]['trim'](),_0x5ef717['section']=_0x397f91[0x4][_0x228993(0x2ca)]());break;}return{..._0x1de2ba,'score':_0x1de2ba['score']||0x1,'metadata':_0x5ef717};})[_0x579880(0x1e3)](Boolean);return console[_0x579880(0x26d)](_0x579880(0x1fe)+_0x5f315c[_0x579880(0x2dd)]+_0x579880(0x21d)+_0x10e337[_0x579880(0x272)]+_0x579880(0x2b5)),_0x10e337;})['catch'](_0x525b72=>{const _0x29f9c9=_0x18dbed;return console[_0x29f9c9(0x28a)](_0x29f9c9(0x21a)+_0x34a6fa+_0x29f9c9(0x29d),_0x525b72),[];});});}),_0x202a94=await Promise[_0x3777ba(0x2c0)](_0x41598e);_0x42775f=_0x202a94[_0x3777ba(0x23d)](),console[_0x3777ba(0x26d)](_0x3777ba(0x2b1)+_0x42775f['length']+_0x3777ba(0x2e7));const _0x284c42=[],_0xb11fa3=new Set();for(const _0x5d6b5d of _0x42775f){if(_0x5d6b5d&&typeof _0x5d6b5d==='object'&&_0x5d6b5d[_0x3777ba(0x25d)]&&typeof _0x5d6b5d[_0x3777ba(0x25d)]==='string'){const _0x21b048=_0x5d6b5d[_0x3777ba(0x25d)]['trim']();_0x21b048[_0x3777ba(0x272)]>0x0&&!_0xb11fa3[_0x3777ba(0x28f)](_0x21b048)&&(_0xb11fa3[_0x3777ba(0x29b)](_0x21b048),_0x284c42[_0x3777ba(0x2a0)](_0x5d6b5d));}}console[_0x3777ba(0x26d)]('[翰林院-日志]\x20去重后剩余\x20'+_0x284c42['length']+_0x3777ba(0x2b5)),_0x284c42[_0x3777ba(0x2d2)]((_0x2281ea,_0x13b49c)=>(_0x13b49c[_0x3777ba(0x2a5)]||0x0)-(_0x2281ea[_0x3777ba(0x2a5)]||0x0));const _0x42148e=[..._0x284c42];return console[_0x3777ba(0x26d)]('[翰林院-修复]\x20最终返回数组长度:\x20'+_0x42148e[_0x3777ba(0x272)]),console[_0x3777ba(0x26d)]('[翰林院-修复]\x20最终返回数组样本:',JSON[_0x3777ba(0x27b)](_0x42148e[_0x3777ba(0x266)](0x0,0x1),null,0x2)),_0x42148e;}async function insertVectors(_0x1b4fb7,_0x18ee5c=null,_0x5c5170){const _0x24d3b0=_0x1d2ea6;if(!_0x5c5170)throw new Error(_0x24d3b0(0x27a));if(_0x1b4fb7[_0x24d3b0(0x272)]===0x0)return{'success':!![],'count':0x0};const _0x560a9a=_0x1b4fb7['map']((_0x1dfb73,_0x250312)=>({'hash':generateHash(_0x1dfb73[_0x24d3b0(0x25d)]+Date[_0x24d3b0(0x1fc)]()+_0x250312),'text':_0x1dfb73[_0x24d3b0(0x25d)],'metadata':_0x1dfb73['metadata']||{'source':'unknown','timestamp':new Date()[_0x24d3b0(0x1db)]()}})),_0x4e378f=_0x560a9a[_0x24d3b0(0x238)]((_0x1cc9b2,_0x8f6b3a,_0x57a11a)=>{const _0x5190d8=_0x24d3b0;return _0x1cc9b2[_0x8f6b3a[_0x5190d8(0x25d)]]=_0x1b4fb7[_0x57a11a][_0x5190d8(0x270)],_0x1cc9b2;},{}),_0x14c277={'collectionId':_0x5c5170,'items':_0x560a9a,'source':_0x24d3b0(0x20d),'embeddings':_0x4e378f},_0xebab35=await fetch(_0x24d3b0(0x2e4),{'method':_0x24d3b0(0x20b),'headers':context[_0x24d3b0(0x1ff)](),'body':JSON['stringify'](_0x14c277),'signal':_0x18ee5c});if(!_0xebab35['ok']){const _0x849de5=await _0xebab35['text']();console['error'](_0x24d3b0(0x26b),_0x849de5);throw new Error(_0x24d3b0(0x1fd)+_0xebab35['status']+':\x20'+_0x849de5);}return{'success':!![],'count':_0x560a9a[_0x24d3b0(0x272)]};}async function getVectorCount(_0x3caec2=null,_0x4e78f0=_0x1d2ea6(0x28b)){const _0xe56a29=_0x1d2ea6,_0x3f1f35=getCharacterStableId();if(_0x3caec2){const _0x5c8a17=_0x4e78f0===_0xe56a29(0x279)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x5446e8=_0x5c8a17[_0x3caec2];if(!_0x5446e8)return console[_0xe56a29(0x1d5)](_0xe56a29(0x1d4)+_0x4e78f0+'\x27\x20中未找到ID为\x20'+_0x3caec2+_0xe56a29(0x208)),0x0;const _0x384cfe=_0x4e78f0==='global'?_0x5446e8[_0xe56a29(0x2b4)]||GLOBAL_SCOPE_ID:_0x3f1f35,_0x57828f=_0x384cfe+'_'+_0x3caec2;return await countVectorsInCollection(_0x57828f);}else{console['log'](_0xe56a29(0x1d1));const _0x1f902d=Object[_0xe56a29(0x1f7)](getLocalKnowledgeBases()),_0x8b2306=Object['values'](getGlobalKnowledgeBases()),_0x3cf4ea=[];_0x1f902d[_0xe56a29(0x2aa)](_0x112299=>{const _0x267ff8=_0xe56a29,_0x244d10=_0x3f1f35+'_'+_0x112299['id'];_0x3cf4ea[_0x267ff8(0x2a0)](countVectorsInCollection(_0x244d10));}),_0x8b2306[_0xe56a29(0x2aa)](_0x541048=>{const _0x2a27af=_0xe56a29,_0x456389=_0x541048[_0x2a27af(0x2b4)]||GLOBAL_SCOPE_ID,_0x495c06=_0x456389+'_'+_0x541048['id'];_0x3cf4ea[_0x2a27af(0x2a0)](countVectorsInCollection(_0x495c06));});const _0x3b7d1b=await _0x2d61b9();_0x3cf4ea[_0xe56a29(0x2a0)](countVectorsInCollection(_0x3b7d1b));const _0x49d003=await Promise[_0xe56a29(0x2c0)](_0x3cf4ea),_0x1ac37e=_0x49d003[_0xe56a29(0x238)]((_0x2dbca5,_0x7b1228)=>_0x2dbca5+_0x7b1228,0x0);return console[_0xe56a29(0x26d)](_0xe56a29(0x229)+_0x1ac37e),_0x1ac37e;}}async function countVectorsInCollection(_0x3ed987){const _0x54bd94=_0x1d2ea6;if(!_0x3ed987)return 0x0;console[_0x54bd94(0x26d)](_0x54bd94(0x22f)+_0x3ed987);const _0x50e689={'collectionId':_0x3ed987,'source':'webllm','embeddings':{}};try{const _0x2b3bf1=await fetch(_0x54bd94(0x2c9),{'method':'POST','headers':context[_0x54bd94(0x1ff)](),'body':JSON['stringify'](_0x50e689)});if(!_0x2b3bf1['ok']){if(_0x2b3bf1['status']===0x194)console['log']('[翰林院-日志]\x20集合\x20'+_0x3ed987+_0x54bd94(0x2bd));else{const _0x5a9c48=await _0x2b3bf1['text']();console[_0x54bd94(0x1d5)](_0x54bd94(0x1d7)+_0x3ed987+_0x54bd94(0x2cb)+_0x2b3bf1[_0x54bd94(0x27f)]+'):',_0x5a9c48);}return 0x0;}const _0x5af5af=await _0x2b3bf1[_0x54bd94(0x24d)]();let _0x47354a=0x0;if(Array[_0x54bd94(0x25c)](_0x5af5af))_0x47354a=_0x5af5af[_0x54bd94(0x272)];else _0x5af5af&&_0x5af5af[_0x54bd94(0x2a2)]&&(_0x47354a=_0x5af5af[_0x54bd94(0x2a2)][_0x54bd94(0x272)]);return _0x47354a;}catch(_0x3efe8b){return console[_0x54bd94(0x28a)](_0x54bd94(0x2af)+_0x3ed987+_0x54bd94(0x29d),_0x3efe8b),0x0;}}async function purgeStorage(_0x3cbc6a=null){const _0x47ff85=_0x1d2ea6;console[_0x47ff85(0x26d)](_0x47ff85(0x2c6));const _0x56db91=_0x3cbc6a||await getCollectionId();if(!_0x56db91)return console['error'](_0x47ff85(0x1cc)),toastr[_0x47ff85(0x28a)](_0x47ff85(0x1f5)),![];console[_0x47ff85(0x26d)](_0x47ff85(0x260)+_0x56db91);const _0x278444={'collectionId':_0x56db91};console[_0x47ff85(0x26d)](_0x47ff85(0x233),JSON[_0x47ff85(0x27b)](_0x278444,null,0x2));const _0x17e953=await fetch('/api/vector/purge',{'method':_0x47ff85(0x20b),'headers':context[_0x47ff85(0x1ff)](),'body':JSON[_0x47ff85(0x27b)](_0x278444)});console['log'](_0x47ff85(0x255)+_0x17e953[_0x47ff85(0x27f)]);if(!_0x17e953['ok']){const _0x491f72=await _0x17e953[_0x47ff85(0x25d)]();console[_0x47ff85(0x28a)](_0x47ff85(0x2a8),_0x491f72);}else console[_0x47ff85(0x26d)](_0x47ff85(0x1d6));return _0x17e953['ok'];}function getMessagesForCondensation(_0xd332cd=null){const _0x21ef87=_0x1d2ea6;if(!settings[_0x21ef87(0x1ed)]['enabled'])return showNotification('凝识之权未开启','warning'),[];const {layerStart:_0x2680fd,layerEnd:_0x5b01ab}=settings[_0x21ef87(0x1ed)],_0x2fb15a=_0xd332cd||settings[_0x21ef87(0x1ed)]['messageTypes'],_0x4f0d1d=context[_0x21ef87(0x299)][_0x21ef87(0x272)],_0x403c7d=Math[_0x21ef87(0x22e)](0x0,_0x2680fd-0x1),_0x18f480=_0x5b01ab===0x0||_0x5b01ab>_0x4f0d1d?_0x4f0d1d:Math[_0x21ef87(0x21c)](_0x4f0d1d,_0x5b01ab),_0x9cab7b=context[_0x21ef87(0x299)]['slice'](_0x403c7d,_0x18f480);return _0x9cab7b[_0x21ef87(0x1e3)](_0x3a0988=>{const _0x2cddda=_0x21ef87,_0x1b7b51=_0x3a0988[_0x2cddda(0x1e0)]===!![],_0x4e1c53=_0x3a0988[_0x2cddda(0x1e0)]===![];if(!_0x3a0988[_0x2cddda(0x204)]||!_0x3a0988[_0x2cddda(0x204)][_0x2cddda(0x2ca)]())return![];return _0x2fb15a[_0x2cddda(0x222)]&&_0x1b7b51||_0x2fb15a['ai']&&_0x4e1c53;});}async function processCondensation(_0x582019,_0x1be7bd=()=>{},_0x5a6f6f=null){const _0x1a4d5a=_0x1d2ea6;if(!_0x582019||_0x582019[_0x1a4d5a(0x272)]===0x0)return{'success':![],'error':'No\x20messages\x20to\x20process.'};try{let _0x507caf,_0x4c65df;const _0x174a4c=getCharacterName()||_0x1a4d5a(0x1ee);if(_0x5a6f6f){const _0x1d5824=_0x5a6f6f[_0x1a4d5a(0x216)]??'?',_0x830c09=_0x5a6f6f[_0x1a4d5a(0x267)]===0x0?'末':_0x5a6f6f['end']??'?';_0x507caf=_0x174a4c+':\x20'+_0x1d5824+'楼-'+_0x830c09+'楼';}else{const _0x314bf6=new Date()['toLocaleString'](_0x1a4d5a(0x227),{'hour12':![]});_0x507caf=_0x1a4d5a(0x22d)+_0x314bf6;}const _0x28a1e0=Object[_0x1a4d5a(0x1f7)](getLocalKnowledgeBases()),_0x1a17d6=_0x28a1e0['find'](_0x19fc81=>_0x19fc81['name']===_0x507caf);if(_0x1a17d6)_0x4c65df=_0x1a17d6['id'],_0x1be7bd(_0x1a4d5a(0x224)+_0x507caf+_0x1a4d5a(0x2c7),_0x1a4d5a(0x213));else{_0x1be7bd('[翰林院-核心]\x20准备为任务\x20\x22'+_0x507caf+_0x1a4d5a(0x297),_0x1a4d5a(0x213));const _0x215a13=addKnowledgeBase(_0x507caf,_0x1a4d5a(0x2ce));_0x4c65df=_0x215a13['id'];}const _0x5137c6=getCharacterStableId(),_0xcad96b=_0x5137c6+'_'+_0x4c65df;_0x1be7bd('[翰林院-核心]\x20凝识任务已锁定知识库:\x20'+_0x507caf+_0x1a4d5a(0x237)+_0xcad96b+')',_0x1a4d5a(0x218));const _0x52da1d=[],_0xa13e5b=context[_0x1a4d5a(0x299)];for(const _0x1c4b32 of _0x582019){const _0xe6d3e4=(_0x1c4b32['mes']||'')[_0x1a4d5a(0x28d)](/<[^>]*>/g,'')[_0x1a4d5a(0x2ca)]();if(_0xe6d3e4[_0x1a4d5a(0x272)]===0x0)continue;let _0x59f5e6;if(_0x1c4b32[_0x1a4d5a(0x2b2)]!==undefined&&_0x1c4b32[_0x1a4d5a(0x2b2)]!==null)_0x59f5e6=_0x1c4b32[_0x1a4d5a(0x2b2)];else{const _0x59f9f3=_0xa13e5b[_0x1a4d5a(0x1dc)](_0x33d54a=>_0x33d54a===_0x1c4b32);_0x59f5e6=_0x59f9f3!==-0x1?_0x59f9f3+0x1:-0x1;}const _0x484a09=new Date(_0x1c4b32['send_date']),_0x161ee9=isNaN(_0x484a09[_0x1a4d5a(0x29c)]())?new Date()[_0x1a4d5a(0x1db)]():_0x484a09[_0x1a4d5a(0x1db)](),_0x1a726e=splitIntoChunks(_0xe6d3e4,'chat_history',{'floor':_0x59f5e6,'is_user':_0x1c4b32['is_user'],'timestamp':_0x161ee9});_0x52da1d[_0x1a4d5a(0x2a0)](..._0x1a726e);}if(_0x52da1d[_0x1a4d5a(0x272)]===0x0)return{'success':!![],'count':0x0};_0x1be7bd('[翰林院-核心]\x20已将\x20'+_0x582019[_0x1a4d5a(0x272)]+_0x1a4d5a(0x203)+_0x52da1d['length']+_0x1a4d5a(0x2da),_0x1a4d5a(0x213));const _0x102715=settings['retrieval']['batchSize']||0x5;let _0x1ccb2a=0x0;for(let _0x4f56d8=0x0;_0x4f56d8<_0x52da1d['length'];_0x4f56d8+=_0x102715){const _0x3323ba=_0x52da1d[_0x1a4d5a(0x266)](_0x4f56d8,_0x4f56d8+_0x102715),_0x139e6a=_0x3323ba['map'](_0x4a34ec=>_0x4a34ec[_0x1a4d5a(0x25d)]),_0x17336f=await getEmbeddings(_0x139e6a);if(_0x3323ba['length']!==_0x17336f[_0x1a4d5a(0x272)])throw new Error(_0x1a4d5a(0x1e2));const _0x3acee9=_0x3323ba[_0x1a4d5a(0x287)]((_0x59ae7f,_0x55c2cd)=>({..._0x59ae7f,'vector':_0x17336f[_0x55c2cd]}));await insertVectors(_0x3acee9,null,_0xcad96b),_0x1ccb2a+=_0x3323ba[_0x1a4d5a(0x272)];}if(_0x5a6f6f){const _0x5bcfbb=_0x5a6f6f[_0x1a4d5a(0x267)]===0x0?context['chat']['length']:_0x5a6f6f['end'],_0x216bb7=getCharacterStableId();!settings[_0x1a4d5a(0x2a4)][_0x216bb7]&&(settings[_0x1a4d5a(0x2a4)][_0x216bb7]={}),settings[_0x1a4d5a(0x2a4)][_0x216bb7][_0xcad96b]={'start':_0x5a6f6f[_0x1a4d5a(0x216)],'end':_0x5bcfbb,'timestamp':new Date()[_0x1a4d5a(0x1db)]()},saveSettings(),_0x1be7bd(_0x1a4d5a(0x291)+_0xcad96b+_0x1a4d5a(0x2d9)+_0x5a6f6f['start']+'-'+_0x5bcfbb,_0x1a4d5a(0x213));}_0x1be7bd('[翰林院-核心]\x20聊天记录凝识完成,成功插入\x20'+_0x1ccb2a+_0x1a4d5a(0x276),_0x1a4d5a(0x218));const _0x47a8ff=_0x582019[_0x1a4d5a(0x287)](_0x14ce26=>{const _0xd5e032=_0x1a4d5a,_0x3cd7e5=_0xa13e5b[_0xd5e032(0x1dc)](_0x4f94ef=>_0x4f94ef===_0x14ce26),_0x1950a3=_0x3cd7e5!==-0x1?_0x3cd7e5+0x1:-0x1,_0xb55544=_0x14ce26[_0xd5e032(0x1e0)]?'用户':getCharacterName()||'AI';return'['+_0xb55544+_0xd5e032(0x271)+_0x1950a3+']\x20的消息已成功凝识。';});return{'success':!![],'count':_0x1ccb2a,'messages':_0x47a8ff};}catch(_0x27b2a8){return console['error'](_0x1a4d5a(0x2d4),_0x27b2a8),_0x1be7bd(_0x1a4d5a(0x24b)+_0x27b2a8[_0x1a4d5a(0x268)],_0x1a4d5a(0x28a)),{'success':![],'error':_0x27b2a8[_0x1a4d5a(0x268)]};}}async function rerankResults(_0x5af45f,_0x54ab5b,_0x3921e9){const _0x5f5954=_0x1d2ea6;let _0x118dfa=_0x5af45f;if(_0x3921e9['rerank'][_0x5f5954(0x215)]&&_0x5af45f[_0x5f5954(0x272)]>0x0){console[_0x5f5954(0x26d)]('[翰林院-Rerank]\x20开始外部API重排序...');try{const _0x11d658=_0x5af45f['map'](_0x360899=>_0x360899[_0x5f5954(0x25d)]),_0x3879b9=await executeRerank(_0x54ab5b,_0x11d658,_0x3921e9[_0x5f5954(0x24e)]),_0x21d292=_0x5af45f['map']((_0x47bf47,_0x563d5e)=>({..._0x47bf47,'original_index':_0x563d5e}));_0x118dfa=_0x21d292['map'](_0x368577=>{const _0x1e5ac0=_0x5f5954,_0x4c277c=_0x3879b9[_0x1e5ac0(0x269)][_0x1e5ac0(0x26e)](_0x4790b2=>_0x4790b2['index']===_0x368577[_0x1e5ac0(0x2d8)]),_0x50fb04=_0x4c277c?_0x4c277c[_0x1e5ac0(0x1fb)]:0x0;return{..._0x368577,'rerank_score':_0x50fb04};});if(_0x3921e9['rerank'][_0x5f5954(0x2e1)])showNotification(_0x5f5954(0x221),_0x5f5954(0x218));}catch(_0x41313d){console[_0x5f5954(0x28a)]('[翰林院-Rerank]\x20外部Rerank失败,将仅使用内部加权。',_0x41313d);if(_0x3921e9[_0x5f5954(0x24e)][_0x5f5954(0x2e1)])showNotification(_0x5f5954(0x292)+_0x41313d['message'],_0x5f5954(0x28a));_0x118dfa[_0x5f5954(0x2aa)](_0x42862c=>_0x42862c[_0x5f5954(0x1ec)]=0x0);}}else _0x118dfa[_0x5f5954(0x2aa)](_0x2702c4=>_0x2702c4['rerank_score']=0x0);console[_0x5f5954(0x26d)](_0x5f5954(0x2ac));const _0x1643e2=context[_0x5f5954(0x299)][_0x5f5954(0x272)],_0x2743bb=_0x3921e9[_0x5f5954(0x24e)][_0x5f5954(0x2be)],_0x73b4e0=_0x118dfa['map'](_0x28a1b6=>{const _0x513aab=_0x5f5954;let _0x25d7f4=0x1;const _0x5ad71c=_0x28a1b6[_0x513aab(0x282)]||{};switch(_0x5ad71c[_0x513aab(0x22a)]){case _0x513aab(0x256):_0x25d7f4*=1.2;break;case _0x513aab(0x259):_0x25d7f4*=1.1;break;case _0x513aab(0x2ce):if(_0x5ad71c['floor']&&_0x1643e2>0x0){const _0x525c56=_0x5ad71c[_0x513aab(0x2b2)]/_0x1643e2;_0x25d7f4*=0x1+_0x525c56;}break;}const _0x4d7d45=_0x28a1b6[_0x513aab(0x1ec)]*_0x2743bb+(_0x28a1b6[_0x513aab(0x2a5)]||0x0)*(0x1-_0x2743bb),_0x2dd2ba=_0x4d7d45*_0x25d7f4;return{'text':_0x28a1b6['text'],'score':_0x28a1b6[_0x513aab(0x2a5)],'rerank_score':_0x28a1b6['rerank_score'],'final_score':_0x2dd2ba,'metadata':_0x28a1b6['metadata']};});_0x73b4e0[_0x5f5954(0x2d2)]((_0x331b25,_0x30c1e8)=>(_0x30c1e8[_0x5f5954(0x2bc)]||0x0)-(_0x331b25[_0x5f5954(0x2bc)]||0x0)),console[_0x5f5954(0x26d)](_0x5f5954(0x21b));if(_0x3921e9[_0x5f5954(0x24e)][_0x5f5954(0x2d1)]){const _0x1da9d7=superSort(_0x73b4e0);return _0x1da9d7[_0x5f5954(0x266)](0x0,_0x3921e9['rerank']['top_n']);}return _0x73b4e0['slice'](0x0,_0x3921e9[_0x5f5954(0x24e)][_0x5f5954(0x251)]);}async function rearrangeChat(_0x2acfa8,_0x17cad4,_0x2cd366,_0x446282){const _0x1ec60f=_0x1d2ea6,_0x2fd192={'novel':'HANLINYUAN_RAG_NOVEL','chat_history':_0x1ec60f(0x21f),'lorebook':_0x1ec60f(0x1cf),'manual':_0x1ec60f(0x209)};Object[_0x1ec60f(0x1f7)](_0x2fd192)[_0x1ec60f(0x2aa)](_0x3ab711=>setExtensionPrompt(_0x3ab711,'',0x0,0x0,![],0x0));if(_0x446282==='quiet'||!settings['retrieval'][_0x1ec60f(0x215)])return;const _0x2e869d=_0x2acfa8[_0x1ec60f(0x266)](-settings[_0x1ec60f(0x285)][_0x1ec60f(0x29a)]);if(_0x2e869d[_0x1ec60f(0x272)]===0x0)return;const _0x28955b=_0x2e869d[_0x1ec60f(0x287)](_0x3b1265=>_0x3b1265[_0x1ec60f(0x204)])[_0x1ec60f(0x26c)]('\x20')['replace'](/<[^>]*>/g,'')[_0x1ec60f(0x2ca)]();if(!_0x28955b)return;try{const _0x2692a2=0x2,_0x4b8531=settings['settingsVersion']||0x1;let _0x5a5e67=![];if(_0x4b8531<_0x2692a2){console['log']('[翰林院-户口普查]\x20检测到旧版设置\x20(V'+_0x4b8531+_0x1ec60f(0x284)),toastr[_0x1ec60f(0x213)](_0x1ec60f(0x2ae),_0x1ec60f(0x289));const _0x1b177d=getKnowledgeBases();for(const _0x1edbdb of Object[_0x1ec60f(0x1f7)](_0x1b177d)){const _0x56547e=_0x1edbdb[_0x1ec60f(0x2dd)],_0x3ccc8b=_0x1edbdb[_0x1ec60f(0x22a)];if(_0x56547e[_0x1ec60f(0x1eb)](_0x1ec60f(0x2df)))_0x1edbdb[_0x1ec60f(0x22a)]=_0x1ec60f(0x259);else{if(_0x56547e[_0x1ec60f(0x1eb)]('小说:'))_0x1edbdb[_0x1ec60f(0x22a)]=_0x1ec60f(0x1d3);else _0x56547e['includes']('楼-')&&_0x56547e[_0x1ec60f(0x2a7)]('楼')&&_0x56547e[_0x1ec60f(0x2a7)](':')?_0x1edbdb[_0x1ec60f(0x22a)]=_0x1ec60f(0x2ce):_0x1edbdb['source']=_0x1ec60f(0x256);}_0x3ccc8b!==_0x1edbdb['source']&&console[_0x1ec60f(0x26d)](_0x1ec60f(0x283)+_0x56547e+_0x1ec60f(0x1dd)+(_0x3ccc8b||'无')+_0x1ec60f(0x244)+_0x1edbdb[_0x1ec60f(0x22a)]+']');}settings[_0x1ec60f(0x298)]=_0x2692a2,_0x5a5e67=!![];}_0x5a5e67&&(console['log'](_0x1ec60f(0x2a6)),saveSettings());let _0x2e87da=[];const _0x2becf2=settings[_0x1ec60f(0x24e)]['priorityRetrieval'];if(_0x2becf2[_0x1ec60f(0x215)]){console['log'](_0x1ec60f(0x265));const _0x53add5=Object['values'](getKnowledgeBases())[_0x1ec60f(0x1e3)](_0x6a522=>_0x6a522[_0x1ec60f(0x215)]),_0x3aab4e=Object['keys'](_0x2becf2[_0x1ec60f(0x1f0)])[_0x1ec60f(0x1e3)](_0x363c58=>_0x2becf2[_0x1ec60f(0x1f0)][_0x363c58]&&_0x2becf2['sources'][_0x363c58][_0x1ec60f(0x215)]),_0x81811d=[];let _0x25a0eb=[..._0x53add5];for(const _0x47b4d2 of _0x3aab4e){const _0x3c53bf=_0x2becf2[_0x1ec60f(0x1f0)][_0x47b4d2],_0x3ad4f9=_0x25a0eb[_0x1ec60f(0x1e3)](_0x145ec2=>_0x145ec2['source']===_0x47b4d2);_0x25a0eb=_0x25a0eb[_0x1ec60f(0x1e3)](_0x1b1ef1=>!_0x3ad4f9[_0x1ec60f(0x2a7)](_0x1b1ef1));if(_0x3ad4f9[_0x1ec60f(0x272)]>0x0){console[_0x1ec60f(0x26d)](_0x1ec60f(0x24a)+_0x47b4d2+'\x20('+_0x3ad4f9[_0x1ec60f(0x272)]+'个库)');const _0x34b2fb=queryVectors(_0x28955b,{'includeBases':_0x3ad4f9})[_0x1ec60f(0x231)](_0x3c6966=>{const _0x13a5a2=_0x1ec60f;console[_0x13a5a2(0x26d)](_0x13a5a2(0x200)+_0x47b4d2+_0x13a5a2(0x21d)+_0x3c6966[_0x13a5a2(0x272)]+'\x20条结果。');let _0x177c60=_0x3c6966[_0x13a5a2(0x1e3)](_0xae513f=>_0xae513f[_0x13a5a2(0x282)]?.['source']===_0x47b4d2);return _0x177c60=_0x177c60[_0x13a5a2(0x266)](0x0,_0x3c53bf[_0x13a5a2(0x2c5)]),console[_0x13a5a2(0x26d)](_0x13a5a2(0x22c)+_0x47b4d2+_0x13a5a2(0x261)+_0x177c60[_0x13a5a2(0x272)]+'\x20条结果。'),settings[_0x13a5a2(0x24e)][_0x13a5a2(0x2d1)]&&(_0x177c60=superSort(_0x177c60)),_0x177c60;});_0x81811d[_0x1ec60f(0x2a0)](_0x34b2fb);}}const _0x24827d=_0x25a0eb;if(_0x24827d[_0x1ec60f(0x272)]>0x0){console['log'](_0x1ec60f(0x2e2)+_0x24827d[_0x1ec60f(0x272)]+_0x1ec60f(0x239));const _0x5d10bb=queryVectors(_0x28955b,{'includeBases':_0x24827d})[_0x1ec60f(0x231)](async _0x155aad=>{const _0x2bcf50=_0x1ec60f;console[_0x2bcf50(0x26d)]('[翰林院]\x20常规组返回\x20'+_0x155aad[_0x2bcf50(0x272)]+_0x2bcf50(0x2b5)),console['log']('[翰林院]\x20开始处理常规池...');const _0x57309b=await rerankResults(_0x155aad,_0x28955b,settings);return console[_0x2bcf50(0x26d)](_0x2bcf50(0x1cd)+(_0x57309b||[])[_0x2bcf50(0x272)]+_0x2bcf50(0x2b5)),_0x57309b;});_0x81811d[_0x1ec60f(0x2a0)](_0x5d10bb);}const _0x5cae65=await Promise[_0x1ec60f(0x2c0)](_0x81811d);_0x2e87da=_0x5cae65[_0x1ec60f(0x23d)]();}else{console[_0x1ec60f(0x26d)](_0x1ec60f(0x1e7));const _0x6c67e0=await queryVectors(_0x28955b);_0x2e87da=await rerankResults(_0x6c67e0,_0x28955b,settings);}if(!_0x2e87da||_0x2e87da['length']===0x0){console[_0x1ec60f(0x26d)](_0x1ec60f(0x246));return;}console[_0x1ec60f(0x26d)](_0x1ec60f(0x210)+_0x2e87da[_0x1ec60f(0x272)]+_0x1ec60f(0x2b5));const _0x1dc8ab={'novel':[],'chat_history':[],'lorebook':[],'manual':[]};_0x2e87da['forEach'](_0x4d8e2d=>{const _0x214f1c=_0x1ec60f,_0x4e8990=_0x4d8e2d['metadata']?.[_0x214f1c(0x22a)];_0x4e8990&&_0x1dc8ab[_0x214f1c(0x24f)](_0x4e8990)&&_0x1dc8ab[_0x4e8990]['push'](_0x4d8e2d);});for(const _0x3d02ee in _0x1dc8ab){const _0xb14c05=_0x1dc8ab[_0x3d02ee];if(_0xb14c05[_0x1ec60f(0x272)]===0x0)continue;const _0x3a4865=settings[_0x1ec60f(0x1ca)+_0x3d02ee[_0x1ec60f(0x28d)]('_history','')];if(!_0x3a4865){console[_0x1ec60f(0x1d5)]('[翰林院]\x20未找到来源\x20\x27'+_0x3d02ee+_0x1ec60f(0x1de));continue;}const _0x583754=_0xb14c05[_0x1ec60f(0x287)](_0x35a5c5=>_0x35a5c5[_0x1ec60f(0x25d)])[_0x1ec60f(0x26c)]('\x0a\x0a'),_0x2ec5e1='{{'+_0x3d02ee[_0x1ec60f(0x28d)](_0x1ec60f(0x226),'')+_0x1ec60f(0x2bf);let _0x535ecd=_0x3a4865[_0x1ec60f(0x25e)][_0x1ec60f(0x28d)](_0x2ec5e1,_0x583754);_0x535ecd['trim']()&&(_0x535ecd='%%'+_0x2fd192[_0x3d02ee]+'%%'+_0x535ecd),setExtensionPrompt(_0x2fd192[_0x3d02ee],_0x535ecd,_0x3a4865[_0x1ec60f(0x295)],_0x3a4865[_0x1ec60f(0x23f)],![],_0x3a4865['depth_role']),console['log'](_0x1ec60f(0x20a)+_0x3d02ee+'\x27\x20注入\x20'+_0xb14c05['length']+'\x20条内容。');}}catch(_0xf07536){console[_0x1ec60f(0x28a)](_0x1ec60f(0x286),_0xf07536);if(settings['retrieval'][_0x1ec60f(0x2e1)])showNotification(_0x1ec60f(0x25b)+_0xf07536[_0x1ec60f(0x268)],_0x1ec60f(0x28a));}}async function moveKnowledgeBase(_0x5135c3,_0x45bf7a){const _0x589612=_0x1d2ea6,_0x52e2bf=_0x45bf7a===_0x589612(0x279)?_0x589612(0x28b):_0x589612(0x279),_0x16bc8e=getCharacterStableId();if(!_0x16bc8e&&_0x52e2bf==='local'){toastr[_0x589612(0x28a)](_0x589612(0x258));return;}const _0x33a72e=_0x45bf7a==='global'?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0xe68761=_0x52e2bf===_0x589612(0x279)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x263437=_0x33a72e[_0x5135c3];if(!_0x263437){const _0x9a5408=_0x589612(0x263)+_0x45bf7a+_0x589612(0x24c)+_0x5135c3+_0x589612(0x208);console['error'](_0x589612(0x262)+_0x9a5408),toastr[_0x589612(0x28a)](_0x589612(0x20f));return;}_0x45bf7a===_0x589612(0x28b)&&_0x52e2bf===_0x589612(0x279)&&!_0x263437['owner']&&(console[_0x589612(0x26d)](_0x589612(0x1f2)+_0x5135c3+_0x589612(0x223)+_0x16bc8e),_0x263437[_0x589612(0x2b4)]=_0x16bc8e);delete _0x33a72e[_0x5135c3],_0xe68761[_0x5135c3]=_0x263437,saveSettings();const _0x17b106='知识库【'+_0x263437[_0x589612(0x2dd)]+'】已成功移动到'+(_0x52e2bf===_0x589612(0x279)?'全局':'局部')+'。';console[_0x589612(0x26d)](_0x589612(0x262)+_0x17b106);}async function getAllVectorsFromCollection(_0x45d2a9){const _0x36d2c1=_0x1d2ea6,_0x3574b1='*',_0x52a280={'collectionId':_0x45d2a9,'searchText':_0x3574b1,'topK':0x2710,'threshold':0x0,'source':_0x36d2c1(0x20d),'embeddings':{}},_0x2d9eec=(await getEmbeddings([_0x3574b1]))[0x0];_0x52a280['embeddings']={[_0x3574b1]:_0x2d9eec};const _0x2411f9=await fetch(_0x36d2c1(0x264),{'method':_0x36d2c1(0x20b),'headers':context[_0x36d2c1(0x1ff)](),'body':JSON[_0x36d2c1(0x27b)](_0x52a280)});if(!_0x2411f9['ok']){if(_0x2411f9[_0x36d2c1(0x27f)]===0x194)return console[_0x36d2c1(0x26d)](_0x36d2c1(0x26f)+_0x45d2a9+_0x36d2c1(0x1e6)),[];const _0x121922=await _0x2411f9['text']();throw new Error(_0x36d2c1(0x20e)+_0x45d2a9+_0x36d2c1(0x2b3)+_0x121922);}const _0x3f46e2=await _0x2411f9['json']();return _0x3f46e2[_0x36d2c1(0x282)]||_0x3f46e2[_0x36d2c1(0x269)]||_0x3f46e2[_0x36d2c1(0x275)]||[];} From bf720ca642b1a2947e58a5d9929dd9ea53c95861 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Fri, 10 Oct 2025 22:05:17 +0800 Subject: [PATCH 02/29] Update rag-settings.js --- core/rag-settings.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/core/rag-settings.js b/core/rag-settings.js index 071a6fa..72aac6f 100644 --- a/core/rag-settings.js +++ b/core/rag-settings.js @@ -59,7 +59,28 @@ export const defaultSettings = { top_n: 5, hybrid_alpha: 0.7, notify: true, - superSortEnabled: false, + superSortEnabled: false, + priorityRetrieval: { + enabled: false, + sources: { + novel: { + enabled: false, + count: 5 + }, + chat_history: { + enabled: false, + count: 5 + }, + lorebook: { + enabled: false, + count: 5 + }, + manual: { + enabled: false, + count: 5 + } + } + }, }, knowledgeBases: {}, }; From 5499125094ba531f343cf0539427b4874451e65d Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Fri, 10 Oct 2025 22:06:21 +0800 Subject: [PATCH 03/29] Update hanlinyuan.html --- assets/hanlinyuan.html | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/assets/hanlinyuan.html b/assets/hanlinyuan.html index f070898..e85cae4 100644 --- a/assets/hanlinyuan.html +++ b/assets/hanlinyuan.html @@ -147,6 +147,63 @@ + +
+ 优先检索 +
+ + +
+ 启用后,可以为特定来源设置固定的检索数量,这些结果将必定被注入,不受后续Rerank和排序影响。未勾选的来源将共享剩余的检索名额。 + + +
+ +
+ + + + +
+ +
+ + + + +
+ +
+ + + + +
+ +
+ + + + +
+
+
感谢功能友情提供:Silence_Lurker潜默
+
From 8c30b51ab607737f3e2228670b8ff0f6d6783c63 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Fri, 10 Oct 2025 22:07:01 +0800 Subject: [PATCH 04/29] Update hanlinyuan.css --- assets/hanlinyuan.css | 78 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/assets/hanlinyuan.css b/assets/hanlinyuan.css index b5c35d8..ac6880b 100644 --- a/assets/hanlinyuan.css +++ b/assets/hanlinyuan.css @@ -208,6 +208,25 @@ margin-top: 2px; } +/* ------------------ 【V15.2 紧急修复】优先检索排版修正 ------------------ */ +#hly-modal-container .hly-priority-source-config .hly-control-block { + flex-direction: row; + align-items: center; + gap: 8px; /* 为元素之间提供一些间距 */ +} +#hly-modal-container .hly-priority-source-config .hly-control-block label:not(.hly-checkbox-label) { + white-space: nowrap; /* 防止 "固定检索:" 换行 */ + flex-shrink: 0; +} +#hly-modal-container .hly-priority-source-config .hly-control-block .hly-imperial-brush { + width: 60px; /* 固定输入框宽度 */ + flex-shrink: 0; + text-align: center; +} +#hly-modal-container .hly-priority-source-config .hly-control-block > span { + flex-shrink: 0; +} + /* ------------------ 按钮组 ------------------ */ #hly-modal-container .hly-button-group { display: flex; @@ -670,3 +689,62 @@ position: relative; margin-bottom: 8px; } + +/* ------------------ 【V15.3 新增 & V15.4 优化】功能署名样式 ------------------ */ +#hly-modal-container .hly-feature-credit { + position: absolute; + bottom: 10px; + right: 15px; + font-size: 0.9em; + font-style: italic; + font-weight: bold; + opacity: 0.9; + background: linear-gradient(90deg, #00d2ff 0%, #928DFF 100%); + -webkit-background-clip: text; + background-clip: text; + color: transparent; + pointer-events: none; + text-shadow: 0 0 4px rgba(200, 200, 255, 0.5); +} + +/* ------------------ 【V15.5】移动端响应式适配 ------------------ */ +@media (max-width: 768px) { + /* 知识库列表项 */ + #hly-modal-container .hly-kb-list-item { + flex-direction: column; + align-items: flex-start; + gap: 12px; /* 增加垂直间距 */ + } + + /* 知识库名称,将其与复选框包裹起来以便对齐 */ + #hly-modal-container .hly-kb-name-container { + display: flex; + align-items: center; + width: 100%; + } + + #hly-modal-container .hly-kb-name { + white-space: normal; /* 允许长标题换行 */ + word-break: break-all; /* 强制长单词换行 */ + flex-grow: 1; + margin-left: 8px; /* 与复选框的间距 */ + } + + /* 操作按钮容器 */ + #hly-modal-container .hly-kb-actions { + width: 100%; + justify-content: flex-end; /* 让按钮靠右对齐 */ + } + + /* 顶部批量操作按钮栏 */ + #hly-modal-container .hly-kb-toolbar { + flex-direction: column; + align-items: flex-start; + gap: 10px; + } + + #hly-modal-container .hly-kb-bulk-actions { + width: 100%; + justify-content: space-around; /* 让按钮均匀分布 */ + } +} From d6bcfe37ff68a3b11c1e0d1c6e9e2cebf14b3749 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Fri, 10 Oct 2025 22:07:51 +0800 Subject: [PATCH 05/29] Update hanlinyuan-bindings.js --- ui/hanlinyuan-bindings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/hanlinyuan-bindings.js b/ui/hanlinyuan-bindings.js index 27d962f..71ea82a 100644 --- a/ui/hanlinyuan-bindings.js +++ b/ui/hanlinyuan-bindings.js @@ -1 +1 @@ -const _0x2eed1f=_0x91bf;(function(_0x53e8fb,_0x57de97){const _0x4490c1=_0x91bf,_0x4c5056=_0x53e8fb();while(!![]){try{const _0x57bc76=parseInt(_0x4490c1(0x159))/0x1*(-parseInt(_0x4490c1(0x269))/0x2)+-parseInt(_0x4490c1(0x92))/0x3*(parseInt(_0x4490c1(0x1dd))/0x4)+parseInt(_0x4490c1(0x1c8))/0x5*(parseInt(_0x4490c1(0x247))/0x6)+parseInt(_0x4490c1(0x7e))/0x7+-parseInt(_0x4490c1(0x195))/0x8+-parseInt(_0x4490c1(0x26d))/0x9+-parseInt(_0x4490c1(0x25b))/0xa*(-parseInt(_0x4490c1(0x1a5))/0xb);if(_0x57bc76===_0x57de97)break;else _0x4c5056['push'](_0x4c5056['shift']());}catch(_0x2fc4d8){_0x4c5056['push'](_0x4c5056['shift']());}}}(_0x21f4,0x43cce));import{getContext}from'/scripts/extensions.js';import*as _0x222c37 from'../core/rag-processor.js';import*as _0x9d7bfc from'../core/historiographer.js';import*as _0x27cc29 from'../core/utils/context-utils.js';import*as _0x263e19 from'../core/ingestion-manager.js';import{showContentModal,showHtmlModal}from'./page-window.js';import{extractBlocksByTags,applyExclusionRules}from'../core/utils/rag-tag-extractor.js';import{filterWorldbooks,filterWorldbookEntries,highlightSearchMatch,debounce}from'../core/rag-processor.js';_0x2eed1f(0x17c);function setupGlobalEventHandlers(){const _0xdb1182=_0x2eed1f;window[_0xdb1182(0x104)]=()=>saveSettingsFromUI(![]),window[_0xdb1182(0x134)]=resetSettingsToUI,window[_0xdb1182(0x170)]=testApi,window[_0xdb1182(0x1f0)]=fetchHLYEmbeddingModels,window[_0xdb1182(0x8c)]=fetchHLYRerankModels,window[_0xdb1182(0x265)]=updatePanelStatus,window[_0xdb1182(0x20c)]=purgeStorage,window[_0xdb1182(0x112)]=startCondensation,window[_0xdb1182(0x194)]=previewCondensation,window[_0xdb1182(0x21a)]=ingestManualText,window[_0xdb1182(0x167)]=log,window[_0xdb1182(0x215)]=showStats,window[_0xdb1182(0x73)]=startHistoriography;}function updateAndSaveSetting(_0x1b367c,_0x16e83b){const _0x56f7ba=_0x2eed1f,_0x8e6d43=_0x222c37[_0x56f7ba(0x1f9)]();if(!_0x8e6d43)return;const _0x37d1ec=_0x1b367c[_0x56f7ba(0x7a)]('.');let _0x3f98cb=_0x8e6d43;for(let _0x3d87c3=0x0;_0x3d87c3<_0x37d1ec[_0x56f7ba(0x1a7)]-0x1;_0x3d87c3++){_0x3f98cb=_0x3f98cb[_0x37d1ec[_0x3d87c3]]=_0x3f98cb[_0x37d1ec[_0x3d87c3]]||{};}_0x3f98cb[_0x37d1ec[_0x37d1ec[_0x56f7ba(0x1a7)]-0x1]]=_0x16e83b,_0x222c37[_0x56f7ba(0x70)](),log(_0x56f7ba(0x225)+_0x1b367c+_0x56f7ba(0x126)+JSON[_0x56f7ba(0xbf)](_0x16e83b),_0x56f7ba(0x249));}function bindAutoSaveEvents(){const _0xcd32c3=_0x2eed1f,_0x49958a=document[_0xcd32c3(0x242)](_0xcd32c3(0x6b));if(!_0x49958a)return;_0x49958a['addEventListener'](_0xcd32c3(0x1ee),_0x32ed26=>{const _0x3f063c=_0xcd32c3,_0x8b449e=_0x32ed26[_0x3f063c(0x18a)],_0x3e4857=_0x8b449e[_0x3f063c(0x13c)]['settingKey'];if(!_0x3e4857)return;let _0x539310;const _0x103817=_0x8b449e[_0x3f063c(0x13c)][_0x3f063c(0x87)]||_0x3f063c(0xf1);if(_0x8b449e[_0x3f063c(0x87)]==='checkbox')_0x539310=_0x8b449e[_0x3f063c(0x13e)];else{if(_0x8b449e[_0x3f063c(0x87)]===_0x3f063c(0x11b)){if(_0x8b449e[_0x3f063c(0x13e)]){const _0x35e330=_0x49958a[_0x3f063c(0x25d)](_0x3f063c(0xe8)+_0x8b449e['name']+'\x22]'),_0x4b1902=Array[_0x3f063c(0xc0)](_0x35e330)['find'](_0x24de98=>_0x24de98['checked']);_0x539310=_0x4b1902[_0x3f063c(0x15e)];}else return;}else _0x539310=_0x8b449e['value'];}switch(_0x103817){case _0x3f063c(0x132):_0x539310=parseInt(_0x539310,0xa);break;case _0x3f063c(0x19d):_0x539310=parseFloat(_0x539310);break;case _0x3f063c(0x21f):typeof _0x539310!==_0x3f063c(0x21f)&&(_0x539310=_0x539310===_0x3f063c(0x163));break;}if(_0x8b449e[_0x3f063c(0x87)]===_0x3f063c(0x11b)&&!_0x8b449e[_0x3f063c(0x13e)])return;updateAndSaveSetting(_0x3e4857,_0x539310);});}export function bindHanlinyuanEvents(){const _0x59a90f=_0x2eed1f,_0x32ca7a=getContext();if(!_0x32ca7a){console[_0x59a90f(0xf4)]('[翰林院-枢纽]\x20未能获取SillyTavern上下文,绑定失败。');return;}setupGlobalEventHandlers(),bindPanelToggleEvents(),bindInternalUIEvents(),bindTutorialEvents(),bindAutoSaveEvents(),bindSessionLockEvent(),initializeUnifiedInjectionEditor();if(_0x222c37['initialize'])_0x222c37[_0x59a90f(0x1c9)]();else{console[_0x59a90f(0xf4)](_0x59a90f(0x16a));return;}loadSettingsToUI(),loadWorldbookList(),log(_0x59a90f(0x17a),_0x59a90f(0x1a4));const _0x2a2d9d=document['getElementById'](_0x59a90f(0x1e6)),_0x4bffe6=document[_0x59a90f(0x242)]('hanlinyuan-ingest-novel-file-name'),_0x550855=document[_0x59a90f(0x242)]('hanlinyuan-ingest-novel-start'),_0x1610ac=document[_0x59a90f(0x242)](_0x59a90f(0xa4)),_0xb0e167=document[_0x59a90f(0x242)]('hanlinyuan-ingest-progress-container'),_0x30f0bb=document['getElementById'](_0x59a90f(0x7d)),_0x9136d7=document[_0x59a90f(0x242)]('hanlinyuan-ingest-status'),_0x1adcca=document[_0x59a90f(0x242)](_0x59a90f(0x106));let _0x1340b0=null,_0x16b666=null;_0x2a2d9d[_0x59a90f(0x1cd)](_0x59a90f(0x1ee),_0x488348=>{const _0x2e9fa2=_0x59a90f;_0x1340b0=_0x488348['target'][_0x2e9fa2(0x260)][0x0],_0x1340b0?(_0x4bffe6[_0x2e9fa2(0x153)]=_0x1340b0[_0x2e9fa2(0x113)],_0x4bffe6['title']=_0x1340b0[_0x2e9fa2(0x113)]):_0x4bffe6[_0x2e9fa2(0x153)]=_0x2e9fa2(0x89);}),_0x550855[_0x59a90f(0x1cd)]('click',async()=>{const _0x36f58a=_0x59a90f;if(!_0x1340b0){toastr[_0x36f58a(0x17d)]('请先选择一个\x20.txt\x20文件');return;}let _0x43a77b=0x0;const _0x154e1e=_0x263e19[_0x36f58a(0x173)](_0x1340b0),_0xf8ff23=_0x263e19[_0x36f58a(0x1d0)](_0x154e1e);if(_0xf8ff23){const _0x31fabe=(_0xf8ff23['processedChunks']/_0xf8ff23[_0x36f58a(0x22f)]*0x64)['toFixed'](0x1),_0x40b90f=confirm('启禀大人,发现此书上次录入已完成\x20'+_0x31fabe+_0x36f58a(0x14e));_0x40b90f?(_0x43a77b=_0xf8ff23[_0x36f58a(0x10b)],toastr['info'](_0x36f58a(0x145)+(_0x43a77b+0x1)+'\x20块继续录入。',_0x36f58a(0x23f)),log(_0x36f58a(0xe5)+_0x154e1e+_0x36f58a(0xa8)+_0x43a77b+_0x36f58a(0x230),_0x36f58a(0x1a4))):(_0x263e19[_0x36f58a(0xc1)](_0x154e1e),toastr[_0x36f58a(0x1a4)](_0x36f58a(0x216),_0x36f58a(0x23f)),log('[断点续传]\x20用户选择放弃旧任务\x20'+_0x154e1e+_0x36f58a(0x9e),_0x36f58a(0x205)));}_0x16b666=new AbortController();const _0x5f4fee=_0x16b666['signal'];_0x1adcca[_0x36f58a(0x191)][_0x36f58a(0x1e1)]=_0x36f58a(0xc7),_0xb0e167[_0x36f58a(0x191)]['display']=_0x36f58a(0x1a1),_0x9136d7['textContent']=_0x36f58a(0x12e),_0x30f0bb[_0x36f58a(0x15e)]=0x0;try{const _0x1ba543=await _0x1340b0['text'](),_0x395440=_0x4fd023=>{const _0x8735a4=_0x36f58a;_0x9136d7['textContent']=_0x8735a4(0x136)+_0x4fd023[_0x8735a4(0x13f)]+'\x20('+_0x4fd023[_0x8735a4(0xaf)]+'/'+_0x4fd023[_0x8735a4(0xbe)]+')',_0x30f0bb['value']=_0x4fd023['processed']/_0x4fd023[_0x8735a4(0xbe)]*0x64;},_0x56bae3=()=>{updatePanelStatus(),log('[实时刷新]\x20批次完成,忆识总数已更新。','info');},_0x34fc08=await _0x222c37['ingestTextToHanlinyuan'](_0x1ba543,_0x36f58a(0x1bc),{'sourceName':_0x1340b0['name']},_0x395440,_0x5f4fee,log,_0x56bae3,_0x154e1e,_0x43a77b);if(_0x34fc08[_0x36f58a(0x249)])toastr['success'](_0x36f58a(0xfc)+_0x34fc08[_0x36f58a(0x165)]+_0x36f58a(0x189)),_0x9136d7[_0x36f58a(0x153)]=_0x36f58a(0x97)+_0x34fc08[_0x36f58a(0x165)]+_0x36f58a(0x1e5),_0x30f0bb[_0x36f58a(0x15e)]=0x64,updatePanelStatus();else throw new Error(_0x34fc08['error']||_0x36f58a(0xc6));}catch(_0x52a0d5){_0x52a0d5['name']===_0x36f58a(0x21b)?(toastr[_0x36f58a(0x1a4)](_0x36f58a(0x7c)),_0x9136d7[_0x36f58a(0x153)]='任务已中止。'):(toastr['error'](_0x36f58a(0x141)+_0x52a0d5['message']+_0x36f58a(0x1ce)),_0x9136d7[_0x36f58a(0x153)]=_0x36f58a(0x188)+_0x52a0d5[_0x36f58a(0x13f)]);}finally{setTimeout(()=>{const _0xb1254b=_0x36f58a;_0x1adcca[_0xb1254b(0x191)][_0xb1254b(0x1e1)]=_0xb1254b(0x185),_0xb0e167['style'][_0xb1254b(0x1e1)]=_0xb1254b(0xc7),_0x2a2d9d[_0xb1254b(0x15e)]='',_0x1340b0=null,_0x4bffe6[_0xb1254b(0x153)]=_0xb1254b(0x89);},0xbb8);}}),_0x1610ac['addEventListener'](_0x59a90f(0x217),()=>{const _0x1a3f0a=_0x59a90f;_0x16b666&&_0x16b666[_0x1a3f0a(0x13b)]();});}function bindSessionLockEvent(){const _0xe8aae0=_0x2eed1f,_0x488ccd=document[_0xe8aae0(0x242)](_0xe8aae0(0x84));if(!_0x488ccd)return;_0x488ccd[_0xe8aae0(0x1cd)]('click',async()=>{const _0x37dcc3=_0xe8aae0,_0x12a74e=await _0x222c37[_0x37dcc3(0xc2)]();updateSessionLockUI(_0x12a74e);if(_0x12a74e){const _0xf397f6=_0x222c37[_0x37dcc3(0x152)]();_0xf397f6&&(toastr[_0x37dcc3(0x249)](_0x37dcc3(0x150)+_0xf397f6['id'],_0x37dcc3(0xa7)),log('会话已锁定到宝库:\x20'+_0xf397f6['id'],_0x37dcc3(0x249)));}else toastr['info'](_0x37dcc3(0x8d),'诏曰'),log(_0x37dcc3(0x183),_0x37dcc3(0x1a4));updatePanelStatus();}),updateSessionLockUI(_0x222c37[_0xe8aae0(0x250)]());}function updateSessionLockUI(_0x547abd){const _0x33342f=_0x2eed1f,_0x3b74fd=document[_0x33342f(0x242)](_0x33342f(0x84));if(!_0x3b74fd)return;const _0x294209=_0x3b74fd[_0x33342f(0x1dc)]('i'),_0x351c88=_0x3b74fd['querySelector'](_0x33342f(0x6d));_0x547abd?(_0x3b74fd[_0x33342f(0x22b)][_0x33342f(0xe7)]('active'),_0x294209[_0x33342f(0x229)]=_0x33342f(0x7f),_0x351c88[_0x33342f(0x153)]=_0x33342f(0x18e),_0x3b74fd['title']=_0x33342f(0x12a)):(_0x3b74fd[_0x33342f(0x22b)][_0x33342f(0x24c)](_0x33342f(0x10c)),_0x294209['className']=_0x33342f(0x266),_0x351c88[_0x33342f(0x153)]=_0x33342f(0xb4),_0x3b74fd['title']=_0x33342f(0xa6));}function bindPanelToggleEvents(){const _0x18b8b2=_0x2eed1f,_0x4318f0=document[_0x18b8b2(0x242)](_0x18b8b2(0xfa));if(_0x4318f0){}}function bindTutorialEvents(){const _0x48a130=_0x2eed1f,_0x589c87=document['getElementById'](_0x48a130(0x255));_0x589c87&&_0x589c87['addEventListener'](_0x48a130(0x217),()=>{const _0x1f1757=_0x48a130;showContentModal(_0x1f1757(0x26a),_0x1f1757(0x1be));});}function bindInternalUIEvents(){const _0x18096f=_0x2eed1f,_0x445cc2=document[_0x18096f(0x25d)](_0x18096f(0xa5));_0x445cc2['forEach'](_0x5db251=>{const _0xf1cdde=_0x18096f;_0x5db251[_0xf1cdde(0x1cd)]('click',()=>{const _0x15246a=_0xf1cdde,_0x4a5911=_0x5db251['dataset'][_0x15246a(0x16e)],_0x409543='hly-'+_0x4a5911+_0x15246a(0x227);document[_0x15246a(0x25d)]('.hly-tab-pane')[_0x15246a(0x1d2)](_0x4257ec=>{const _0x36ff74=_0x15246a;_0x4257ec[_0x36ff74(0x22b)][_0x36ff74(0x1a6)](_0x36ff74(0x10c),_0x4257ec['id']===_0x409543);}),_0x445cc2[_0x15246a(0x1d2)](_0x4d6c8f=>_0x4d6c8f[_0x15246a(0x22b)][_0x15246a(0x1a6)]('active',_0x4d6c8f===_0x5db251));});});const _0x1f81d1=document[_0x18096f(0x242)]('hly-api-endpoint');_0x1f81d1&&_0x1f81d1[_0x18096f(0x1cd)]('change',handleApiModeChange);const _0x4908fd=document[_0x18096f(0x242)](_0x18096f(0xeb)),_0x156dd5=document['getElementById']('hly-tag-input-container');_0x4908fd&&_0x156dd5&&_0x4908fd[_0x18096f(0x1cd)](_0x18096f(0x1ee),()=>{const _0x53a294=_0x18096f;_0x156dd5[_0x53a294(0x191)]['display']=_0x4908fd['checked']?'block':_0x53a294(0xc7);});const _0x174d36=document[_0x18096f(0x242)](_0x18096f(0x23b));_0x174d36&&_0x174d36[_0x18096f(0x1cd)](_0x18096f(0x1ee),handleWorldbookSelectionChange);const _0x2169a5=document[_0x18096f(0x242)]('hly-exclusion-rules-btn');_0x2169a5&&_0x2169a5[_0x18096f(0x1cd)]('click',showExclusionRulesModal);const _0x59cf21=document[_0x18096f(0x242)]('hly-hist-entry-multiselect-btn'),_0x73b81a=document[_0x18096f(0x242)](_0x18096f(0x1ef));_0x59cf21&&_0x73b81a&&(_0x59cf21['addEventListener'](_0x18096f(0x217),_0x76ea7b=>{const _0x4df355=_0x18096f;_0x76ea7b[_0x4df355(0x76)]();const _0x4ee04b=_0x73b81a[_0x4df355(0x191)]['display']===_0x4df355(0x1a1);_0x73b81a[_0x4df355(0x191)][_0x4df355(0x1e1)]=_0x4ee04b?'none':_0x4df355(0x1a1);}),_0x73b81a[_0x18096f(0x1cd)]('change',_0x184f6e=>{const _0x4f33c2=_0x18096f,_0x34c041=_0x184f6e[_0x4f33c2(0x18a)];if(_0x34c041[_0x4f33c2(0x87)]!==_0x4f33c2(0x1fc))return;const _0x1ecec7=_0x73b81a[_0x4f33c2(0x25d)](_0x4f33c2(0x231)),_0x2afb8c=document[_0x4f33c2(0x242)](_0x4f33c2(0x100));if(_0x34c041['id']===_0x4f33c2(0x100))_0x1ecec7[_0x4f33c2(0x1d2)](_0x138b3b=>_0x138b3b['checked']=_0x34c041['checked']);else{const _0x3d30f1=Array[_0x4f33c2(0xc0)](_0x1ecec7)['every'](_0x3198f4=>_0x3198f4[_0x4f33c2(0x13e)]);_0x2afb8c[_0x4f33c2(0x13e)]=_0x3d30f1;}const _0x10cecf=_0x73b81a[_0x4f33c2(0x25d)](_0x4f33c2(0x21e))['length'],_0x505e92=_0x1ecec7[_0x4f33c2(0x1a7)];_0x59cf21[_0x4f33c2(0x1dc)](_0x4f33c2(0x6d))['textContent']=_0x4f33c2(0x1ec)+_0x10cecf+'\x20/\x20'+_0x505e92+_0x4f33c2(0x15b);}),document['addEventListener']('click',_0x46231e=>{const _0x428f68=_0x18096f;!_0x59cf21[_0x428f68(0x26c)](_0x46231e['target'])&&!_0x73b81a[_0x428f68(0x26c)](_0x46231e[_0x428f68(0x18a)])&&(_0x73b81a[_0x428f68(0x191)][_0x428f68(0x1e1)]=_0x428f68(0xc7));}));const _0xf710ed=document['getElementById'](_0x18096f(0x124));_0xf710ed&&_0xf710ed['addEventListener']('click',deleteAllLocalKnowledgeBases);const _0x111206=document['getElementById'](_0x18096f(0x1ff));_0x111206&&_0x111206['addEventListener'](_0x18096f(0x217),()=>moveAllKnowledgeBases(_0x18096f(0x1c3)));const _0x3c038f=document['getElementById'](_0x18096f(0x1ad));_0x3c038f&&_0x3c038f['addEventListener'](_0x18096f(0x217),()=>moveAllKnowledgeBases(_0x18096f(0x224)));const _0x153405=[_0x18096f(0x12c),_0x18096f(0x22c)];_0x153405[_0x18096f(0x1d2)](_0x168654=>{const _0x2fe279=_0x18096f,_0x358ca5=document[_0x2fe279(0x242)](_0x168654);_0x358ca5&&(_0x358ca5[_0x2fe279(0x1cd)](_0x2fe279(0x217),handleKbAction),_0x358ca5[_0x2fe279(0x1cd)](_0x2fe279(0x1ee),handleKbAction));}),document['getElementById'](_0x18096f(0x223))[_0x18096f(0x1cd)](_0x18096f(0x1ee),_0x450273=>handleSelectAll(_0x450273,_0x18096f(0x118))),document[_0x18096f(0x242)]('hly-kb-select-all-local')['addEventListener'](_0x18096f(0x1ee),_0xcdaa76=>handleSelectAll(_0xcdaa76,_0x18096f(0x1eb))),document['getElementById'](_0x18096f(0x10a))['addEventListener']('click',_0x4be060=>handleBulkAction(_0x4be060,'global')),document[_0x18096f(0x242)](_0x18096f(0x204))[_0x18096f(0x1cd)]('click',_0x443b7b=>handleBulkAction(_0x443b7b,_0x18096f(0x1eb)));}function initializeUnifiedInjectionEditor(){const _0x10f115=_0x2eed1f,_0x228011=document['getElementById'](_0x10f115(0x1c4)),_0x2a5fc7=document[_0x10f115(0x242)]('hly-unified-template-editor'),_0xb43f10=document['getElementById'](_0x10f115(0x235)),_0x256826=document[_0x10f115(0x25d)](_0x10f115(0x23c)),_0x300e7a=document[_0x10f115(0x242)](_0x10f115(0x129)),_0x509a18=document[_0x10f115(0x242)]('hly-unified-injection-role');if(!_0x228011)return;const _0x16a74b={'novel':'{{novel_text}}','chat':_0x10f115(0xa9),'lorebook':'{{lorebook_text}}','manual':_0x10f115(0xa0)};function _0xc77ce4(){const _0x534afa=_0x10f115,_0x35cdf0=_0x228011[_0x534afa(0x15e)],_0xe88796=_0x222c37['getSettings'](),_0x1fb55d=_0xe88796['injection_'+_0x35cdf0]||{};_0x2a5fc7['value']=_0x1fb55d[_0x534afa(0x268)]||'',_0xb43f10[_0x534afa(0x153)]='以\x20'+(_0x16a74b[_0x35cdf0]||_0x534afa(0xb0))+_0x534afa(0x139);const _0x9b2890=_0x1fb55d[_0x534afa(0x117)]!==undefined?String(_0x1fb55d[_0x534afa(0x117)]):'2';_0x256826[_0x534afa(0x1d2)](_0x13105c=>_0x13105c[_0x534afa(0x13e)]=_0x13105c[_0x534afa(0x15e)]===_0x9b2890),_0x300e7a[_0x534afa(0x15e)]=_0x1fb55d[_0x534afa(0x1aa)]||0x0,_0x509a18['value']=_0x1fb55d[_0x534afa(0xde)]!==undefined?String(_0x1fb55d[_0x534afa(0xde)]):'0';const _0x3dfb3a=_0x9b2890==='1';_0x300e7a[_0x534afa(0xd5)]=!_0x3dfb3a,_0x509a18[_0x534afa(0xd5)]=!_0x3dfb3a;}function _0x5f3b6e(){const _0x1c5035=_0x10f115,_0x4429de=_0x228011[_0x1c5035(0x15e)];updateAndSaveSetting('injection_'+_0x4429de+'.template',_0x2a5fc7[_0x1c5035(0x15e)]);const _0x430985=document[_0x1c5035(0x1dc)]('input[name=\x22hly-unified-injection-position\x22]:checked');_0x430985&&updateAndSaveSetting(_0x1c5035(0xdb)+_0x4429de+_0x1c5035(0x251),parseInt(_0x430985[_0x1c5035(0x15e)],0xa)),updateAndSaveSetting(_0x1c5035(0xdb)+_0x4429de+'.depth',parseInt(_0x300e7a[_0x1c5035(0x15e)],0xa)),updateAndSaveSetting(_0x1c5035(0xdb)+_0x4429de+'.depth_role',parseInt(_0x509a18['value'],0xa));}_0x228011[_0x10f115(0x1cd)](_0x10f115(0x1ee),_0xc77ce4);const _0x1a20be=debounce(_0x5f3b6e,0x12c);_0x2a5fc7[_0x10f115(0x1cd)](_0x10f115(0x82),_0x1a20be),_0x300e7a['addEventListener'](_0x10f115(0x1ee),_0x5f3b6e),_0x509a18['addEventListener']('change',_0x5f3b6e),_0x256826[_0x10f115(0x1d2)](_0x596ce7=>_0x596ce7['addEventListener'](_0x10f115(0x1ee),()=>{const _0x5e5de9=_0x10f115;_0x5f3b6e();const _0x21639b=_0x596ce7[_0x5e5de9(0x15e)]==='1'&&_0x596ce7[_0x5e5de9(0x13e)];_0x300e7a[_0x5e5de9(0xd5)]=!_0x21639b,_0x509a18['disabled']=!_0x21639b;})),_0xc77ce4();}function handleApiModeChange(){const _0x32c35e=_0x2eed1f,_0x34362a=document[_0x32c35e(0x242)]('hly-api-endpoint')['value'],_0x159129=document[_0x32c35e(0x242)](_0x32c35e(0x74)),_0x3e9434=document[_0x32c35e(0x242)](_0x32c35e(0xd2)),_0xe3fb22=document[_0x32c35e(0x242)](_0x32c35e(0x81)),_0x2481c1=_0xe3fb22[_0x32c35e(0x218)];if(!_0x159129||!_0x3e9434)return;_0x159129['style'][_0x32c35e(0x1e1)]='block',_0x3e9434[_0x32c35e(0x191)]['display']=_0x32c35e(0x1a1);switch(_0x34362a){case'google_direct':_0x159129[_0x32c35e(0x191)][_0x32c35e(0x1e1)]='none',_0x3e9434[_0x32c35e(0x1dc)](_0x32c35e(0x1df))[_0x32c35e(0x153)]=_0x32c35e(0xe0),_0x3e9434[_0x32c35e(0x1dc)](_0x32c35e(0x82))[_0x32c35e(0x147)]='请输入您的Google\x20API\x20Key';break;case _0x32c35e(0x1bf):_0x159129['querySelector']('label')[_0x32c35e(0x153)]='本地代理地址:',_0x159129[_0x32c35e(0x1dc)](_0x32c35e(0x82))[_0x32c35e(0x147)]='例如\x20http://127.0.0.1:8000/v1',_0x3e9434['style'][_0x32c35e(0x1e1)]=_0x32c35e(0xc7);break;case'custom':default:_0x159129[_0x32c35e(0x1dc)](_0x32c35e(0x1df))['textContent']='自定义路径:',_0x159129[_0x32c35e(0x1dc)](_0x32c35e(0x82))['placeholder']=_0x32c35e(0xf5),_0x3e9434[_0x32c35e(0x1dc)](_0x32c35e(0x1df))[_0x32c35e(0x153)]='通行令牌\x20(API\x20Key):';break;}}function loadSettingsToUI(){const _0x219a09=_0x2eed1f,_0x419957=_0x222c37['getSettings']();if(!_0x419957)return;document[_0x219a09(0x242)](_0x219a09(0xb1))['checked']=_0x419957[_0x219a09(0x99)][_0x219a09(0x209)],document['getElementById'](_0x219a09(0x18c))[_0x219a09(0x15e)]=_0x419957[_0x219a09(0x99)][_0x219a09(0xec)],document[_0x219a09(0x242)](_0x219a09(0x264))[_0x219a09(0x15e)]=_0x419957[_0x219a09(0x99)][_0x219a09(0x240)],document[_0x219a09(0x242)](_0x219a09(0x149))['value']=_0x419957[_0x219a09(0x99)][_0x219a09(0x1f7)];const _0x347d8a=document[_0x219a09(0x242)](_0x219a09(0x81));if(_0x347d8a['options'][_0x219a09(0x1a7)]===0x0){const _0x46bbd6=_0x419957[_0x219a09(0x99)][_0x219a09(0xed)],_0x16a0ca=new Option(_0x46bbd6,_0x46bbd6,!![],!![]);_0x347d8a[_0x219a09(0xe7)](_0x16a0ca);}_0x347d8a['value']=_0x419957[_0x219a09(0x99)][_0x219a09(0xed)],document[_0x219a09(0x242)](_0x219a09(0xf6))[_0x219a09(0x13e)]=_0x419957[_0x219a09(0x99)][_0x219a09(0x199)],document[_0x219a09(0x242)](_0x219a09(0x19a))[_0x219a09(0x15e)]=_0x419957[_0x219a09(0x181)][_0x219a09(0x1b3)],document[_0x219a09(0x242)](_0x219a09(0x1d5))['value']=_0x419957['advanced'][_0x219a09(0x1cb)],document[_0x219a09(0x242)](_0x219a09(0x17b))[_0x219a09(0x15e)]=_0x419957['advanced'][_0x219a09(0x111)],document['getElementById']('hly-query-message-count')[_0x219a09(0x15e)]=_0x419957['advanced'][_0x219a09(0x78)],document[_0x219a09(0x242)](_0x219a09(0x11f))[_0x219a09(0x15e)]=_0x419957[_0x219a09(0x181)]['maxResults'],document[_0x219a09(0x242)](_0x219a09(0x109))[_0x219a09(0x15e)]=_0x419957[_0x219a09(0x99)]['batchSize'],handleApiModeChange(),document[_0x219a09(0x242)]('hly-condensation-enabled')['checked']=_0x419957['condensation']['enabled'],document[_0x219a09(0x242)](_0x219a09(0x198))[_0x219a09(0x15e)]=_0x419957[_0x219a09(0x221)][_0x219a09(0x25f)],document[_0x219a09(0x242)](_0x219a09(0x10e))[_0x219a09(0x15e)]=_0x419957[_0x219a09(0x221)][_0x219a09(0x14a)],document[_0x219a09(0x242)](_0x219a09(0x237))[_0x219a09(0x13e)]=_0x419957['condensation'][_0x219a09(0xa2)][_0x219a09(0x7b)],document[_0x219a09(0x242)]('hly-include-ai')[_0x219a09(0x13e)]=_0x419957[_0x219a09(0x221)][_0x219a09(0xa2)]['ai'];const _0x504881=document[_0x219a09(0x242)]('hly-tag-extraction-toggle'),_0x17c410=document[_0x219a09(0x242)](_0x219a09(0x12f)),_0x1a212c=document[_0x219a09(0x242)](_0x219a09(0x239));_0x504881[_0x219a09(0x13e)]=_0x419957['condensation'][_0x219a09(0x222)],_0x17c410[_0x219a09(0x15e)]=_0x419957[_0x219a09(0x221)]['tags'],_0x1a212c['style']['display']=_0x504881[_0x219a09(0x13e)]?_0x219a09(0x1a1):_0x219a09(0xc7),document['getElementById'](_0x219a09(0x24e))[_0x219a09(0x13e)]=_0x419957['rerank'][_0x219a09(0x209)],document[_0x219a09(0x242)](_0x219a09(0xfd))[_0x219a09(0x15e)]=_0x419957[_0x219a09(0x18f)]['url'],document[_0x219a09(0x242)](_0x219a09(0x15f))[_0x219a09(0x15e)]=_0x419957[_0x219a09(0x18f)][_0x219a09(0x1f7)];const _0x4bee8b=document[_0x219a09(0x242)]('hly-rerank-model');if(_0x4bee8b[_0x219a09(0x232)]['length']===0x0){const _0x58807f=_0x419957[_0x219a09(0x18f)]['model'];if(_0x58807f){const _0x3e1768=new Option(_0x58807f,_0x58807f,!![],!![]);_0x4bee8b[_0x219a09(0xe7)](_0x3e1768);}}_0x4bee8b[_0x219a09(0x15e)]=_0x419957[_0x219a09(0x18f)]['model'],document[_0x219a09(0x242)]('hly-rerank-top-n')['value']=_0x419957[_0x219a09(0x18f)]['top_n'],document[_0x219a09(0x242)]('hly-rerank-hybrid-alpha')[_0x219a09(0x15e)]=_0x419957[_0x219a09(0x18f)][_0x219a09(0x12b)],document[_0x219a09(0x242)](_0x219a09(0x1a0))[_0x219a09(0x13e)]=_0x419957['rerank'][_0x219a09(0x199)],document['getElementById']('hly-super-sort-enabled')[_0x219a09(0x13e)]=_0x419957[_0x219a09(0x18f)]['superSortEnabled'];}function saveSettingsFromUI(_0x4b8aae=!![]){const _0x1fd7b9=_0x2eed1f,_0x5b0f6b=document[_0x1fd7b9(0x242)](_0x1fd7b9(0x6b));if(!_0x5b0f6b)return;const _0x49ebfc=_0x5b0f6b[_0x1fd7b9(0x25d)](_0x1fd7b9(0x1ba));_0x49ebfc['forEach'](_0x50b97b=>{const _0x36abf6=_0x1fd7b9,_0x427a39=_0x50b97b[_0x36abf6(0x13c)][_0x36abf6(0x193)];if(!_0x427a39)return;let _0x591493;const _0x505520=_0x50b97b[_0x36abf6(0x13c)]['type']||_0x36abf6(0xf1);if(_0x50b97b['type']==='checkbox')_0x591493=_0x50b97b[_0x36abf6(0x13e)];else{if(_0x50b97b[_0x36abf6(0x87)]==='radio'){if(!_0x50b97b['checked'])return;_0x591493=_0x50b97b['value'];}else _0x591493=_0x50b97b[_0x36abf6(0x15e)];}switch(_0x505520){case'integer':_0x591493=parseInt(_0x591493,0xa);break;case _0x36abf6(0x19d):_0x591493=parseFloat(_0x591493);break;case _0x36abf6(0x21f):if(typeof _0x591493!=='boolean')_0x591493=_0x591493===_0x36abf6(0x163);break;}const _0xb6fde7=_0x222c37[_0x36abf6(0x1f9)](),_0x56e00a=_0x427a39['split']('.');let _0x2c2428=_0xb6fde7;for(let _0xf2e9d=0x0;_0xf2e9d<_0x56e00a[_0x36abf6(0x1a7)]-0x1;_0xf2e9d++){_0x2c2428=_0x2c2428[_0x56e00a[_0xf2e9d]]=_0x2c2428[_0x56e00a[_0xf2e9d]]||{};}_0x2c2428[_0x56e00a[_0x56e00a[_0x36abf6(0x1a7)]-0x1]]=_0x591493;}),_0x222c37[_0x1fd7b9(0x70)](),!_0x4b8aae&&(log(_0x1fd7b9(0x1f1),_0x1fd7b9(0x249)),toastr[_0x1fd7b9(0x249)](_0x1fd7b9(0xb2),_0x1fd7b9(0x23f)));}function resetSettingsToUI(){const _0x43d5d1=_0x2eed1f;confirm(_0x43d5d1(0x176))&&(_0x222c37[_0x43d5d1(0x243)](),loadSettingsToUI(),toastr[_0x43d5d1(0x1a4)](_0x43d5d1(0x15c),'诏曰'));}async function updatePanelStatus(){const _0x2e3d7d=_0x2eed1f,_0x163d16=_0x222c37[_0x2e3d7d(0x250)](),_0x1060de=document[_0x2e3d7d(0x242)](_0x2e3d7d(0x1e2)),_0xe2e094=document[_0x2e3d7d(0x242)](_0x2e3d7d(0xcd));if(_0x163d16){const _0x22d101=_0x222c37['getLockedSessionInfo']();_0x22d101&&(_0x1060de[_0x2e3d7d(0x153)]=_0x2e3d7d(0x18b),_0xe2e094['textContent']=_0x22d101['id'],_0xe2e094[_0x2e3d7d(0x122)]='当前所有操作都将指向这个锁定的宝库:'+_0x22d101['id'],_0x1060de[_0x2e3d7d(0x22b)][_0x2e3d7d(0xe7)]('hly-locked-status'),_0xe2e094[_0x2e3d7d(0x22b)][_0x2e3d7d(0xe7)](_0x2e3d7d(0x101)));}else _0x1060de[_0x2e3d7d(0x153)]=_0x27cc29[_0x2e3d7d(0x107)](),_0xe2e094[_0x2e3d7d(0x153)]=_0x27cc29[_0x2e3d7d(0x13d)]()||'无',_0xe2e094[_0x2e3d7d(0x122)]='',_0x1060de['classList'][_0x2e3d7d(0x24c)]('hly-locked-status'),_0xe2e094[_0x2e3d7d(0x22b)]['remove'](_0x2e3d7d(0x101));const _0x285b3e=document[_0x2e3d7d(0x242)](_0x2e3d7d(0x71));_0x285b3e[_0x2e3d7d(0x153)]=_0x2e3d7d(0x1a9);try{const _0x257293=await _0x222c37['getVectorCount']();_0x285b3e[_0x2e3d7d(0x153)]=_0x257293;}catch(_0x59af74){console[_0x2e3d7d(0xf4)](_0x2e3d7d(0x1c5),_0x59af74),_0x285b3e[_0x2e3d7d(0x153)]=_0x2e3d7d(0x6f),_0x285b3e[_0x2e3d7d(0x122)]=_0x2e3d7d(0x102)+_0x59af74[_0x2e3d7d(0x13f)];}const _0x45eaba=document['getElementById'](_0x2e3d7d(0x1b7));if(_0x45eaba&&!_0x45eaba['dataset'][_0x2e3d7d(0xa1)]){const _0x3dbf6f=_0x222c37[_0x2e3d7d(0x1f9)](),_0x2981b4=await _0x222c37[_0x2e3d7d(0x154)]();if(_0x3dbf6f[_0x2e3d7d(0x186)]&&_0x3dbf6f[_0x2e3d7d(0x186)][_0x2981b4]){const _0x4c8035=_0x3dbf6f[_0x2e3d7d(0x186)][_0x2981b4];_0x45eaba[_0x2e3d7d(0x1d7)]='上次已从第\x20'+_0x4c8035[_0x2e3d7d(0x207)]+_0x2e3d7d(0x1c0)+_0x4c8035[_0x2e3d7d(0x23d)]+'\x20楼。

';}else _0x45eaba[_0x2e3d7d(0x1d7)]='可在此预览凝识结果。

';}renderKnowledgeBases();}async function moveAllKnowledgeBases(_0x4deef9){const _0x4bf2d8=_0x2eed1f,_0x165969=_0x4deef9===_0x4bf2d8(0x1c3),_0x1df23b=_0x165969?'global':_0x4bf2d8(0x1eb),_0x122e8f=_0x165969?'局部':'全局',_0x2dece0=_0x165969?_0x222c37[_0x4bf2d8(0x143)]():_0x222c37[_0x4bf2d8(0x67)](),_0x316b91=Object['keys'](_0x2dece0);if(_0x316b91[_0x4bf2d8(0x1a7)]===0x0){toastr['info'](_0x4bf2d8(0x1b0)+(_0x165969?'全局':'局部')+_0x4bf2d8(0x75),'圣谕');return;}if(!confirm(_0x4bf2d8(0x1db)+_0x316b91['length']+_0x4bf2d8(0x1d3)+(_0x165969?'全局':'局部')+_0x4bf2d8(0x16d)+_0x122e8f+'】吗?'))return;log(_0x4bf2d8(0x96)+_0x316b91[_0x4bf2d8(0x1a7)]+'\x20个知识库从\x20'+_0x1df23b+'\x20移动到\x20'+(_0x165969?_0x4bf2d8(0x1eb):_0x4bf2d8(0x118))+_0x4bf2d8(0x1a9),_0x4bf2d8(0x1a4));const _0x2e9695=_0x316b91[_0x4bf2d8(0x1d8)](_0x59e46d=>_0x222c37['moveKnowledgeBase'](_0x59e46d,_0x1df23b));try{await Promise[_0x4bf2d8(0x160)](_0x2e9695),toastr[_0x4bf2d8(0x249)]('所有\x20'+_0x316b91[_0x4bf2d8(0x1a7)]+'\x20个知识库均已成功移动。',_0x4bf2d8(0x130)),log(_0x4bf2d8(0xb5),_0x4bf2d8(0x249));}catch(_0x1b8978){toastr[_0x4bf2d8(0xf4)]('批量移动过程中发生错误:\x20'+_0x1b8978[_0x4bf2d8(0x13f)],'警报'),log(_0x4bf2d8(0x220)+_0x1b8978[_0x4bf2d8(0x13f)],_0x4bf2d8(0xf4));}finally{await updatePanelStatus();}}async function deleteAllLocalKnowledgeBases(){const _0x34a7c4=_0x2eed1f,_0x348c07=_0x222c37[_0x34a7c4(0x67)](),_0x105924=Object[_0x34a7c4(0x119)](_0x348c07);if(_0x105924['length']===0x0){toastr[_0x34a7c4(0x1a4)]('当前角色没有任何局部知识库可供删除。','圣谕');return;}if(!confirm(_0x34a7c4(0x22d)+_0x105924[_0x34a7c4(0x1a7)]+_0x34a7c4(0x25a)))return;toastr[_0x34a7c4(0x1a4)](_0x34a7c4(0x123)+_0x105924[_0x34a7c4(0x1a7)]+_0x34a7c4(0x22a),'圣旨'),log(_0x34a7c4(0x19f)+_0x105924[_0x34a7c4(0x1a7)]+_0x34a7c4(0x22a),'warn');let _0x7eb903=0x0,_0x4fdef2=0x0;for(const _0x1d8c0f of _0x105924){try{await _0x222c37['removeKnowledgeBase'](_0x1d8c0f,_0x34a7c4(0x1eb)),_0x7eb903++;}catch(_0xe81d50){_0x4fdef2++,log('删除局部知识库\x20'+_0x1d8c0f+'\x20失败:\x20'+_0xe81d50[_0x34a7c4(0x13f)],_0x34a7c4(0xf4));}}_0x4fdef2>0x0?toastr[_0x34a7c4(0xf4)](_0x34a7c4(0x15d)+_0x4fdef2+_0x34a7c4(0x1b1),'警报'):toastr['success'](_0x34a7c4(0x182)+_0x7eb903+'\x20个局部知识库均已成功删除。',_0x34a7c4(0x130)),log(_0x34a7c4(0x24f)+_0x7eb903+_0x34a7c4(0x8f)+_0x4fdef2,_0x34a7c4(0x1a4)),await updatePanelStatus();}async function renderKnowledgeBases(){const _0x182e3a=_0x2eed1f,_0x4c8fc1=document[_0x182e3a(0x242)](_0x182e3a(0x12c)),_0x41f18e=document[_0x182e3a(0x242)]('hly-kb-list-global'),_0x30da28=document[_0x182e3a(0x242)](_0x182e3a(0x19b));if(!_0x4c8fc1||!_0x41f18e||!_0x30da28)return;_0x30da28['textContent']=_0x27cc29[_0x182e3a(0x107)]()||_0x182e3a(0x151);try{const _0x477031=_0x222c37['getLocalKnowledgeBases'](),_0x26fb83=_0x222c37['getGlobalKnowledgeBases']();await _renderKbList(_0x477031,_0x4c8fc1,'local','hly-kb-list-local-placeholder'),await _renderKbList(_0x26fb83,_0x41f18e,'global',_0x182e3a(0xb7));}catch(_0x725202){console[_0x182e3a(0xf4)](_0x182e3a(0x108),_0x725202),_0x4c8fc1[_0x182e3a(0x1d7)]=_0x182e3a(0x258)+_0x725202[_0x182e3a(0x13f)]+_0x182e3a(0x125),_0x41f18e[_0x182e3a(0x1d7)]='加载失败:\x20'+_0x725202[_0x182e3a(0x13f)]+_0x182e3a(0x125);}}async function _renderKbList(_0x4e03a9,_0x455848,_0xa770f2,_0x330db6){const _0x28cc2b=_0x2eed1f,_0x289a67=document[_0x28cc2b(0x242)](_0x330db6);_0x455848[_0x28cc2b(0x1d7)]='',_0x455848[_0x28cc2b(0x200)](_0x289a67);if(Object['keys'](_0x4e03a9)[_0x28cc2b(0x1a7)]===0x0){_0x289a67[_0x28cc2b(0x191)][_0x28cc2b(0x1e1)]=_0x28cc2b(0x1a1);return;}_0x289a67['style'][_0x28cc2b(0x1e1)]='none';for(const [_0x6fb85d,_0x19a1d7]of Object[_0x28cc2b(0xbd)](_0x4e03a9)){const _0x19bb62=document[_0x28cc2b(0x80)](_0x28cc2b(0xdf));_0x19bb62[_0x28cc2b(0x229)]='hly-kb-list-item',_0x19bb62[_0x28cc2b(0x13c)][_0x28cc2b(0x1b5)]=_0x6fb85d,_0x19bb62[_0x28cc2b(0x13c)][_0x28cc2b(0x1b6)]=_0xa770f2;const _0x229f47=await _0x222c37[_0x28cc2b(0xb8)](_0x6fb85d,_0xa770f2),_0x3f9f04=_0xa770f2===_0x28cc2b(0x1eb)?_0x28cc2b(0x1c1):_0x28cc2b(0xf0);_0x19bb62[_0x28cc2b(0x1d7)]=_0x28cc2b(0x17f)+_0x6fb85d+_0x28cc2b(0x1e9)+_0x6fb85d+'\x22>'+_0x19a1d7[_0x28cc2b(0x113)]+'\x20('+_0x229f47+_0x28cc2b(0x131)+_0x3f9f04+_0x28cc2b(0x69)+(_0x19a1d7['enabled']?_0x28cc2b(0x13e):'')+'>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20×\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
\x0a\x20\x20\x20\x20\x20\x20\x20\x20',_0x455848[_0x28cc2b(0x200)](_0x19bb62);}}async function handleKbAction(_0x25e2e9){const _0x41b462=_0x2eed1f,_0x16a086=_0x25e2e9[_0x41b462(0x18a)],_0x2e776d=_0x16a086[_0x41b462(0x10f)](_0x41b462(0xe4));if(!_0x2e776d)return;const _0x385851=_0x2e776d[_0x41b462(0x13c)][_0x41b462(0x1b5)],_0x181dc4=_0x2e776d['dataset']['kbScope'],_0x5d13a4=_0x2e776d['querySelector'](_0x41b462(0x202))['textContent'][_0x41b462(0x7a)]('\x20(')[0x0];if(_0x16a086[_0x41b462(0x22b)]['contains'](_0x41b462(0x253))){if(confirm('您确定要永久删除知识库【'+_0x5d13a4+_0x41b462(0x179)))try{await _0x222c37['removeKnowledgeBase'](_0x385851,_0x181dc4),log(_0x41b462(0x201)+_0x5d13a4+_0x41b462(0x262)+_0x385851+_0x41b462(0x234),_0x41b462(0x249)),toastr[_0x41b462(0x249)](_0x41b462(0xee)+_0x5d13a4+_0x41b462(0x19e)),await updatePanelStatus();}catch(_0x4f1b2d){log('删除知识库\x20'+_0x5d13a4+_0x41b462(0xe6)+_0x4f1b2d[_0x41b462(0x13f)],_0x41b462(0xf4)),toastr['error'](_0x41b462(0x252)+_0x4f1b2d[_0x41b462(0x13f)]);}}if(_0x16a086[_0x41b462(0x10f)](_0x41b462(0xc4))){const _0x1b15ac=_0x181dc4===_0x41b462(0x1eb)?'全局':'局部';if(confirm(_0x41b462(0x133)+_0x5d13a4+_0x41b462(0x16d)+_0x1b15ac+_0x41b462(0x197)))try{await _0x222c37['moveKnowledgeBase'](_0x385851,_0x181dc4),await updatePanelStatus();}catch(_0xe81869){log(_0x41b462(0xe9)+_0x5d13a4+_0x41b462(0xe6)+_0xe81869[_0x41b462(0x13f)],'error'),toastr[_0x41b462(0xf4)](_0x41b462(0x178)+_0xe81869[_0x41b462(0x13f)]);}}if(_0x16a086[_0x41b462(0x22b)][_0x41b462(0x26c)](_0x41b462(0x98))&&_0x25e2e9[_0x41b462(0x87)]===_0x41b462(0x1ee))try{await _0x222c37[_0x41b462(0xf3)](_0x385851,_0x181dc4),log(_0x41b462(0x201)+_0x5d13a4+_0x41b462(0x212),_0x41b462(0x249));}catch(_0x1f1695){log(_0x41b462(0x226)+_0x5d13a4+_0x41b462(0xc3)+_0x1f1695[_0x41b462(0x13f)],_0x41b462(0xf4)),toastr['error'](_0x41b462(0xbb)+_0x1f1695[_0x41b462(0x13f)]),_0x16a086[_0x41b462(0x13e)]=!_0x16a086[_0x41b462(0x13e)];}_0x16a086[_0x41b462(0x22b)]['contains'](_0x41b462(0xa3))&&_0x25e2e9[_0x41b462(0x87)]===_0x41b462(0x1ee)&&updateBulkActionUI(_0x181dc4);}function handleSelectAll(_0x1fe508,_0x4d1c0c){const _0x2ff17f=_0x2eed1f,_0x296d34=_0x1fe508[_0x2ff17f(0x18a)][_0x2ff17f(0x13e)],_0x1a5fc5=document[_0x2ff17f(0x242)](_0x2ff17f(0x95)+_0x4d1c0c),_0x539cca=_0x1a5fc5['querySelectorAll'](_0x2ff17f(0x24a));_0x539cca[_0x2ff17f(0x1d2)](_0x4eefdc=>_0x4eefdc[_0x2ff17f(0x13e)]=_0x296d34),updateBulkActionUI(_0x4d1c0c);}function _0x21f4(){const _0x4bd65b=['会话已解锁,将跟随当前角色。','\x22>\x20[',',\x20失败:\x20','condensation.exclusionRules','\x20条忆识。','93DFBTzE','您确定要永久删除选中的\x20','未找到符合条件的消息。','hly-kb-list-','开始将\x20','任务完成!成功录入\x20','hly-kb-toggle','retrieval','hly-historiography-results','成功获取\x20',',\x20向量:\x20','正在处理您提交的文书...',',重新开始。','\x20楼到第\x20','{{manual_text}}','finalText','messageTypes','hly-kb-item-checkbox','hanlinyuan-ingest-abort','.hly-nav-item','点击以锁定,让翰林院固定操作当前角色的宝库','圣旨已下',',从第\x20','{{chat_text}}','批量编纂任务已完成,但有部分错误。','[翰林院-枢纽]\x20预览过程发生错误:','.hly-preview-textarea','delete','send-date','processed','{{text}}','hly-retrieval-enabled','翰林院设定已存档封印。','[翰林院-枢纽]\x20加载书库列表失败:','锁定会话','批量移动完成。','finalMessages','hly-kb-list-global-placeholder','getVectorCount','is_user','此书库为空','切换状态失败:\x20','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a翰林院宝库状态\x0a--------------------\x0a集合ID:\x20','\x20个书库。','神力连接失败:\x20','.hly-kb-list-item','[断点续传]\x20用户选择继续任务\x20','\x20失败:\x20','add','input[name=\x22','移动知识库\x20','凝识失败:\x20','hly-tag-extraction-toggle','apiEndpoint','embeddingModel','知识库【','\x0a\x20\x20\x20\x20\x20\x20\x20\x20','string','根据标签提取或内容排除条件,未找到任何有效内容。','toggleKnowledgeBase','error','输入兼容OpenAI的embeddings端点','hly-retrieval-notify','\x22\x20placeholder=\x22结束字符,\x20如\x20-->\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20×\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20','已采集\x20','正在对\x20','amily2_open_rag_palace','hly-log-output','成功录入\x20','hly-rerank-url','收到手动录入请求,文本长度:\x20','开始对《','hly-hist-select-all-entries','hly-locked-status','无法获取总数:\x20','.hly-log-placeholder','saveHLYSettings','.hly-preview-item-v2','hanlinyuan-ingest-novel-controls','getCharacterName','[翰林院-枢纽]\x20渲染知识库列表失败:','hly-batch-size','hly-kb-bulk-actions-global','processedChunks','active','[翰林院-枢纽]\x20凝识过程发生错误:','hly-layer-end','closest','toLocaleTimeString','matchThreshold','startHLYCondensation','name','[翰林院-枢纽]\x20查询宝库状态失败:','加载失败','用户尝试录入空文本。','position','global','keys','getAvailableWorldbooks','radio','查询宝库状态失败:\x20','\x20个知识库\x20(范围:\x20','请先选择一个书库并至少选择一个要编纂的条目。','hly-max-results','未能获取到任何Rerank模型。','文书已成功录入宝库,新增\x20','title','正在删除\x20','hly-kb-delete-local-btn','

','\x27\x20已更新为:\x20','join','严重错误','hly-unified-injection-depth','点击以解锁,让翰林院跟随当前角色','hybrid_alpha','hly-kb-list-local','》的条目失败:','正在读取文件...','hly-tag-input','大功告成','条)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20','integer','您确定要将知识库【','resetHLYSettings','\x20个模型。','处理中:\x20','加载失败','insertAdjacentHTML','\x20为占位符。','正在清空宝库...','abort','dataset','getChatId','checked','message','testApiConnection','录入失败:\x20','\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20','getGlobalKnowledgeBases','indeterminate','遵命,将从第\x20','hly-include-ai','placeholder','预览失败:\x20','hly-api-key','layerEnd','未找到匹配的条目','_searchHandler',')\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20未找到模型','flex','condensationHistory','\x20个知识库执行批量操作...','错误:\x20','\x20个知识块','target','会话已锁定','hly-api-endpoint','聊天记录从第\x20','解锁会话','rerank','成功删除了\x20','style','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20','','globalToLocal','hly-injection-source-selector','[翰林院-枢纽]\x20更新忆识数量失败:','文书录入失败:\x20','scrollTop','20rhwboa','initialize','.hly-preview-delete-btn-v2','overlap','正在查询宝库状态...','addEventListener','。进度已保存,可稍后重试。','hly-manual-text','loadProgress','宝库已清空。','forEach','\x20个知识库从【','data','hly-overlap-size','\x20楼到\x20','innerHTML','map','检测到预览后待处理的消息对象,开始精确凝识...','mes','您确定要将\x20','querySelector','51260keGLnO','allWorldbooks','label','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20未找到匹配的书库','preview-item-','hly-delete-rule-btn','\x20个知识库移动到【','apiKey','parse','getSettings','正在测试神力连接...','#hly-rules-list','checkbox','fetchEmbeddingModels','正在获取可用书库列表...','hly-kb-move-all-to-local','appendChild','知识库\x20','.hly-kb-name','preventDefault','hly-kb-bulk-actions-local','warn','加载书库列表失败:\x20','start','\x20条消息,开始凝识...','enabled','圣谕不明','\x20个知识库的状态。','purgeHLYStorage','手动录入失败:\x20','send_date','children','未找到符合条件的消息可供凝识。','allEntries','\x20的状态已切换','hly-worldbook-search','processCondensation','showHLYStats','遵命,将从头开始录入此书。','click','previousElementSibling','翰林院启奏','ingestHLYManualText','AbortError','》的批量编纂任务已完成。成功:\x20','\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20第\x20','.hly-hist-entry-checkbox:checked','boolean','批量移动失败:\x20','condensation','tagExtractionEnabled','hly-kb-select-all-global','localToGlobal','[自动保存]\x20设置项\x20\x27','切换知识库\x20','-tab','chat','className','\x20个局部知识库...','classList','hly-kb-list-global','您确定要永久删除【当前角色】的全部\x20','','totalChunks','\x20块开始。','.hly-hist-entry-checkbox','options','content',')\x20已被删除','hly-unified-template-notes','\x20个条目。','hly-include-user','','hly-tag-input-container','action','hly-hist-select-library','input[name=\x22hly-unified-injection-position\x22]','end','.hly-kb-item-checkbox:checked','圣旨已达','customApiUrl','获取模型失败:\x20','getElementById','resetSettings','正在为《','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20全选/全不选\x0a\x20\x20\x20\x20\x20\x20\x20\x20','请至少选择一个知识库进行操作。','710916wDCmXY','manual','success','.hly-kb-item-checkbox','您确定要切换选中的\x20','remove','预览并编辑凝识内容','hly-rerank-enabled','局部知识库批量删除完成。成功:\x20','isSessionLocked','.position','删除失败:\x20','hly-kb-delete-btn','录入内容不能为空。','amily2_open_hanlin_tutorial','[翰林院-枢纽]\x20编纂过程发生严重错误:','\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20加载失败:\x20','准备对《','\x20个局部知识库吗?此操作无法恢复!','94630JLPCaS','正在准备凝识...','querySelectorAll','根据当前勾选条件,未找到符合的消息可供预览。','layerStart','files','确认并更新预览','\x20(ID:\x20','请选择一个书库...','hly-custom-api-url','updateHLYMemoryCount','fas\x20fa-lock-open','\x20个Rerank模型。','template','2PKrxSz','翰林院使用教程','》中的\x20','contains','2211930rMuWdG','批量\x20','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20在这里定义需要从提取内容中排除的文本片段。例如,排除HTML注释,可以设置开始字符为\x20``。

\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20','getLocalKnowledgeBases','fetchRerankModels','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20','split','user','任务已由用户中止。进度已保存,可随时继续。','hanlinyuan-ingest-progress-bar','3246901siVvDH','fas\x20fa-lock','createElement','hly-embedding-model','input','ingestTextToHanlinyuan','hly-session-lock-btn','.hly-exclusion-rule-row','is-user','type','hly-hist-entry-multiselect-btn','未选择文件','includes','\x20操作失败:\x20','fetchHLYRerankModels'];_0x21f4=function(){return _0x4bd65b;};return _0x21f4();}function updateBulkActionUI(_0x1436f0){const _0x3167e2=_0x2eed1f,_0x4f763c=document[_0x3167e2(0x242)]('hly-kb-list-'+_0x1436f0),_0x51faf4=document[_0x3167e2(0x242)](_0x3167e2(0x177)+_0x1436f0),_0x28bdef=document[_0x3167e2(0x242)](_0x3167e2(0x1a2)+_0x1436f0),_0x16568e=_0x4f763c[_0x3167e2(0x25d)]('.hly-kb-item-checkbox'),_0x1d4f26=_0x4f763c[_0x3167e2(0x25d)](_0x3167e2(0x23e)),_0x5475f4=_0x1d4f26[_0x3167e2(0x1a7)],_0x4dca1e=_0x16568e['length'];_0x5475f4>0x0?_0x51faf4[_0x3167e2(0x191)][_0x3167e2(0x1e1)]='flex':_0x51faf4[_0x3167e2(0x191)][_0x3167e2(0x1e1)]='none';if(_0x4dca1e===0x0)_0x28bdef[_0x3167e2(0x13e)]=![],_0x28bdef[_0x3167e2(0x144)]=![];else{if(_0x5475f4===_0x4dca1e)_0x28bdef[_0x3167e2(0x13e)]=!![],_0x28bdef[_0x3167e2(0x144)]=![];else _0x5475f4>0x0?(_0x28bdef[_0x3167e2(0x13e)]=![],_0x28bdef[_0x3167e2(0x144)]=!![]):(_0x28bdef['checked']=![],_0x28bdef[_0x3167e2(0x144)]=![]);}}async function handleBulkAction(_0x365282,_0x4e2f4d){const _0x448508=_0x2eed1f,_0x12bb22=_0x365282['target'][_0x448508(0x13c)][_0x448508(0x23a)];if(!_0x12bb22)return;const _0x153e7e=document[_0x448508(0x242)](_0x448508(0x95)+_0x4e2f4d),_0xc58f95=_0x153e7e['querySelectorAll']('.hly-kb-item-checkbox:checked'),_0x7f5c9f=Array['from'](_0xc58f95)[_0x448508(0x1d8)](_0x4d0b01=>_0x4d0b01[_0x448508(0x13c)][_0x448508(0x1b5)]);if(_0x7f5c9f[_0x448508(0x1a7)]===0x0){toastr[_0x448508(0x17d)](_0x448508(0x246),'圣谕');return;}let _0x14ed29='',_0x4f55c4,_0x11f873='';switch(_0x12bb22){case _0x448508(0xad):_0x14ed29=_0x448508(0x93)+_0x7f5c9f[_0x448508(0x1a7)]+_0x448508(0x6c),_0x4f55c4=_0x4560b3=>_0x222c37[_0x448508(0xc8)](_0x4560b3,_0x4e2f4d),_0x11f873=_0x448508(0x190)+_0x7f5c9f[_0x448508(0x1a7)]+_0x448508(0xc9);break;case'move':const _0x5733e3=_0x4e2f4d===_0x448508(0x1eb)?'全局':'局部';_0x14ed29=_0x448508(0xd4)+_0x7f5c9f[_0x448508(0x1a7)]+_0x448508(0x1f6)+_0x5733e3+_0x448508(0x197),_0x4f55c4=_0x2b4301=>_0x222c37['moveKnowledgeBase'](_0x2b4301,_0x4e2f4d),_0x11f873=_0x448508(0x1ae)+_0x7f5c9f[_0x448508(0x1a7)]+_0x448508(0xc9);break;case _0x448508(0x1a6):_0x14ed29=_0x448508(0x24b)+_0x7f5c9f[_0x448508(0x1a7)]+'\x20个知识库的启用状态吗?',_0x4f55c4=_0x3bff37=>_0x222c37[_0x448508(0xf3)](_0x3bff37,_0x4e2f4d),_0x11f873='成功切换了\x20'+_0x7f5c9f[_0x448508(0x1a7)]+_0x448508(0x20b);break;default:return;}if(!confirm(_0x14ed29))return;toastr[_0x448508(0x1a4)](_0x448508(0xf9)+_0x7f5c9f[_0x448508(0x1a7)]+_0x448508(0x187),'圣旨'),log(_0x448508(0x1b8)+_0x7f5c9f[_0x448508(0x1a7)]+_0x448508(0x11d)+_0x4e2f4d+_0x448508(0xcc)+_0x12bb22+'\x20操作...',_0x448508(0x1a4));try{const _0x1c3098=_0x7f5c9f[_0x448508(0x1d8)](_0xfc1433=>_0x4f55c4(_0xfc1433));await Promise[_0x448508(0x160)](_0x1c3098),toastr[_0x448508(0x249)](_0x11f873,'大功告成'),log(_0x448508(0x26e)+_0x12bb22+'\x20操作成功。','success');}catch(_0x1999df){toastr[_0x448508(0xf4)](_0x448508(0xdd)+_0x1999df[_0x448508(0x13f)],'警报'),log(_0x448508(0x26e)+_0x12bb22+_0x448508(0x8b)+_0x1999df[_0x448508(0x13f)],_0x448508(0xf4));}finally{await updatePanelStatus();}}async function testApi(){const _0xbe698d=_0x2eed1f;toastr[_0xbe698d(0x1a4)](_0xbe698d(0x1fa),'圣旨');try{await _0x222c37[_0xbe698d(0x140)](),toastr[_0xbe698d(0x249)]('神力连接通畅!','圣意');}catch(_0x5b1913){toastr[_0xbe698d(0xf4)](_0xbe698d(0xe3)+_0x5b1913['message'],'警报');}}async function fetchHLYEmbeddingModels(){const _0x2df936=_0x2eed1f,_0x4b03dd=document[_0x2df936(0x242)](_0x2df936(0x81)),_0x5ef352=_0x4b03dd[_0x2df936(0x15e)];_0x4b03dd[_0x2df936(0x1d7)]=_0x2df936(0x1c2),_0x4b03dd[_0x2df936(0xd5)]=!![];try{log(_0x2df936(0x14f),_0x2df936(0x1a4));const _0x9d94e7=await _0x222c37[_0x2df936(0x1fd)]();_0x4b03dd[_0x2df936(0x1d7)]='';if(_0x9d94e7[_0x2df936(0x1a7)]===0x0){_0x4b03dd['innerHTML']=_0x2df936(0x184),toastr[_0x2df936(0x205)](_0x2df936(0x174),'翰林院启奏'),log('未能获取到任何模型。',_0x2df936(0x205));return;}_0x9d94e7[_0x2df936(0x1d2)](_0x37cceb=>{const _0x1b3e58=_0x2df936,_0x2979f5=new Option(_0x37cceb,_0x37cceb);_0x4b03dd[_0x1b3e58(0xe7)](_0x2979f5);}),_0x9d94e7[_0x2df936(0x8a)](_0x5ef352)?_0x4b03dd[_0x2df936(0x15e)]=_0x5ef352:_0x4b03dd['selectedIndex']=0x0,toastr[_0x2df936(0x249)](_0x2df936(0x9b)+_0x9d94e7[_0x2df936(0x1a7)]+_0x2df936(0x135),'圣意'),log(_0x2df936(0x9b)+_0x9d94e7[_0x2df936(0x1a7)]+_0x2df936(0x135),'success');}catch(_0x4d5db6){console[_0x2df936(0xf4)](_0x2df936(0xd1),_0x4d5db6),toastr[_0x2df936(0xf4)](_0x2df936(0x241)+_0x4d5db6[_0x2df936(0x13f)],'严重错误'),log(_0x2df936(0x241)+_0x4d5db6[_0x2df936(0x13f)],_0x2df936(0xf4)),_0x4b03dd[_0x2df936(0x1d7)]=_0x2df936(0x22e);}finally{_0x4b03dd[_0x2df936(0xd5)]=![];}}async function fetchHLYRerankModels(){const _0x5f25db=_0x2eed1f,_0xce3686=document[_0x5f25db(0x242)](_0x5f25db(0x17e)),_0x5a5c31=_0xce3686[_0x5f25db(0x15e)];_0xce3686[_0x5f25db(0x1d7)]=_0x5f25db(0x1c2),_0xce3686[_0x5f25db(0xd5)]=!![];try{log(_0x5f25db(0x168),_0x5f25db(0x1a4));const _0x26fbe7=await _0x222c37[_0x5f25db(0x68)]();_0xce3686[_0x5f25db(0x1d7)]='';if(_0x26fbe7[_0x5f25db(0x1a7)]===0x0){_0xce3686[_0x5f25db(0x1d7)]=_0x5f25db(0x184),toastr['warn'](_0x5f25db(0x120),_0x5f25db(0x219)),log(_0x5f25db(0x120),_0x5f25db(0x205));return;}_0x26fbe7['forEach'](_0x1afffd=>{const _0x3efd80=_0x5f25db,_0x5c9421=new Option(_0x1afffd,_0x1afffd);_0xce3686[_0x3efd80(0xe7)](_0x5c9421);}),_0x26fbe7['includes'](_0x5a5c31)?_0xce3686[_0x5f25db(0x15e)]=_0x5a5c31:_0xce3686[_0x5f25db(0x19c)]=0x0,toastr[_0x5f25db(0x249)](_0x5f25db(0x9b)+_0x26fbe7['length']+_0x5f25db(0x267),'圣意'),log('成功获取\x20'+_0x26fbe7['length']+_0x5f25db(0x267),_0x5f25db(0x249));}catch(_0x21817d){console[_0x5f25db(0xf4)](_0x5f25db(0xdc),_0x21817d),toastr[_0x5f25db(0xf4)](_0x5f25db(0x1bd)+_0x21817d['message'],_0x5f25db(0x128)),log('获取Rerank模型失败:\x20'+_0x21817d[_0x5f25db(0x13f)],'error'),_0xce3686[_0x5f25db(0x1d7)]=_0x5f25db(0x22e);}finally{_0xce3686['disabled']=![];}}async function purgeStorage(){const _0x4d5dbb=_0x2eed1f;if(confirm(_0x4d5dbb(0x1e3))){toastr['info'](_0x4d5dbb(0x13a),'圣旨');const _0x479d61=await _0x222c37[_0x4d5dbb(0x196)]();_0x479d61?toastr[_0x4d5dbb(0x249)](_0x4d5dbb(0x1d1),'圣意'):toastr[_0x4d5dbb(0xf4)](_0x4d5dbb(0x1a8),'警报'),await updatePanelStatus();}}async function startCondensation(){const _0x78f6f6=_0x2eed1f,_0x7f5150=document[_0x78f6f6(0x242)](_0x78f6f6(0x1b7)),_0x16aa89=_0x7f5150['dataset']['finalMessages'],_0x2493d9=document[_0x78f6f6(0x242)](_0x78f6f6(0x198))[_0x78f6f6(0x15e)],_0x5a4c9e=document[_0x78f6f6(0x242)](_0x78f6f6(0x10e))[_0x78f6f6(0x15e)],_0x4c7819={'start':parseInt(_0x2493d9),'end':parseInt(_0x5a4c9e)};try{let _0x407304;_0x16aa89?(log(_0x78f6f6(0x1d9),_0x78f6f6(0x1a4)),toastr[_0x78f6f6(0x1a4)]('正在处理您确认后的文书...','圣旨'),_0x407304=JSON[_0x78f6f6(0x1f8)](_0x16aa89),delete _0x7f5150[_0x78f6f6(0x13c)][_0x78f6f6(0xb6)]):(log('未检测到预览文本,按标准流程采集消息...',_0x78f6f6(0x1a4)),toastr[_0x78f6f6(0x1a4)](_0x78f6f6(0x25c),'圣旨'),_0x407304=_0x222c37['getMessagesForCondensation']());if(!_0x407304||_0x407304[_0x78f6f6(0x1a7)]===0x0){toastr['warning'](_0x78f6f6(0x210),'翰林院启奏'),_0x7f5150[_0x78f6f6(0x153)]=_0x78f6f6(0x94);return;}_0x7f5150[_0x78f6f6(0x153)]=_0x78f6f6(0xf8)+_0x407304[_0x78f6f6(0x1a7)]+_0x78f6f6(0x208),toastr[_0x78f6f6(0x1a4)](_0x78f6f6(0xf8)+_0x407304[_0x78f6f6(0x1a7)]+_0x78f6f6(0x208),_0x78f6f6(0x219));const _0x2c5614=await _0x222c37[_0x78f6f6(0x214)](_0x407304,log,_0x4c7819);if(_0x2c5614[_0x78f6f6(0x249)]){toastr['success'](_0x78f6f6(0x6a)+_0x2c5614[_0x78f6f6(0x165)]+'\x20条忆识。',_0x78f6f6(0x130));const _0x3a8224=_0x4c7819[_0x78f6f6(0x23d)]===0x0?getContext()['chat']['length']:_0x4c7819[_0x78f6f6(0x23d)];_0x7f5150[_0x78f6f6(0x153)]=_0x78f6f6(0x18d)+_0x4c7819['start']+_0x78f6f6(0x9f)+_0x3a8224+'\x20楼已成功凝识,新增\x20'+_0x2c5614[_0x78f6f6(0x165)]+'\x20条忆识。';}else throw new Error(_0x2c5614['error']||_0x78f6f6(0xc6));}catch(_0x401d6f){console[_0x78f6f6(0xf4)](_0x78f6f6(0x10d),_0x401d6f),toastr[_0x78f6f6(0xf4)](_0x78f6f6(0xea)+_0x401d6f[_0x78f6f6(0x13f)],'严重错误'),_0x7f5150[_0x78f6f6(0x153)]='凝识失败:\x20'+_0x401d6f[_0x78f6f6(0x13f)];}finally{await updatePanelStatus();}}async function loadWorldbookList(){const _0x4ddfab=_0x2eed1f,_0x3e818e=document[_0x4ddfab(0x242)]('hly-hist-select-library'),_0x341704=document[_0x4ddfab(0x242)](_0x4ddfab(0x213));if(!_0x3e818e)return;try{log(_0x4ddfab(0x1fe),_0x4ddfab(0x1a4));const _0x5ab26a=await _0x9d7bfc[_0x4ddfab(0x11a)]();window[_0x4ddfab(0x1de)]=_0x5ab26a,updateWorldbookOptions(_0x3e818e,'',_0x5ab26a);if(_0x341704){const _0xa075c6=debounce(_0x100bfc=>{updateWorldbookOptions(_0x3e818e,_0x100bfc,_0x5ab26a);},0x12c);_0x341704[_0x4ddfab(0x1cd)](_0x4ddfab(0x82),_0x4d8e13=>{const _0x577cdd=_0x4ddfab;_0xa075c6(_0x4d8e13[_0x577cdd(0x18a)]['value']);});}log(_0x4ddfab(0x15a)+_0x5ab26a['length']+_0x4ddfab(0xe2),'success');}catch(_0x14de0c){console[_0x4ddfab(0xf4)](_0x4ddfab(0xb3),_0x14de0c),log(_0x4ddfab(0x206)+_0x14de0c['message'],_0x4ddfab(0xf4)),_0x3e818e&&(_0x3e818e['innerHTML']=_0x4ddfab(0x115));}}function updateWorldbookOptions(_0x4ec42c,_0x595f76,_0x5b46c4){const _0x3730fd=_0x2eed1f,_0x243395=filterWorldbooks(_0x595f76,_0x5b46c4),_0x4db7f3=_0x4ec42c['value'];_0x4ec42c[_0x3730fd(0x1d7)]=_0x3730fd(0x263);if(_0x243395[_0x3730fd(0x1a7)]===0x0){_0x4ec42c['innerHTML']=_0x595f76[_0x3730fd(0x155)]()?_0x3730fd(0x1f3):'未找到任何书库';return;}_0x243395[_0x3730fd(0x1d2)](_0xe4f61c=>{const _0x36060b=_0x3730fd,_0x86818e=document[_0x36060b(0x80)](_0x36060b(0x180));_0x86818e[_0x36060b(0x15e)]=_0xe4f61c,_0x86818e[_0x36060b(0x153)]=_0xe4f61c,_0x4ec42c[_0x36060b(0x200)](_0x86818e);}),_0x4db7f3&&_0x243395[_0x3730fd(0x8a)](_0x4db7f3)&&(_0x4ec42c[_0x3730fd(0x15e)]=_0x4db7f3);}async function handleWorldbookSelectionChange(){const _0x175f79=_0x2eed1f,_0x402c5d=document['getElementById'](_0x175f79(0x23b)),_0x1700cc=document['getElementById'](_0x175f79(0x88)),_0x1063f4=document[_0x175f79(0x242)](_0x175f79(0x1ef)),_0x4c0f43=document[_0x175f79(0x242)](_0x175f79(0xd7)),_0x572184=_0x402c5d[_0x175f79(0x15e)];_0x1700cc[_0x175f79(0xd5)]=!![],_0x1700cc[_0x175f79(0x1dc)](_0x175f79(0x6d))[_0x175f79(0x153)]='正在加载条目...',_0x1063f4['innerHTML']='',_0x1063f4['style']['display']=_0x175f79(0xc7);_0x4c0f43&&(_0x4c0f43[_0x175f79(0x15e)]='');if(!_0x572184){_0x1700cc['querySelector'](_0x175f79(0x6d))[_0x175f79(0x153)]=_0x175f79(0x164);return;}try{log(_0x175f79(0x244)+_0x572184+'》获取条目列表...',_0x175f79(0x1a4));const _0x21495e=await _0x9d7bfc[_0x175f79(0xca)](_0x572184);if(_0x21495e[_0x175f79(0x1a7)]===0x0){_0x1700cc[_0x175f79(0x1dc)](_0x175f79(0x6d))['textContent']=_0x175f79(0xba);return;}window[_0x175f79(0x211)]=_0x21495e,updateEntryOptions('',_0x21495e);if(_0x4c0f43){_0x4c0f43[_0x175f79(0x162)]('input',_0x4c0f43['_searchHandler']);const _0xa292ee=debounce(_0x341066=>{updateEntryOptions(_0x341066,_0x21495e);},0x12c);_0x4c0f43[_0x175f79(0x14c)]=_0x56a5dc=>{const _0x18de74=_0x175f79;_0xa292ee(_0x56a5dc['target'][_0x18de74(0x15e)]);},_0x4c0f43[_0x175f79(0x1cd)](_0x175f79(0x82),_0x4c0f43[_0x175f79(0x14c)]);}log(_0x175f79(0x15a)+_0x21495e[_0x175f79(0x1a7)]+_0x175f79(0x236),_0x175f79(0x249));}catch(_0x573c37){console['error'](_0x175f79(0x16b)+_0x572184+_0x175f79(0x12d),_0x573c37),log(_0x175f79(0xd0)+_0x573c37[_0x175f79(0x13f)],'error'),_0x1700cc[_0x175f79(0x1dc)](_0x175f79(0x6d))['textContent']=_0x175f79(0x137);}finally{_0x1700cc[_0x175f79(0xd5)]=![];}}function updateEntryOptions(_0xfc2738,_0xa1f5a3){const _0x492392=_0x2eed1f,_0x24f846=document[_0x492392(0x242)](_0x492392(0x1ef)),_0x16c3c8=document[_0x492392(0x242)](_0x492392(0x88)),_0x64b7b5=filterWorldbookEntries(_0xfc2738,_0xa1f5a3);_0x24f846['innerHTML']='';const _0x1e06a3=_0x492392(0x245);_0x24f846['insertAdjacentHTML'](_0x492392(0x1e4),_0x1e06a3);if(_0x64b7b5[_0x492392(0x1a7)]===0x0){const _0x38243e=_0x492392(0x14b);_0x24f846[_0x492392(0x138)](_0x492392(0x1e4),_0x38243e),_0x16c3c8[_0x492392(0x1dc)]('span')[_0x492392(0x153)]='未找到匹配的条目';return;}_0x64b7b5[_0x492392(0x1d2)](_0x58892f=>{const _0x39f282=_0x492392,_0x1eee41=_0xfc2738?highlightSearchMatch(_0x58892f[_0x39f282(0xce)],_0xfc2738):_0x58892f[_0x39f282(0xce)],_0x27e4fd=_0x39f282(0x1e0)+_0x58892f[_0x39f282(0xce)]+'\x20(Key:\x20'+_0x58892f['key']+_0x39f282(0x14d)+_0x58892f['key']+'\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20'+_0x1eee41+'\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20';_0x24f846['insertAdjacentHTML'](_0x39f282(0x1e4),_0x27e4fd);}),_0x16c3c8[_0x492392(0x1dc)](_0x492392(0x6d))[_0x492392(0x153)]=_0x492392(0x156)+_0x64b7b5[_0x492392(0x1a7)]+_0x492392(0x15b);}async function startHistoriography(){const _0x3b0ecd=_0x2eed1f,_0x169685=document['getElementById'](_0x3b0ecd(0x23b))[_0x3b0ecd(0x15e)],_0x477509=document[_0x3b0ecd(0x242)](_0x3b0ecd(0x1ef)),_0x4c448d=document[_0x3b0ecd(0x242)](_0x3b0ecd(0x9a)),_0x22ce66=Array[_0x3b0ecd(0xc0)](_0x477509[_0x3b0ecd(0x25d)](_0x3b0ecd(0x21e)))[_0x3b0ecd(0x1d8)](_0x528e31=>_0x528e31[_0x3b0ecd(0x15e)]);if(!_0x169685||_0x22ce66['length']===0x0){toastr[_0x3b0ecd(0x17d)](_0x3b0ecd(0x11e),_0x3b0ecd(0x20a));return;}_0x4c448d[_0x3b0ecd(0x153)]=_0x3b0ecd(0x259)+_0x169685+_0x3b0ecd(0x26b)+_0x22ce66[_0x3b0ecd(0x1a7)]+'\x20个条目进行批量编纂...',toastr[_0x3b0ecd(0x1a4)](_0x3b0ecd(0x157),'圣旨'),log(_0x3b0ecd(0xff)+_0x169685+_0x3b0ecd(0x26b)+_0x22ce66[_0x3b0ecd(0x1a7)]+_0x3b0ecd(0x72),_0x3b0ecd(0x1a4));try{const _0x22261c=await _0x9d7bfc[_0x3b0ecd(0x1a3)](_0x169685,_0x22ce66);_0x4c448d[_0x3b0ecd(0x153)]=_0x22261c[_0x3b0ecd(0x233)],_0x22261c[_0x3b0ecd(0x249)]?toastr[_0x3b0ecd(0x249)](_0x3b0ecd(0x158),_0x3b0ecd(0x130)):toastr[_0x3b0ecd(0x17d)](_0x3b0ecd(0xaa),'圣谕'),log('对《'+_0x169685+_0x3b0ecd(0x21c)+_0x22261c[_0x3b0ecd(0x1f2)]+_0x3b0ecd(0x9c)+_0x22261c[_0x3b0ecd(0x1e8)],_0x3b0ecd(0x249));}catch(_0x4b1a9c){console[_0x3b0ecd(0xf4)](_0x3b0ecd(0x256),_0x4b1a9c),toastr[_0x3b0ecd(0xf4)](_0x3b0ecd(0xc5)+_0x4b1a9c[_0x3b0ecd(0x13f)],_0x3b0ecd(0x128)),_0x4c448d[_0x3b0ecd(0x153)]='编纂失败:\x20'+_0x4b1a9c[_0x3b0ecd(0x13f)];}finally{await updatePanelStatus();}}async function showStats(){const _0x337841=_0x2eed1f;try{log(_0x337841(0x77),_0x337841(0x1a4)),toastr[_0x337841(0x1a4)](_0x337841(0x1cc),'圣旨');const _0x116826=await _0x222c37[_0x337841(0xb8)](),_0x157490=await _0x222c37[_0x337841(0x154)](),_0x1eb939=_0x222c37[_0x337841(0x1f9)](),_0x328420=_0x337841(0xe1)+_0x157490+_0x337841(0x175)+_0x116826+'\x0a--------------------\x0aAPI端点:\x20'+_0x1eb939[_0x337841(0x99)][_0x337841(0xec)]+'\x0a所用模型:\x20'+_0x1eb939['retrieval']['embeddingModel']+_0x337841(0x142);toastr[_0x337841(0x1a4)](_0x328420,_0x337841(0x1b4),{'timeOut':0x3a98,'extendedTimeOut':0x1388,'tapToDismiss':!![],'closeButton':!![]}),log(_0x337841(0x166)+_0x157490+_0x337841(0x1e7)+_0x116826,_0x337841(0x249));}catch(_0x34738c){console['error'](_0x337841(0x114),_0x34738c),toastr[_0x337841(0xf4)](_0x337841(0x11c)+_0x34738c['message'],_0x337841(0x128)),log('查询宝库状态失败:\x20'+_0x34738c['message'],_0x337841(0xf4));}}function showExclusionRulesModal(){const _0x32ab6d=_0x2eed1f,_0x5e723f=_0x222c37[_0x32ab6d(0x1f9)](),_0x14b57c=_0x5e723f['condensation'][_0x32ab6d(0x1b2)]||[],_0x1c6bf7=(_0x1ddd98={'start':'','end':''},_0x296d64)=>_0x32ab6d(0xef)+_0x296d64+_0x32ab6d(0x257)+_0x1ddd98[_0x32ab6d(0x207)]+_0x32ab6d(0x171)+_0x1ddd98['end']+_0x32ab6d(0xf7),_0x44e1db=_0x14b57c['map'](_0x1c6bf7)[_0x32ab6d(0x127)](''),_0x1f94a1=_0x32ab6d(0x26f)+_0x44e1db+'\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
\x20添加新规则\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20';showHtmlModal(_0x32ab6d(0x172),_0x1f94a1,{'okText':'保存规则','onOk':_0xdb5aa9=>{const _0x493885=_0x32ab6d,_0x26ae04=[];_0xdb5aa9[_0x493885(0xcf)](_0x493885(0x85))[_0x493885(0xcb)](function(){const _0x3f33df=_0x493885,_0x29755d=$(this)[_0x3f33df(0xcf)](_0x3f33df(0x82))['eq'](0x0)[_0x3f33df(0xd3)]()[_0x3f33df(0x155)](),_0x37503d=$(this)[_0x3f33df(0xcf)](_0x3f33df(0x82))['eq'](0x1)[_0x3f33df(0xd3)]()[_0x3f33df(0x155)]();_0x29755d&&_0x37503d&&_0x26ae04[_0x3f33df(0x1af)]({'start':_0x29755d,'end':_0x37503d});}),updateAndSaveSetting(_0x493885(0x90),_0x26ae04),toastr[_0x493885(0x249)](_0x493885(0xd8),'圣旨已达');}});const _0x1e4bad=document[_0x32ab6d(0x242)]('hly-exclusion-rules-container'),_0x9890d4=_0x1e4bad[_0x32ab6d(0x1dc)](_0x32ab6d(0x1fb));_0x1e4bad[_0x32ab6d(0x1dc)]('#hly-add-rule-btn')[_0x32ab6d(0x1cd)](_0x32ab6d(0x217),()=>{const _0x5ca979=_0x32ab6d,_0x480e4c=_0x9890d4[_0x5ca979(0x20f)][_0x5ca979(0x1a7)],_0x52221b=_0x1c6bf7({'start':'','end':''},_0x480e4c);_0x9890d4['insertAdjacentHTML'](_0x5ca979(0x1e4),_0x52221b);}),_0x9890d4['addEventListener'](_0x32ab6d(0x217),_0x51a1b7=>{const _0x28f04f=_0x32ab6d;_0x51a1b7[_0x28f04f(0x18a)][_0x28f04f(0x22b)][_0x28f04f(0x26c)](_0x28f04f(0x1f5))&&_0x51a1b7['target'][_0x28f04f(0x10f)](_0x28f04f(0x85))['remove']();});}function previewCondensation(){const _0x207657=_0x2eed1f,_0x4d4764=document['getElementById']('hly-condensation-results');try{const _0x5b6603=_0x222c37[_0x207657(0x1f9)](),_0x1a9c66=_0x5b6603[_0x207657(0x221)][_0x207657(0x1b2)]||[],_0x25529f={'user':document[_0x207657(0x242)](_0x207657(0x237))[_0x207657(0x13e)],'ai':document['getElementById'](_0x207657(0x146))[_0x207657(0x13e)]},_0x4b335a=document[_0x207657(0x242)](_0x207657(0xeb))[_0x207657(0x13e)],_0x1cb4ab=_0x4b335a?document[_0x207657(0x242)](_0x207657(0x12f))[_0x207657(0x15e)][_0x207657(0x7a)](',')[_0x207657(0x1d8)](_0x47820b=>_0x47820b[_0x207657(0x155)]())[_0x207657(0x161)](Boolean):[],_0x5e613d=_0x222c37[_0x207657(0xd9)](_0x25529f);if(!_0x5e613d||_0x5e613d[_0x207657(0x1a7)]===0x0){_0x4d4764[_0x207657(0x153)]=_0x207657(0x25e),toastr[_0x207657(0x17d)](_0x207657(0x94),'翰林院启奏');return;}const _0x5dca39=getContext()[_0x207657(0x228)],_0x39f938=_0x5e613d[_0x207657(0x1d8)]((_0x16b342,_0x3da0c8)=>{const _0x27c412=_0x207657;let _0x41cf85;if(_0x16b342[_0x27c412(0xb9)])_0x41cf85=_0x16b342[_0x27c412(0x1da)];else{if(_0x4b335a&&_0x1cb4ab[_0x27c412(0x1a7)]>0x0){const _0x36797b=extractBlocksByTags(_0x16b342['mes'],_0x1cb4ab);_0x41cf85=_0x36797b['join']('\x0a\x0a');}else _0x41cf85=_0x16b342[_0x27c412(0x1da)];_0x41cf85=applyExclusionRules(_0x41cf85,_0x1a9c66);}const _0x5b7eb7=_0x5dca39[_0x27c412(0x6e)](_0x5e2b21=>_0x5e2b21===_0x16b342),_0x12b576=_0x5b7eb7!==-0x1?_0x5b7eb7+0x1:-0x1;return{'id':_0x27c412(0x1f4)+_0x3da0c8,'name':_0x16b342[_0x27c412(0x113)],'content':_0x41cf85[_0x27c412(0x155)](),'floor':_0x12b576,'is_user':_0x16b342[_0x27c412(0xb9)],'send_date':_0x16b342[_0x27c412(0x20e)]};})['filter'](_0x50b0d6=>_0x50b0d6[_0x207657(0x233)]);if(_0x39f938[_0x207657(0x1a7)]===0x0){_0x4d4764[_0x207657(0x153)]=_0x207657(0xf2),toastr['warning'](_0x207657(0xf2),_0x207657(0x219));return;}const _0x19a03f=_0x39f938['map']((_0x2bb6c3,_0x5291a7)=>_0x207657(0xbc)+_0x2bb6c3['id']+_0x207657(0x21d)+_0x2bb6c3[_0x207657(0x1bb)]+_0x207657(0x1ea)+_0x2bb6c3['name']+']\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20'+_0x2bb6c3[_0x207657(0x233)]+_0x207657(0x192)+_0x2bb6c3['id']+'\x22\x20title=\x22删除此条\x22>×\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20')['join']('');showHtmlModal(_0x207657(0x24d),_0x207657(0x79)+_0x19a03f+_0x207657(0x238),{'okText':_0x207657(0x261),'onOk':_0x2b44cf=>{const _0x5861eb=_0x207657,_0xc1bbf0=[];_0x2b44cf[_0x5861eb(0xcf)](_0x5861eb(0x105))[_0x5861eb(0xcb)](function(){const _0x10effb=_0x5861eb,_0x9328c8=$(this)[_0x10effb(0xcf)](_0x10effb(0xac)),_0x245ad5=_0x9328c8[_0x10effb(0xd3)]();_0x245ad5[_0x10effb(0x155)]()&&_0xc1bbf0[_0x10effb(0x1af)]({'mes':_0x245ad5,'is_user':_0x9328c8[_0x10effb(0x1d4)](_0x10effb(0x86)),'send_date':_0x9328c8[_0x10effb(0x1d4)](_0x10effb(0xae)),'floor':_0x9328c8[_0x10effb(0x1d4)](_0x10effb(0x1bb))});}),_0x4d4764[_0x5861eb(0x13c)]['finalMessages']=JSON['stringify'](_0xc1bbf0);const _0x426010=document[_0x5861eb(0x242)](_0x5861eb(0x198))[_0x5861eb(0x15e)],_0x26bea6=document['getElementById'](_0x5861eb(0x10e))['value'];_0x4d4764[_0x5861eb(0x153)]=_0x5861eb(0x1ec)+_0x426010+_0x5861eb(0x1d6)+_0x26bea6+'\x20楼的内容(共\x20'+_0xc1bbf0['length']+'\x20条有效条目),请点击“开始凝识”进入自动向量化流程。',toastr[_0x5861eb(0x249)]('预览内容已更新,可随时开始凝识。',_0x5861eb(0x23f));}}),$(_0x207657(0x1ca))['on'](_0x207657(0x217),function(_0x4c15f4){const _0x3e6675=_0x207657;_0x4c15f4[_0x3e6675(0x203)]();const _0x5984b8=$(this)[_0x3e6675(0x1d4)](_0x3e6675(0x18a));$('#'+_0x5984b8)['remove']();});}catch(_0x5f0086){console[_0x207657(0xf4)](_0x207657(0xab),_0x5f0086),_0x4d4764[_0x207657(0x153)]=_0x207657(0x148)+_0x5f0086[_0x207657(0x13f)],toastr['error'](_0x207657(0x148)+_0x5f0086[_0x207657(0x13f)],_0x207657(0x128));}}function _0x91bf(_0x4a7f01,_0x560610){const _0x21f4d0=_0x21f4();return _0x91bf=function(_0x91bfea,_0x3f1dca){_0x91bfea=_0x91bfea-0x67;let _0x4f33ea=_0x21f4d0[_0x91bfea];return _0x4f33ea;},_0x91bf(_0x4a7f01,_0x560610);}function log(_0x1da166,_0x1fed3c=_0x2eed1f(0x1a4)){const _0x6d1cee=_0x2eed1f,_0x246421=document[_0x6d1cee(0x242)](_0x6d1cee(0xfb));if(!_0x246421)return;const _0x2091f7=document[_0x6d1cee(0x80)]('p'),_0x298dc3=new Date()[_0x6d1cee(0x110)]();let _0x44484f='fa-circle-info',_0x26ff05='log-info';switch(_0x1fed3c){case _0x6d1cee(0x249):_0x44484f=_0x6d1cee(0x1ed),_0x26ff05=_0x6d1cee(0x1b9);break;case _0x6d1cee(0xf4):_0x44484f=_0x6d1cee(0x1ac),_0x26ff05='log-error';break;case _0x6d1cee(0x205):_0x44484f='fa-exclamation-triangle',_0x26ff05='log-warn';break;}_0x2091f7[_0x6d1cee(0x229)]=_0x6d1cee(0x16f)+_0x26ff05,_0x2091f7['innerHTML']='\x0a\x20\x20\x20\x20\x20\x20\x20\x20','tags','[翰林院-枢纽]\x20编纂过程发生严重错误:','\x20失败:\x20','翰林院启奏','localToGlobal','【手动存档】所有设定已存档封印。','圣旨已下','checkbox','您确定要永久删除【当前角色】的全部\x20','hly-unified-injection-depth','clearJob','>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20×\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20','已采集\x20','novel','rerank','getVectorCount','checked','[翰林院-枢纽]\x20加载书库列表失败:','3174224fiPGcE','fa-exclamation-triangle','400393eayTjI',')\x20已被删除','getChatId','processed','hly-kb-delete-btn','hly-rerank-model','\x20条消息,开始凝识...','会话已解锁,将跟随当前角色。','previousElementSibling','message','翰林院使用教程','未检测到预览文本,按标准流程采集消息...','hly-retrieval-enabled','val','\x20楼:\x20[','local_proxy','\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20第\x20','\x22\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20data-send-date=\x22','解锁会话','scrollTop','every','change','hly-layer-end','processCondensation','hlyLog','[翰林院-枢纽]\x20未能获取SillyTavern上下文,绑定失败。','。进度已保存,可稍后重试。','embeddingModel','\x20个条目进行编纂...','\x22\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20data-is-user=\x22','is_user','[data-setting-key]','delete','hly-api-key',')\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20添加新规则\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20','批量编纂任务已完成。','请输入您的Google\x20API\x20Key','toggleSessionLock','hly-hist-entry-multiselect-btn','find','startHLYHistoriography','当前角色','log-error','disabled','getGlobalKnowledgeBases','\x20条忆识。','\x22\x20placeholder=\x22开始字符,\x20如\x20\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20×\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20',_0x4963e1=_0x5ebf60['map'](_0x60a6d7)[_0x20f51a(0x2c3)](''),_0x32d4d4='\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20在这里定义需要从提取内容中排除的文本片段。例如,排除HTML注释,可以设置开始字符为\x20``。

\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20'+_0x4963e1+_0x20f51a(0x392);showHtmlModal('编辑内容排除规则',_0x32d4d4,{'okText':'保存规则','onOk':_0x44c19c=>{const _0xcf3c95=_0x20f51a,_0x6ee4f1=[];_0x44c19c[_0xcf3c95(0x397)](_0xcf3c95(0x2f2))['each'](function(){const _0x14c552=_0xcf3c95,_0x10f34d=$(this)[_0x14c552(0x397)](_0x14c552(0x23e))['eq'](0x0)['val']()[_0x14c552(0x322)](),_0x3154b9=$(this)[_0x14c552(0x397)](_0x14c552(0x23e))['eq'](0x1)[_0x14c552(0x378)]()[_0x14c552(0x322)]();_0x10f34d&&_0x3154b9&&_0x6ee4f1[_0x14c552(0x325)]({'start':_0x10f34d,'end':_0x3154b9});}),updateAndSaveSetting(_0xcf3c95(0x2c9),_0x6ee4f1),toastr[_0xcf3c95(0x1ea)](_0xcf3c95(0x2bf),_0xcf3c95(0x1dc));}});const _0x1bdae1=document[_0x20f51a(0x2c1)](_0x20f51a(0x327)),_0x4780c4=_0x1bdae1[_0x20f51a(0x1a8)](_0x20f51a(0x29b));_0x1bdae1[_0x20f51a(0x1a8)](_0x20f51a(0x270))['addEventListener'](_0x20f51a(0x273),()=>{const _0x5dc824=_0x20f51a,_0x41ff0e=_0x4780c4[_0x5dc824(0x2aa)][_0x5dc824(0x2b7)],_0x1712e0=_0x60a6d7({'start':'','end':''},_0x41ff0e);_0x4780c4['insertAdjacentHTML'](_0x5dc824(0x2a3),_0x1712e0);}),_0x4780c4['addEventListener']('click',_0x387845=>{const _0x4187bb=_0x20f51a;_0x387845['target'][_0x4187bb(0x2ce)][_0x4187bb(0x2cf)](_0x4187bb(0x2e5))&&_0x387845[_0x4187bb(0x350)]['closest']('.hly-exclusion-rule-row')[_0x4187bb(0x1cb)]();});}function previewCondensation(){const _0x81c39d=_0x13c5aa,_0x1d0fd1=document[_0x81c39d(0x2c1)]('hly-condensation-results');try{const _0x118734=_0x3ea5ae[_0x81c39d(0x292)](),_0x349fb4=_0x118734[_0x81c39d(0x23c)]['exclusionRules']||[],_0x535657={'user':document[_0x81c39d(0x2c1)](_0x81c39d(0x33b))[_0x81c39d(0x367)],'ai':document[_0x81c39d(0x2c1)](_0x81c39d(0x216))[_0x81c39d(0x367)]},_0x133ede=document[_0x81c39d(0x2c1)](_0x81c39d(0x22e))[_0x81c39d(0x367)],_0x22e611=_0x133ede?document['getElementById'](_0x81c39d(0x29a))['value']['split'](',')[_0x81c39d(0x288)](_0xafe4f7=>_0xafe4f7[_0x81c39d(0x322)]())[_0x81c39d(0x2d1)](Boolean):[],_0x5c94bd=_0x3ea5ae['getMessagesForCondensation'](_0x535657);if(!_0x5c94bd||_0x5c94bd[_0x81c39d(0x2b7)]===0x0){_0x1d0fd1['textContent']=_0x81c39d(0x268),toastr['warning'](_0x81c39d(0x390),_0x81c39d(0x35a));return;}const _0x5b7d3e=getContext()[_0x81c39d(0x1da)],_0x104de7=_0x5c94bd['map']((_0x25c477,_0x2dfcf0)=>{const _0xd5f7d0=_0x81c39d;let _0x466c19;if(_0x25c477['is_user'])_0x466c19=_0x25c477[_0xd5f7d0(0x30a)];else{if(_0x133ede&&_0x22e611[_0xd5f7d0(0x2b7)]>0x0){const _0x3fe09d=extractBlocksByTags(_0x25c477[_0xd5f7d0(0x30a)],_0x22e611);_0x466c19=_0x3fe09d[_0xd5f7d0(0x2c3)]('\x0a\x0a');}else _0x466c19=_0x25c477['mes'];_0x466c19=applyExclusionRules(_0x466c19,_0x349fb4);}const _0x157fd3=_0x5b7d3e[_0xd5f7d0(0x26f)](_0x5996d3=>_0x5996d3===_0x25c477),_0x54f592=_0x157fd3!==-0x1?_0x157fd3+0x1:-0x1;return{'id':_0xd5f7d0(0x2f0)+_0x2dfcf0,'name':_0x25c477[_0xd5f7d0(0x1c4)],'content':_0x466c19[_0xd5f7d0(0x322)](),'floor':_0x54f592,'is_user':_0x25c477['is_user'],'send_date':_0x25c477[_0xd5f7d0(0x30d)]};})[_0x81c39d(0x2d1)](_0x2a8117=>_0x2a8117['content']);if(_0x104de7['length']===0x0){_0x1d0fd1[_0x81c39d(0x267)]=_0x81c39d(0x1f6),toastr[_0x81c39d(0x223)]('根据标签提取或内容排除条件,未找到任何有效内容。','翰林院启奏');return;}const _0x1d6eaf=_0x104de7['map']((_0xf4dbe5,_0x573043)=>'\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20'+_0xf4dbe5['content']+'\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20×\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20')[_0x81c39d(0x2c3)]('');showHtmlModal(_0x81c39d(0x27a),_0x81c39d(0x235)+_0x1d6eaf+'',{'okText':_0x81c39d(0x252),'onOk':_0x476935=>{const _0x126247=_0x81c39d,_0x1d84ac=[];_0x476935['find']('.hly-preview-item-v2')['each'](function(){const _0x59c4bf=_0x46ab,_0x2f6950=$(this)[_0x59c4bf(0x397)]('.hly-preview-textarea'),_0x51f124=_0x2f6950[_0x59c4bf(0x378)]();_0x51f124[_0x59c4bf(0x322)]()&&_0x1d84ac[_0x59c4bf(0x325)]({'mes':_0x51f124,'is_user':_0x2f6950[_0x59c4bf(0x304)](_0x59c4bf(0x1a4)),'send_date':_0x2f6950[_0x59c4bf(0x304)](_0x59c4bf(0x1b6)),'floor':_0x2f6950['data'](_0x59c4bf(0x21c))});}),_0x1d0fd1[_0x126247(0x1f3)][_0x126247(0x1f7)]=JSON[_0x126247(0x28d)](_0x1d84ac);const _0x5965e9=document[_0x126247(0x2c1)](_0x126247(0x2c6))[_0x126247(0x31b)],_0x34e1b4=document[_0x126247(0x2c1)](_0x126247(0x381))[_0x126247(0x31b)];_0x1d0fd1[_0x126247(0x267)]=_0x126247(0x2eb)+_0x5965e9+_0x126247(0x226)+_0x34e1b4+'\x20楼的内容(共\x20'+_0x1d84ac[_0x126247(0x2b7)]+_0x126247(0x314),toastr['success'](_0x126247(0x347),'圣旨已达');}}),$(_0x81c39d(0x2fd))['on']('click',function(_0x1fdb73){const _0x39e4eb=_0x81c39d;_0x1fdb73[_0x39e4eb(0x20f)]();const _0x59f6b3=$(this)['data'](_0x39e4eb(0x350));$('#'+_0x59f6b3)[_0x39e4eb(0x1cb)]();});}catch(_0x1ac6f9){console['error'](_0x81c39d(0x23a),_0x1ac6f9),_0x1d0fd1['textContent']=_0x81c39d(0x1c8)+_0x1ac6f9['message'],toastr['error'](_0x81c39d(0x1c8)+_0x1ac6f9[_0x81c39d(0x374)],_0x81c39d(0x295));}}function _0x46ab(_0x1d1517,_0x14bd99){const _0x26e1e1=_0x26e1();return _0x46ab=function(_0x46ab60,_0x28dc1f){_0x46ab60=_0x46ab60-0x1a1;let _0x2c353d=_0x26e1e1[_0x46ab60];return _0x2c353d;},_0x46ab(_0x1d1517,_0x14bd99);}function log(_0xb1ce57,_0x5f470a='info'){const _0x17349b=_0x13c5aa,_0x76705c=document['getElementById']('hly-log-output');if(!_0x76705c)return;const _0xdfc310=document[_0x17349b(0x1ac)]('p'),_0x534a6c=new Date()[_0x17349b(0x2bd)]();let _0x238f63=_0x17349b(0x1d0),_0x371921=_0x17349b(0x26a);switch(_0x5f470a){case'success':_0x238f63='fa-check-circle',_0x371921=_0x17349b(0x205);break;case _0x17349b(0x275):_0x238f63=_0x17349b(0x251),_0x371921=_0x17349b(0x39a);break;case'warn':_0x238f63=_0x17349b(0x36a),_0x371921=_0x17349b(0x1a3);break;}_0xdfc310[_0x17349b(0x2c0)]=_0x17349b(0x28a)+_0x371921,_0xdfc310[_0x17349b(0x2dd)]=_0x17349b(0x213)+_0x238f63+'\x22>\x20['+_0x534a6c+']\x20'+_0xb1ce57;const _0x3a997a=_0x76705c[_0x17349b(0x1a8)](_0x17349b(0x1f2));_0x3a997a&&_0x3a997a[_0x17349b(0x1cb)](),_0x76705c[_0x17349b(0x2ab)](_0xdfc310),_0x76705c[_0x17349b(0x37e)]=_0x76705c[_0x17349b(0x1bd)];}async function ingestManualText(){const _0x199cc5=_0x13c5aa,_0x2b971a=document[_0x199cc5(0x2c1)](_0x199cc5(0x340)),_0x2a4c37=_0x2b971a[_0x199cc5(0x31b)][_0x199cc5(0x322)]();if(!_0x2a4c37){toastr[_0x199cc5(0x223)](_0x199cc5(0x27b),_0x199cc5(0x35a)),log(_0x199cc5(0x1d4),_0x199cc5(0x2da));return;}log(_0x199cc5(0x1b3)+_0x2a4c37[_0x199cc5(0x2b7)],_0x199cc5(0x239)),toastr[_0x199cc5(0x239)](_0x199cc5(0x1f8),'圣旨');try{const _0x531305=await _0x3ea5ae[_0x199cc5(0x227)](_0x2a4c37,_0x199cc5(0x1ba),{'sourceName':_0x199cc5(0x1db)});if(_0x531305[_0x199cc5(0x1ea)])toastr['success'](_0x199cc5(0x1ed)+_0x531305['count']+_0x199cc5(0x39d),_0x199cc5(0x32f)),log(_0x199cc5(0x22a)+_0x531305['count']+_0x199cc5(0x39d),_0x199cc5(0x1ea)),_0x2b971a[_0x199cc5(0x31b)]='';else throw new Error(_0x531305[_0x199cc5(0x275)]||_0x199cc5(0x21b));}catch(_0x344687){console[_0x199cc5(0x275)](_0x199cc5(0x2d2),_0x344687),toastr[_0x199cc5(0x275)](_0x199cc5(0x260)+_0x344687[_0x199cc5(0x374)],_0x199cc5(0x295)),log('手动录入失败:\x20'+_0x344687['message'],_0x199cc5(0x275));}finally{await updatePanelStatus();}} From 42c2bce746a455bf852e31ef5a60d23b73b80d11 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Fri, 10 Oct 2025 22:08:37 +0800 Subject: [PATCH 06/29] Update manifest.json --- manifest.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index c6dcaad..dc06c57 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "Amily2号聊天优化助手", "display_name": "Amily2号助手", - "version": "1.5.4", + "version": "1.5.5", "author": "Wx-2025", "description": "一个拥有独立UI的智能引擎,正文优化、自动总结、记忆表格、rag向量、隐藏楼层、剧情推进六大功能整合。", "minSillyTavernVersion": "1.10.0", @@ -27,3 +27,4 @@ + From 22a452296fb5199ef37ba31925fe43aecc2eb50e Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Fri, 10 Oct 2025 23:32:35 +0800 Subject: [PATCH 07/29] Update cwb_utils.js --- CharacterWorldBook/src/cwb_utils.js | 167 +++++++++++++++++++++++++++- 1 file changed, 166 insertions(+), 1 deletion(-) diff --git a/CharacterWorldBook/src/cwb_utils.js b/CharacterWorldBook/src/cwb_utils.js index 000f895..690796e 100644 --- a/CharacterWorldBook/src/cwb_utils.js +++ b/CharacterWorldBook/src/cwb_utils.js @@ -1 +1,166 @@ -const _0x38c295=_0x4996;(function(_0x2379d5,_0x3b247a){const _0x3ffd16=_0x4996,_0x1451c5=_0x2379d5();while(!![]){try{const _0x3e8606=parseInt(_0x3ffd16(0x141))/0x1*(parseInt(_0x3ffd16(0x131))/0x2)+-parseInt(_0x3ffd16(0x151))/0x3*(parseInt(_0x3ffd16(0x143))/0x4)+parseInt(_0x3ffd16(0x138))/0x5+parseInt(_0x3ffd16(0x142))/0x6+parseInt(_0x3ffd16(0x136))/0x7+parseInt(_0x3ffd16(0x146))/0x8*(parseInt(_0x3ffd16(0x133))/0x9)+parseInt(_0x3ffd16(0x158))/0xa*(-parseInt(_0x3ffd16(0x140))/0xb);if(_0x3e8606===_0x3b247a)break;else _0x1451c5['push'](_0x1451c5['shift']());}catch(_0x1b32fd){_0x1451c5['push'](_0x1451c5['shift']());}}}(_0x1549,0x22a34));function _0x4996(_0xd6cad5,_0x535f66){const _0x15498d=_0x1549();return _0x4996=function(_0x4996a1,_0x4d2986){_0x4996a1=_0x4996a1-0x12f;let _0x2a8a22=_0x15498d[_0x4996a1];return _0x2a8a22;},_0x4996(_0xd6cad5,_0x535f66);}const DEBUG_MODE=!![],SCRIPT_ID_PREFIX=_0x38c295(0x148);export function logDebug(..._0x195e75){const _0x78f1c2=_0x38c295;DEBUG_MODE&&console[_0x78f1c2(0x149)]('['+SCRIPT_ID_PREFIX+']',..._0x195e75);}export function logError(..._0xa9201a){console['error']('['+SCRIPT_ID_PREFIX+']',..._0xa9201a);}export function isCwbEnabled(){const _0x5d1fc6=_0x38c295;try{const _0x1adfe7=JSON[_0x5d1fc6(0x14f)](localStorage[_0x5d1fc6(0x159)](_0x5d1fc6(0x13d))||'{}');if(_0x1adfe7[_0x5d1fc6(0x155)]!==undefined)return _0x1adfe7[_0x5d1fc6(0x155)]===!![];const _0x58cc23=localStorage[_0x5d1fc6(0x159)](_0x5d1fc6(0x14b));if(_0x58cc23){const _0x4a7ebc=JSON[_0x5d1fc6(0x14f)](_0x58cc23);if(_0x4a7ebc?.[_0x5d1fc6(0x155)]!==undefined)return _0x4a7ebc[_0x5d1fc6(0x155)]===!![];}return!![];}catch(_0x4313de){return console[_0x5d1fc6(0x134)](_0x5d1fc6(0x13a),_0x4313de),!![];}}export function checkCwbEnabled(_0xf3ff4a='操作'){const _0x2b1478=_0x38c295;if(!isCwbEnabled())return console[_0x2b1478(0x149)]('['+SCRIPT_ID_PREFIX+']\x20'+_0xf3ff4a+'被跳过\x20-\x20CharacterWorldBook总开关已关闭'),![];return!![];}export function showToastr(_0x2ab4ee,_0x5849b6,_0x663368={}){const _0x39b1a9=_0x38c295;if(!isCwbEnabled())return;window[_0x39b1a9(0x14c)]?(window[_0x39b1a9(0x14c)]['clear'](),window['toastr'][_0x2ab4ee](_0x5849b6,_0x39b1a9(0x137),_0x663368)):logDebug(_0x39b1a9(0x15a)+_0x2ab4ee+'):\x20'+_0x5849b6);}function _0x1549(){const _0x556ba4=['cwb_boolean_settings_override','max','test','5724070tKaHcb','258DOyUvN','612336dNleve','232AtInHR','call','match','8xjPbsr','isArray','CWB','log','includes','extensions_settings_ST-Amily2-Chat-Optimisation','toastr','\x0a[--Amily2::CHAR_END--]','[--Amily2::CHAR_START--]\x0a','parse','hasOwnProperty','11226KEcRws','split','map','unknown_chat_source','cwb_master_enabled','object','filter','10AqRsCy','getItem','Toastr\x20(','forEach','prototype','1052yhndcO','trim','2438532yFrnEz','error',''','1103074vqsqoZ','角色世界书','1064940WbgcVO','length','[CWB]\x20Error\x20reading\x20master\x20switch\x20state:','replace','string'];_0x1549=function(){return _0x556ba4;};return _0x1549();}export function escapeHtml(_0x478b0e){const _0x1c1d17=_0x38c295;if(typeof _0x478b0e!==_0x1c1d17(0x13c))return'';return _0x478b0e[_0x1c1d17(0x13b)](/&/g,'&')['replace'](//g,'>')['replace'](/"/g,'\x22')['replace'](/'/g,_0x1c1d17(0x135));}export function cleanChatName(_0x52de28){const _0x1e52ab=_0x38c295;if(!_0x52de28||typeof _0x52de28!==_0x1e52ab(0x13c))return _0x1e52ab(0x154);let _0x4f5583=_0x52de28;if(_0x52de28[_0x1e52ab(0x14a)]('/')||_0x52de28[_0x1e52ab(0x14a)]('\x5c')){const _0x1201ba=_0x52de28['split'](/[\\/]/);_0x4f5583=_0x1201ba[_0x1201ba[_0x1e52ab(0x139)]-0x1];}return _0x4f5583[_0x1e52ab(0x13b)](/\.jsonl$/,'')[_0x1e52ab(0x13b)](/\.json$/,'');}export function compareVersions(_0x1076b2,_0x3e0dea){const _0x2d3335=_0x38c295,_0x4a0322=String(_0x1076b2)[_0x2d3335(0x152)]('.')[_0x2d3335(0x153)](Number),_0x3ca967=String(_0x3e0dea)[_0x2d3335(0x152)]('.')[_0x2d3335(0x153)](Number);for(let _0xa41569=0x0;_0xa41569_0x9e1f93)return 0x1;if(_0x44b8c0<_0x9e1f93)return-0x1;}return 0x0;}export function parseCustomFormat(_0x53ab0b){const _0x1c8852=_0x38c295,_0x265bf9={};if(typeof _0x53ab0b!==_0x1c8852(0x13c))return _0x265bf9;const _0x4e0c7b=_0x53ab0b[_0x1c8852(0x145)](/\[--Amily2::CHAR_START--\]([\s\S]*?)\[--Amily2::CHAR_END--\]/);if(!_0x4e0c7b||!_0x4e0c7b[0x1])return _0x265bf9;const _0x342192=_0x4e0c7b[0x1],_0x12eba0=(_0x26b008,_0x4580d9,_0x4e7136)=>{const _0xef770b=_0x1c8852,_0x3c3e76=_0x4580d9[_0xef770b(0x152)]('.');let _0x40a0db=_0x26b008;for(let _0x5c49fd=0x0;_0x5c49fd<_0x3c3e76['length']-0x1;_0x5c49fd++){const _0x2283bb=_0x3c3e76[_0x5c49fd],_0x400a83=_0x3c3e76[_0x5c49fd+0x1],_0x5ae114=/^\d+$/[_0xef770b(0x13f)](_0x400a83);!_0x40a0db[_0x2283bb]&&(_0x40a0db[_0x2283bb]=_0x5ae114?[]:{}),_0x40a0db=_0x40a0db[_0x2283bb];}const _0x35e568=_0x3c3e76[_0x3c3e76[_0xef770b(0x139)]-0x1];/^\d+$/[_0xef770b(0x13f)](_0x35e568)&&Array['isArray'](_0x40a0db)?_0x40a0db[parseInt(_0x35e568,0xa)]=_0x4e7136:_0x40a0db[_0x35e568]=_0x4e7136;},_0x5e994f=_0x342192[_0x1c8852(0x152)]('\x0a')[_0x1c8852(0x157)](_0x843880=>_0x843880[_0x1c8852(0x132)]()!=='');return _0x5e994f[_0x1c8852(0x12f)](_0x3c7e74=>{const _0x27a6b3=_0x1c8852,_0x544c6f=_0x3c7e74['match'](/^\[{1,2}(.*?)\]{1,2}:([\s\S]*)$/);if(_0x544c6f){const _0x2f5e8b=_0x544c6f[0x1],_0x45271e=_0x544c6f[0x2][_0x27a6b3(0x132)]();_0x12eba0(_0x265bf9,_0x2f5e8b,_0x45271e);}}),_0x265bf9;}function buildCustomFormatRecursive(_0x4b3004,_0x35c1fa=''){const _0x7d17d9=_0x38c295;let _0x108b43='';for(const _0x12bb5c in _0x4b3004){if(Object[_0x7d17d9(0x130)][_0x7d17d9(0x150)][_0x7d17d9(0x144)](_0x4b3004,_0x12bb5c)){const _0x255cd5=_0x35c1fa?_0x35c1fa+'.'+_0x12bb5c:_0x12bb5c,_0x115a84=_0x4b3004[_0x12bb5c];if(_0x115a84===null||_0x115a84===undefined)continue;if(typeof _0x115a84==='object'&&!Array[_0x7d17d9(0x147)](_0x115a84))_0x108b43+=buildCustomFormatRecursive(_0x115a84,_0x255cd5);else Array[_0x7d17d9(0x147)](_0x115a84)?_0x115a84[_0x7d17d9(0x139)]>0x0&&typeof _0x115a84[0x0]===_0x7d17d9(0x156)&&_0x115a84[0x0]!==null?_0x115a84['forEach']((_0x167804,_0x46eedf)=>{_0x108b43+=buildCustomFormatRecursive(_0x167804,_0x255cd5+'.'+_0x46eedf);}):_0x115a84[_0x7d17d9(0x12f)]((_0x425283,_0x6020b5)=>{_0x108b43+='['+_0x255cd5+'.'+_0x6020b5+']:'+_0x425283+'\x0a';}):_0x108b43+='['+_0x255cd5+']:'+_0x115a84+'\x0a';}}return _0x108b43;}export function buildCustomFormat(_0x40e36c){const _0x3af960=_0x38c295;let _0x44c89a=buildCustomFormatRecursive(_0x40e36c);return _0x44c89a=_0x44c89a[_0x3af960(0x152)]('\x0a')[_0x3af960(0x157)](_0x2fb3e9=>_0x2fb3e9[_0x3af960(0x145)](/^\[.*?]:.+/))['join']('\x0a'),_0x3af960(0x14e)+_0x44c89a['trim']()+_0x3af960(0x14d);} +const DEBUG_MODE = true; +const SCRIPT_ID_PREFIX = 'CWB'; + + +export function logDebug(...args) { + if (DEBUG_MODE) { + console.log(`[${SCRIPT_ID_PREFIX}]`, ...args); + } +} + +export function logError(...args) { + console.error(`[${SCRIPT_ID_PREFIX}]`, ...args); +} + +export function isCwbEnabled() { + try { + const overrides = JSON.parse(localStorage.getItem('cwb_boolean_settings_override') || '{}'); + if (overrides.cwb_master_enabled !== undefined) { + return overrides.cwb_master_enabled === true; + } + + const settingsString = localStorage.getItem('extensions_settings_ST-Amily2-Chat-Optimisation'); + if (settingsString) { + const settings = JSON.parse(settingsString); + if (settings?.cwb_master_enabled !== undefined) { + return settings.cwb_master_enabled === true; + } + } + + return true; + } catch (error) { + console.error('[CWB] Error reading master switch state:', error); + return true; + } +} + +export function checkCwbEnabled(operation = '操作') { + if (!isCwbEnabled()) { + console.log(`[${SCRIPT_ID_PREFIX}] ${operation}被跳过 - CharacterWorldBook总开关已关闭`); + return false; + } + return true; +} + +export function showToastr(type, message, options = {}) { + if (!isCwbEnabled()) { + return; + } + if (window.toastr) { + window.toastr.clear(); + window.toastr[type](message, `角色世界书`, options); + } else { + logDebug(`Toastr (${type}): ${message}`); + } +} + +export function escapeHtml(unsafe) { + if (typeof unsafe !== 'string') return ''; + return unsafe.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, '''); +} + +export function cleanChatName(fileName) { + if (!fileName || typeof fileName !== 'string') return 'unknown_chat_source'; + let cleanedName = fileName; + if (fileName.includes('/') || fileName.includes('\\')) { + const parts = fileName.split(/[\\/]/); + cleanedName = parts[parts.length - 1]; + } + return cleanedName.replace(/\.jsonl$/, '').replace(/\.json$/, ''); +} + +export function compareVersions(v1, v2) { + const parts1 = String(v1).split('.').map(Number); + const parts2 = String(v2).split('.').map(Number); + for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) { + const p1 = parts1[i] || 0; + const p2 = parts2[i] || 0; + if (p1 > p2) return 1; + if (p1 < p2) return -1; + } + return 0; +} + +export function parseCustomFormat(text) { + const data = {}; + if (typeof text !== 'string') return data; + + const coreDataMatch = text.match(/\[--Amily2::CHAR_START--\]([\s\S]*?)\[--Amily2::CHAR_END--\]/); + if (!coreDataMatch || !coreDataMatch[1]) { + return data; + } + const coreData = coreDataMatch[1]; + + const setNestedValue = (obj, path, value) => { + const keys = path.split('.'); + let current = obj; + for (let i = 0; i < keys.length - 1; i++) { + const key = keys[i]; + const nextKey = keys[i + 1]; + const isNextKeyNumeric = /^\d+$/.test(nextKey); + if (!current[key]) { + current[key] = isNextKeyNumeric ? [] : {}; + } + + if (typeof current[key] !== 'object' || current[key] === null) { + logError(`Path conflict in worldbook entry for path: ${path}. Expected object/array at key '${key}', but found ${typeof current[key]}.`); + return; + } + + current = current[key]; + } + const finalKey = keys[keys.length - 1]; + if (/^\d+$/.test(finalKey) && Array.isArray(current)) { + current[parseInt(finalKey, 10)] = value; + } else if (typeof current === 'object' && !Array.isArray(current)) { + current[finalKey] = value; + } + }; + + const lines = coreData.split('\n').filter(line => line.trim() !== ''); + lines.forEach(line => { + const match = line.match(/^\[{1,2}(.*?)\]{1,2}:([\s\S]*)$/); + if (match) { + const path = match[1]; + const value = match[2].trim(); + setNestedValue(data, path, value); + } + }); + + return data; +} + +function buildCustomFormatRecursive(obj, prefix = '') { + let result = ''; + for (const key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) { + const newPrefix = prefix ? `${prefix}.${key}` : key; + const value = obj[key]; + + if (value === null || value === undefined) continue; + + if (typeof value === 'object' && !Array.isArray(value)) { + result += buildCustomFormatRecursive(value, newPrefix); + } else if (Array.isArray(value)) { + if (value.length > 0 && typeof value[0] === 'object' && value[0] !== null) { + value.forEach((item, index) => { + result += buildCustomFormatRecursive(item, `${newPrefix}.${index}`); + }); + } else { + value.forEach((item, index) => { + result += `[${newPrefix}.${index}]:${item}\n`; + }); + } + } else { + result += `[${newPrefix}]:${value}\n`; + } + } + } + return result; +} + +export function buildCustomFormat(data) { + let content = buildCustomFormatRecursive(data); + content = content.split('\n').filter(line => line.match(/^\[.*?]:.+/)).join('\n'); + return `[--Amily2::CHAR_START--]\n${content.trim()}\n[--Amily2::CHAR_END--]`; +} From 4520cd86b512b5650ea5e402506e34887d65366f Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 12 Oct 2025 15:56:10 +0800 Subject: [PATCH 08/29] Update rag-processor.js --- core/rag-processor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/rag-processor.js b/core/rag-processor.js index 0d1db69..426b26d 100644 --- a/core/rag-processor.js +++ b/core/rag-processor.js @@ -1 +1 @@ -'use strict';const _0x1d2ea6=_0x292c;(function(_0xbc1e4f,_0x4d6bc8){const _0x280f6b=_0x292c,_0x152b1b=_0xbc1e4f();while(!![]){try{const _0x2ba4e6=parseInt(_0x280f6b(0x207))/0x1+-parseInt(_0x280f6b(0x29e))/0x2+-parseInt(_0x280f6b(0x2d0))/0x3+parseInt(_0x280f6b(0x1e5))/0x4*(parseInt(_0x280f6b(0x252))/0x5)+parseInt(_0x280f6b(0x1df))/0x6*(parseInt(_0x280f6b(0x274))/0x7)+parseInt(_0x280f6b(0x243))/0x8+-parseInt(_0x280f6b(0x242))/0x9*(parseInt(_0x280f6b(0x2cf))/0xa);if(_0x2ba4e6===_0x4d6bc8)break;else _0x152b1b['push'](_0x152b1b['shift']());}catch(_0x165e1a){_0x152b1b['push'](_0x152b1b['shift']());}}}(_0x255c,0x44e7d));function _0x255c(){const _0x117b49=['key','[翰林院-日志]\x20/api/vector/purge\x20响应状态:\x20','lorebook','未分类世界书','移动失败:没有当前角色,无法移入局部知识库。','manual','saveProgress','忆识检索失败:\x20','isArray','text','template','\x20及其向量数据。','[翰林院-日志]\x20清空目标集合ID:\x20','\x20池精确提取\x20','[翰林院-配置]\x20','在源作用域\x20\x27','/api/vector/query','[翰林院]\x20进入多路并行独立检索流程...','slice','end','message','results','[翰林院-迁移]\x20用户确认迁移,正在处理旧宝库:\x20','[翰林院-日志]\x20忆识存入API错误:','join','log','find','[翰林院-迁移]\x20集合\x20','vector','\x20-\x20楼层\x20#','length','AbortError','7zengPT','data','\x20个条目。','\x27的文本分割成\x20','[来源:\x20','global','insertVectors\x20必须接收一个有效的\x20collectionId\x20参数。','stringify','chapter','(已锁定:\x20','[翰林院-核心]\x20文本录入失败:\x20','status','第1章','对话记录大总结','metadata','[翰林院-户口普查]\x20知识库\x20\x22','),开始强制重分类所有知识库...','advanced','[翰林院]\x20检索或注入时发生错误:','map','substring','翰林院通告','error','local','小说录入','replace','[翰林院-核心]\x20尝试删除一个不存在的知识库:\x20','has','toString','[翰林院-核心]\x20已为宝库\x20','Rerank失败:\x20','bookName','\x0a$1','[翰林院]\x20最终无可用结果,注入中止。','[翰林院-迁移]\x20用户取消了迁移操作。','tiaomu','\x22\x20已删除。','[翰林院]\x20创建优先查询组:\x20','[翰林院-核心]\x20聊天记录凝识失败:\x20','\x27\x20中未找到ID为\x20','json','rerank','hasOwnProperty','extensionSettings','top_n','23245iiSaxI','sousuo'];_0x255c=function(){return _0x117b49;};return _0x255c();}import{extension_prompt_roles,setExtensionPrompt}from'/script.js';import*as _0x274781 from'./utils/context-utils.js';import{getCollectionIdInfo,getCharacterId,getCharacterStableId}from'./utils/context-utils.js';import{defaultSettings as _0x1e824f}from'./rag-settings.js';import*as _0x249d4f from'./ingestion-manager.js';import{getEmbeddings,fetchEmbeddingModels as _0xc3e478,fetchRerankModels as _0x303e64,executeRerank,testApiConnection as _0x528b44}from'./rag-api.js';import{superSort}from'./super-sorter.js';const MODULE_NAME=_0x1d2ea6(0x2d5),OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME='vectors_rearrangeChat',GLOBAL_SCOPE_ID=_0x1d2ea6(0x214);let context=null,settings=null,lockedCollectionId=null;function filterWorldbooks(_0x1d1706,_0x42b6b5){const _0x106c03=_0x1d2ea6;if(!_0x1d1706||!_0x1d1706[_0x106c03(0x2ca)]())return _0x42b6b5;const _0x32fea9=_0x1d1706[_0x106c03(0x2e3)]()['trim']();return _0x42b6b5['filter'](_0xf39df2=>{const _0x141186=_0x106c03;return _0xf39df2[_0x141186(0x2e3)]()[_0x141186(0x2a7)](_0x32fea9)||containsPinyinMatch(_0xf39df2,_0x32fea9);});}function filterWorldbookEntries(_0x32de80,_0x1a2817){const _0x46bf0f=_0x1d2ea6;if(!_0x32de80||!_0x32de80[_0x46bf0f(0x2ca)]())return _0x1a2817;const _0x4b8b62=_0x32de80['toLowerCase']()[_0x46bf0f(0x2ca)]();return _0x1a2817[_0x46bf0f(0x1e3)](_0x3e174e=>{const _0x37dbb4=_0x46bf0f,_0x15afad=[_0x3e174e[_0x37dbb4(0x2ad)]||'',_0x3e174e[_0x37dbb4(0x254)]||'',_0x3e174e[_0x37dbb4(0x2db)]||''][_0x37dbb4(0x26c)]('\x20')[_0x37dbb4(0x2e3)]();return _0x15afad[_0x37dbb4(0x2a7)](_0x4b8b62)||containsPinyinMatch(_0x3e174e[_0x37dbb4(0x2ad)]||'',_0x4b8b62);});}function containsPinyinMatch(_0x10600b,_0x137e2b){const _0x3e0b39=_0x1d2ea6,_0x3ade6b={'世界书':'sjshu','条目':_0x3e0b39(0x248),'编纂':'bianzhuan','搜索':_0x3e0b39(0x253)},_0x4dc3bd=_0x3ade6b[_0x10600b];return _0x4dc3bd&&_0x4dc3bd[_0x3e0b39(0x2a7)](_0x137e2b);}function highlightSearchMatch(_0x39e005,_0x14bf3c){const _0x25fafc=_0x1d2ea6;if(!_0x14bf3c||!_0x14bf3c['trim']())return _0x39e005;const _0x53b3c3=new RegExp('('+_0x14bf3c[_0x25fafc(0x28d)](/[.*+?^${}()|[\]\\]/g,'\x5c$&')+')','gi');return _0x39e005[_0x25fafc(0x28d)](_0x53b3c3,_0x25fafc(0x245));}function debounce(_0x464e5f,_0x58ebbf){let _0x54567c;return function _0x1f19dc(..._0x2e13a0){const _0x297501=()=>{clearTimeout(_0x54567c),_0x464e5f(..._0x2e13a0);};clearTimeout(_0x54567c),_0x54567c=setTimeout(_0x297501,_0x58ebbf);};}export{initialize,getSettings,saveSettings,resetSettings,_0x528b44 as testApiConnection,_0xc3e478 as fetchEmbeddingModels,_0x303e64 as fetchRerankModels,getVectorCount,purgeStorage,getMessagesForCondensation,processCondensation,ingestTextToHanlinyuan,getCollectionId,toggleSessionLock,isSessionLocked,getLockedSessionInfo,addKnowledgeBase,removeKnowledgeBase,getLocalKnowledgeBases,getGlobalKnowledgeBases,toggleKnowledgeBase,moveKnowledgeBase,filterWorldbooks,filterWorldbookEntries,highlightSearchMatch,debounce};function initialize(){const _0x594298=_0x1d2ea6;context=SillyTavern['getContext']();if(!context){console['error'](_0x594298(0x232));return;}settings=getSettings(),!window[_0x594298(0x2cc)]&&(window[_0x594298(0x2cc)]={}),window['hanlinyuanRagProcessor'][_0x594298(0x23a)]=rearrangeChat,window['hanlinyuanRagProcessor'][_0x594298(0x2d3)]=!![],console['log'](_0x594298(0x2b9));}async function ingestTextToHanlinyuan(_0x1f502f,_0x399b28='manual',_0x419d32={},_0x888350=()=>{},_0x48057f=null,_0x279698=()=>{},_0xf4d384=()=>{},_0x3ce809=null,_0x3619fc=0x0){const _0x4dace7=_0x1d2ea6;if(!_0x1f502f||!_0x1f502f['trim']())return{'success':![],'error':_0x4dace7(0x1d8)};if(!settings)return{'success':![],'error':_0x4dace7(0x1d9)};try{const _0x5ce1b3=getCollectionIdInfo(),_0x524ab9=await _0x2d61b9();if(_0x5ce1b3['oldId']&&_0x5ce1b3[_0x4dace7(0x2c4)]===_0x524ab9&&_0x5ce1b3['oldId']!==_0x5ce1b3[_0x4dace7(0x201)]){const _0x3302fb=confirm(_0x4dace7(0x1da));if(_0x3302fb)_0x279698(_0x4dace7(0x26a)+_0x5ce1b3[_0x4dace7(0x2c4)],_0x4dace7(0x1d5)),await purgeStorage(_0x5ce1b3['oldId']),_0x279698(_0x4dace7(0x2dc),_0x4dace7(0x218));else return _0x279698(_0x4dace7(0x247),_0x4dace7(0x213)),toastr[_0x4dace7(0x213)](_0x4dace7(0x29f)),{'success':![],'error':_0x4dace7(0x2ba)};}let _0x215b11,_0x3a34df;const _0x14c2cf=new Date()['toLocaleString'](_0x4dace7(0x227),{'hour12':![]}),_0x3a9161=getCharacterName()||_0x4dace7(0x1ee);switch(_0x399b28){case _0x4dace7(0x2ce):const _0x207241=_0x419d32['range']||{},_0x74be40=_0x207241['start']??'?',_0x37b3f4=_0x207241[_0x4dace7(0x267)]===0x0?'末':_0x207241[_0x4dace7(0x267)]??'?';_0x215b11=_0x3a9161+':\x20'+_0x74be40+'楼-'+_0x37b3f4+'楼';break;case _0x4dace7(0x256):const _0x865e9e=_0x419d32[_0x4dace7(0x293)]||_0x4dace7(0x257);if(_0x419d32[_0x4dace7(0x1e8)]&&_0x419d32[_0x4dace7(0x1e8)][_0x4dace7(0x2a7)]('微言录总结'))_0x419d32[_0x4dace7(0x1e8)]=_0x4dace7(0x2c8);else _0x419d32['entryName']&&_0x419d32[_0x4dace7(0x1e8)]['includes'](_0x4dace7(0x2a9))&&(_0x419d32[_0x4dace7(0x1e8)]=_0x4dace7(0x281));const _0x5a1545=_0x419d32[_0x4dace7(0x1e8)]||_0x4dace7(0x230);_0x215b11=_0x865e9e+':\x20'+_0x5a1545;break;case _0x4dace7(0x1d3):_0x215b11=_0x4dace7(0x236)+(_0x419d32[_0x4dace7(0x2c1)]||_0x4dace7(0x2b8));break;case _0x4dace7(0x259):default:_0x215b11=_0x4dace7(0x2df)+_0x14c2cf;break;}const _0x5e6eb6=Object[_0x4dace7(0x1f7)](getKnowledgeBases()),_0xca4c5d=_0x5e6eb6['find'](_0x4d2993=>_0x4d2993[_0x4dace7(0x2dd)]===_0x215b11);if(_0xca4c5d)_0x3a34df=_0xca4c5d['id'],_0x279698(_0x4dace7(0x224)+_0x215b11+'\x22,将数据合并入库。',_0x4dace7(0x213));else{_0x279698('[翰林院-核心]\x20准备为任务\x20\x22'+_0x215b11+_0x4dace7(0x297),_0x4dace7(0x213));const _0x9ffcbd=addKnowledgeBase(_0x215b11,_0x399b28);_0x3a34df=_0x9ffcbd['id'];}const _0xd6a3de=getCharacterStableId(),_0x2d15ee=_0xd6a3de+'_'+_0x3a34df;_0x279698(_0x4dace7(0x1f8)+_0x215b11+'\x20(集合ID:\x20'+_0x2d15ee+')',_0x4dace7(0x218)),_0x279698(_0x4dace7(0x1d0)+_0x2d15ee,_0x4dace7(0x213)),_0x888350({'message':_0x4dace7(0x1d2),'processed':0x0,'total':0x1});const _0x1d1326=splitIntoChunks(_0x1f502f,_0x399b28,_0x419d32),_0x4a03ba=_0x1d1326['length'];if(_0x48057f?.[_0x4dace7(0x1e9)])throw new Error(_0x4dace7(0x273));_0x279698(_0x4dace7(0x241)+_0x215b11+_0x4dace7(0x277)+_0x4a03ba+'\x20个块。','info');if(_0x4a03ba===0x0)return{'success':!![],'count':0x0};const _0x4892e1=settings['retrieval'][_0x4dace7(0x1f9)]||0x5;let _0x572369=_0x3619fc;for(let _0x3a9246=_0x3619fc;_0x3a9246<_0x4a03ba;_0x3a9246+=_0x4892e1){if(_0x48057f?.[_0x4dace7(0x1e9)])throw new Error('AbortError');const _0x28efdf=_0x1d1326[_0x4dace7(0x266)](_0x3a9246,_0x3a9246+_0x4892e1);_0x888350({'message':'正在处理\x20'+(_0x3a9246+0x1)+'-'+(_0x3a9246+_0x28efdf[_0x4dace7(0x272)])+'\x20块','processed':_0x3a9246,'total':_0x4a03ba});const _0x48b59f=_0x28efdf['map'](_0x4eb6db=>_0x4eb6db[_0x4dace7(0x25d)]),_0x48ff1d=await getEmbeddings(_0x48b59f,_0x48057f);if(_0x48057f?.['aborted'])throw new Error(_0x4dace7(0x273));if(_0x28efdf['length']!==_0x48ff1d[_0x4dace7(0x272)])throw new Error(_0x4dace7(0x1e2));const _0x26546f=_0x28efdf[_0x4dace7(0x287)]((_0x5c2fc0,_0x5eff83)=>({..._0x5c2fc0,'vector':_0x48ff1d[_0x5eff83]}));await insertVectors(_0x26546f,_0x48057f,_0x2d15ee),_0x572369+=_0x28efdf[_0x4dace7(0x272)],_0x3ce809&&_0x249d4f[_0x4dace7(0x25a)](_0x3ce809,_0x572369,_0x4a03ba),await _0xf4d384();}return _0x3ce809&&_0x249d4f['clearJob'](_0x3ce809),_0x279698('[翰林院-核心]\x20成功插入\x20'+_0x572369+'\x20个向量条目。',_0x4dace7(0x218)),{'success':!![],'count':_0x572369};}catch(_0x9f6acd){if(_0x9f6acd[_0x4dace7(0x2dd)]===_0x4dace7(0x273)){_0x279698('[翰林院-核心]\x20文本录入任务被用户中止。',_0x4dace7(0x1d5));throw _0x9f6acd;}return console[_0x4dace7(0x28a)]('[翰林院-核心]\x20ingestTextToHanlinyuan\x20失败:',_0x9f6acd),_0x279698(_0x4dace7(0x27e)+_0x9f6acd['message'],_0x4dace7(0x28a)),{'success':![],'error':_0x9f6acd[_0x4dace7(0x268)]};}}function getSettings(){const _0x2c78b0=_0x1d2ea6;if(!context||!context[_0x2c78b0(0x250)])return structuredClone(_0x1e824f);let _0x295228=context[_0x2c78b0(0x250)][MODULE_NAME];!_0x295228&&(_0x295228={},context[_0x2c78b0(0x250)][MODULE_NAME]=_0x295228);_0x295228[_0x2c78b0(0x2a4)]===undefined&&(_0x295228[_0x2c78b0(0x2a4)]={});_0x295228[_0x2c78b0(0x1f3)]===undefined&&(_0x295228[_0x2c78b0(0x1f3)]={});for(const _0x3f3b7b in _0x1e824f){if(_0x295228[_0x3f3b7b]===undefined)_0x295228[_0x3f3b7b]=structuredClone(_0x1e824f[_0x3f3b7b]);else{if(typeof _0x1e824f[_0x3f3b7b]===_0x2c78b0(0x212)&&!Array[_0x2c78b0(0x25c)](_0x1e824f[_0x3f3b7b])&&_0x1e824f[_0x3f3b7b]!==null)for(const _0x15c7b1 in _0x1e824f[_0x3f3b7b]){_0x295228[_0x3f3b7b][_0x15c7b1]===undefined&&(_0x295228[_0x3f3b7b][_0x15c7b1]=_0x1e824f[_0x3f3b7b][_0x15c7b1]);}}}return _0x295228;}function saveSettings(){const _0x22dc18=_0x1d2ea6;if(context)context[_0x22dc18(0x20c)]();}function resetSettings(){const _0x5dca40=_0x1d2ea6;context&&(context[_0x5dca40(0x250)][MODULE_NAME]=structuredClone(_0x1e824f),saveSettings());}function showNotification(_0x15c667,_0x2051d2=_0x1d2ea6(0x213)){toastr[_0x2051d2](_0x15c667);}function getTagForSource(_0x9cda1d){const _0x2ce6aa=_0x1d2ea6;switch(_0x9cda1d){case _0x2ce6aa(0x2ce):return _0x2ce6aa(0x1cb);case _0x2ce6aa(0x256):return'世界书';case _0x2ce6aa(0x259):return _0x2ce6aa(0x235);case _0x2ce6aa(0x1d3):return'小说录入';default:return'资料';}}function _0x292c(_0x4584ba,_0x107353){const _0x255cb2=_0x255c();return _0x292c=function(_0x292cd7,_0x3e519c){_0x292cd7=_0x292cd7-0x1ca;let _0x1c7d4c=_0x255cb2[_0x292cd7];return _0x1c7d4c;},_0x292c(_0x4584ba,_0x107353);}function splitIntoChunks(_0x427b59,_0x45965a,_0x33ef7e={}){const _0x3c4fa6=_0x1d2ea6;switch(_0x45965a){case _0x3c4fa6(0x1d3):return _chunkForNovel(_0x427b59,_0x33ef7e);case _0x3c4fa6(0x2ce):return _chunkForChatHistory(_0x427b59,_0x33ef7e);case _0x3c4fa6(0x256):return _chunkForLorebook(_0x427b59,_0x33ef7e);case'manual':return _chunkForManual(_0x427b59,_0x33ef7e);default:console[_0x3c4fa6(0x1d5)]('[翰林院-分块]\x20未知的来源类型\x20\x27'+_0x45965a+_0x3c4fa6(0x23b));return _chunkForManual(_0x427b59,{..._0x33ef7e,'sourceName':_0x33ef7e['sourceName']||_0x3c4fa6(0x2a3)});}}function _chunkForNovel(_0x336b46,_0x44efd3){const _0x56b8ba=_0x1d2ea6,{chunkSize:_0xa7e873,overlap:_0x21de6d}=settings['advanced'],{sourceName:sourceName='小说'}=_0x44efd3,_0x37e116=[];if(!_0x336b46||_0xa7e873<=0x0)return _0x37e116;const _0x1504ce=/(第\s*[一二三四五六七八九十百千万零\d]+\s*卷)/gim,_0x4e7897=/(第\s*[一二三四五六七八九十百千万零\d]+\s*[章回节部])|^(Chapter\s+\d+)/gim;let _0x30bbb5=0x0;const _0x2cc32e=_0x336b46[_0x56b8ba(0x205)]('\x0a');let _0x1fb716=_0x56b8ba(0x2b7),_0x4d71aa='第1章',_0x5bc12f=[];function _0x5421e7(){const _0x52dd14=_0x56b8ba;if(_0x5bc12f[_0x52dd14(0x272)]===0x0)return;const _0x449103=_0x5bc12f[_0x52dd14(0x26c)]('\x0a');let _0x360ca8=0x0,_0x281736=0x1;while(_0x360ca8<_0x449103[_0x52dd14(0x272)]){const _0x44f186=Math[_0x52dd14(0x21c)](_0x360ca8+_0xa7e873,_0x449103['length']),_0x2348a9=_0x449103[_0x52dd14(0x288)](_0x360ca8,_0x44f186);if(_0x2348a9[_0x52dd14(0x2ca)]()[_0x52dd14(0x272)]>0x0){const _0x4c702d={'source':_0x52dd14(0x1d3),'sourceName':sourceName,'timestamp':new Date()['toISOString'](),'globalIndex':_0x30bbb5++,'volume':_0x1fb716,'chapter':_0x4d71aa,'section':_0x281736},_0x3cdcab=getTagForSource('novel'),_0x4ab5e6=_0x52dd14(0x278)+sourceName+',\x20'+_0x1fb716+',\x20'+_0x4d71aa+',\x20第'+_0x281736+'节]',_0x916ffa='<'+_0x3cdcab+'>\x0a'+_0x4ab5e6+'\x0a'+_0x2348a9+_0x52dd14(0x294)+_0x3cdcab+'>';_0x37e116['push']({'text':_0x916ffa,'metadata':_0x4c702d}),_0x281736++;}_0x360ca8+=_0xa7e873-_0x21de6d;if(_0x360ca8>=_0x449103[_0x52dd14(0x272)])break;}_0x5bc12f=[];}for(const _0x10bead of _0x2cc32e){const _0x83b522=_0x10bead['trim']();if(_0x1504ce[_0x56b8ba(0x2bb)](_0x83b522))_0x5421e7(),_0x1fb716=_0x83b522,_0x4d71aa='第1章';else _0x4e7897[_0x56b8ba(0x2bb)](_0x83b522)?(_0x5421e7(),_0x4d71aa=_0x83b522):_0x5bc12f[_0x56b8ba(0x2a0)](_0x10bead);}_0x5421e7();if(_0x37e116[_0x56b8ba(0x272)]===0x0&&_0x336b46[_0x56b8ba(0x272)]>0x0){let _0x6b6989=0x0,_0x2be45c=0x1;while(_0x6b6989<_0x336b46['length']){const _0x4cc944=Math[_0x56b8ba(0x21c)](_0x6b6989+_0xa7e873,_0x336b46[_0x56b8ba(0x272)]),_0x5a84=_0x336b46[_0x56b8ba(0x288)](_0x6b6989,_0x4cc944),_0x18e123={'source':_0x56b8ba(0x1d3),'sourceName':sourceName,'timestamp':new Date()['toISOString'](),'globalIndex':_0x37e116['length'],'volume':_0x56b8ba(0x2b7),'chapter':_0x56b8ba(0x280),'section':_0x2be45c},_0x5a8662=getTagForSource(_0x56b8ba(0x1d3)),_0x59f77c='[来源:\x20'+sourceName+',\x20第1卷,\x20第1章,\x20第'+_0x2be45c+'节]',_0x255917='<'+_0x5a8662+'>\x0a'+_0x59f77c+'\x0a'+_0x5a84+_0x56b8ba(0x294)+_0x5a8662+'>';_0x37e116[_0x56b8ba(0x2a0)]({'text':_0x255917,'metadata':_0x18e123}),_0x2be45c++,_0x6b6989+=_0xa7e873-_0x21de6d;}}return _0x37e116;}function _chunkForChatHistory(_0x47f013,_0x478bb5){const _0x388564=_0x1d2ea6,{chunkSize:_0xfd2ee1,overlap:_0x1c5321}=settings['advanced'],{floor:_0x4af717,is_user:_0x2863c2,timestamp:_0x14ee10}=_0x478bb5,_0x4b21b0=[];if(!_0x47f013||_0xfd2ee1<=0x0)return _0x4b21b0;let _0x5d66d4=0x1,_0x2c7b2a=0x0;while(_0x2c7b2a<_0x47f013[_0x388564(0x272)]){const _0x4f3682=Math[_0x388564(0x21c)](_0x2c7b2a+_0xfd2ee1,_0x47f013[_0x388564(0x272)]),_0x5b98a0=_0x47f013[_0x388564(0x288)](_0x2c7b2a,_0x4f3682),_0x47ca9e='[来源:\x20聊天记录,\x20楼层:\x20#'+_0x4af717+_0x388564(0x228)+_0x5d66d4+_0x388564(0x296),_0x4de1f9=getTagForSource(_0x388564(0x2ce)),_0x3c3b4e='<'+_0x4de1f9+'>\x0a'+_0x47ca9e+'\x0a'+_0x5b98a0+'\x0a';_0x4b21b0[_0x388564(0x2a0)]({'text':_0x3c3b4e,'metadata':{'source':_0x388564(0x2ce),'sourceName':'聊天记录\x20#'+_0x4af717,'floor':_0x4af717,'part':_0x5d66d4,'is_user':_0x2863c2,'timestamp':_0x14ee10}}),_0x5d66d4++,_0x2c7b2a+=_0xfd2ee1-_0x1c5321;if(_0x2c7b2a>=_0x47f013[_0x388564(0x272)])break;}return _0x4b21b0;}function _chunkForLorebook(_0x2dc47e,_0x3c4926){const _0x4903e0=_0x1d2ea6,{chunkSize:_0x10e0bc,overlap:_0x3ba63c}=settings['advanced'],{bookName:bookName=_0x4903e0(0x23c),entryName:entryName='世界书条目'}=_0x3c4926,_0x3519fc=[];if(!_0x2dc47e||_0x10e0bc<=0x0)return _0x3519fc;let _0x2aac49=0x1,_0x15b95d=0x0;while(_0x15b95d<_0x2dc47e['length']){const _0x2435dc=Math[_0x4903e0(0x21c)](_0x15b95d+_0x10e0bc,_0x2dc47e[_0x4903e0(0x272)]),_0x381cdc=_0x2dc47e['substring'](_0x15b95d,_0x2435dc),_0x491afe=_0x4903e0(0x278)+bookName+_0x4903e0(0x2c3)+entryName+_0x4903e0(0x228)+_0x2aac49+_0x4903e0(0x296),_0x740191=getTagForSource(_0x4903e0(0x256)),_0x479623='<'+_0x740191+'>\x0a'+_0x491afe+'\x0a'+_0x381cdc+_0x4903e0(0x294)+_0x740191+'>';_0x3519fc['push']({'text':_0x479623,'metadata':{'source':'lorebook','sourceName':bookName+':\x20'+entryName,'bookName':bookName,'entryName':entryName,'part':_0x2aac49,'timestamp':new Date()[_0x4903e0(0x1db)]()}}),_0x2aac49++,_0x15b95d+=_0x10e0bc-_0x3ba63c;if(_0x15b95d>=_0x2dc47e[_0x4903e0(0x272)])break;}return _0x3519fc;}function _chunkForManual(_0x4e85b9,_0x4ccd32){const _0x47a778=_0x1d2ea6,{chunkSize:_0x4bbbd7,overlap:_0x6a4fa1}=settings[_0x47a778(0x285)],{sourceName:sourceName=_0x47a778(0x235)}=_0x4ccd32,_0x5a42ba=[];if(!_0x4e85b9||_0x4bbbd7<=0x0)return _0x5a42ba;const _0x4bb6fe=new Date(),_0x5ade21=_0x4bb6fe[_0x47a778(0x2a1)](_0x47a778(0x227));let _0x25b539=0x1,_0x1fd54d=0x0;while(_0x1fd54d<_0x4e85b9['length']){const _0x4a8786=Math['min'](_0x1fd54d+_0x4bbbd7,_0x4e85b9[_0x47a778(0x272)]),_0x4a596b=_0x4e85b9[_0x47a778(0x288)](_0x1fd54d,_0x4a8786),_0x247112=_0x47a778(0x278)+sourceName+_0x47a778(0x211)+_0x5ade21+_0x47a778(0x228)+_0x25b539+_0x47a778(0x296),_0x4f27a5=getTagForSource(_0x47a778(0x259)),_0x2012d3='<'+_0x4f27a5+'>\x0a'+_0x247112+'\x0a'+_0x4a596b+_0x47a778(0x294)+_0x4f27a5+'>';_0x5a42ba[_0x47a778(0x2a0)]({'text':_0x2012d3,'metadata':{'source':_0x47a778(0x259),'sourceName':sourceName,'part':_0x25b539,'timestamp':_0x4bb6fe['toISOString']()}}),_0x25b539++,_0x1fd54d+=_0x4bbbd7-_0x6a4fa1;if(_0x1fd54d>=_0x4e85b9[_0x47a778(0x272)])break;}return _0x5a42ba;}import{getCollectionId as _0x2d61b9,getCharacterName}from'./utils/context-utils.js';async function getCollectionId(){return lockedCollectionId||await _0x2d61b9();}async function toggleSessionLock(){return lockedCollectionId?(lockedCollectionId=null,![]):(lockedCollectionId=await _0x2d61b9(),!![]);}function isSessionLocked(){return lockedCollectionId!==null;}function getLockedSessionInfo(){const _0x32d6bd=_0x1d2ea6;if(!lockedCollectionId)return null;return{'id':lockedCollectionId,'name':_0x32d6bd(0x27d)+lockedCollectionId[_0x32d6bd(0x288)](0x0,0x8)+_0x32d6bd(0x1fa)};}function getLocalKnowledgeBases(){const _0x63eb6c=_0x1d2ea6,_0x202a99=getCharacterStableId();return!settings[_0x63eb6c(0x1f3)][_0x202a99]&&(settings[_0x63eb6c(0x1f3)][_0x202a99]={}),settings['knowledgeBases'][_0x202a99];}function getGlobalKnowledgeBases(){const _0x1ec62b=_0x1d2ea6;return!settings[_0x1ec62b(0x1f3)][GLOBAL_SCOPE_ID]&&(settings[_0x1ec62b(0x1f3)][GLOBAL_SCOPE_ID]={}),settings['knowledgeBases'][GLOBAL_SCOPE_ID];}function getKnowledgeBases(){const _0x1687e3=getLocalKnowledgeBases(),_0x1f6184=getGlobalKnowledgeBases();return{..._0x1f6184,..._0x1687e3};}function addKnowledgeBase(_0x2956dd,_0x125333='manual'){const _0x460b44=_0x1d2ea6;if(!_0x2956dd||!_0x2956dd[_0x460b44(0x2ca)]())throw new Error('知识库名称不能为空');const _0x2509dd=getCharacterStableId(),_0x29233d=getLocalKnowledgeBases(),_0x272144=_0x460b44(0x2e6)+Date[_0x460b44(0x1fc)]()+'_'+Math[_0x460b44(0x2ab)]()[_0x460b44(0x290)](0x24)['substring'](0x2,0x9),_0x19b731={'id':_0x272144,'name':_0x2956dd[_0x460b44(0x2ca)](),'enabled':!![],'createdAt':new Date()['toISOString'](),'owner':_0x2509dd,'source':_0x125333};return _0x29233d[_0x272144]=_0x19b731,saveSettings(),console[_0x460b44(0x26d)](_0x460b44(0x2b6)+_0x2509dd+_0x460b44(0x2c2)+_0x2956dd+'\x20(ID:\x20'+_0x272144+')'),_0x19b731;}async function removeKnowledgeBase(_0x11b78e,_0x2a77cb){const _0x564298=_0x1d2ea6,_0x523a79=getCharacterStableId(),_0x34de17=_0x2a77cb==='global'?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x4a192f=_0x34de17[_0x11b78e],_0x39d93b=_0x4a192f?.[_0x564298(0x2dd)]||_0x11b78e;if(!_0x4a192f){console[_0x564298(0x1d5)](_0x564298(0x28e)+_0x11b78e+_0x564298(0x2d6)+_0x2a77cb+')');return;}const _0x2dc988=_0x2a77cb===_0x564298(0x279)?_0x4a192f[_0x564298(0x2b4)]||GLOBAL_SCOPE_ID:_0x523a79,_0x4d2e36=_0x2dc988+'_'+_0x11b78e;console[_0x564298(0x26d)](_0x564298(0x217)+_0x11b78e+_0x564298(0x2e0)+_0x4d2e36);const _0xbf11f=await purgeStorage(_0x4d2e36);_0xbf11f?(delete _0x34de17[_0x11b78e],saveSettings(),console[_0x564298(0x26d)]('[翰林院-核心]\x20成功删除知识库\x20'+_0x11b78e+_0x564298(0x25f)),toastr[_0x564298(0x218)](_0x564298(0x240)+_0x39d93b+_0x564298(0x249))):(console[_0x564298(0x28a)]('[翰林院-核心]\x20清空向量集合\x20'+_0x4d2e36+'\x20失败,删除操作中止。'),toastr[_0x564298(0x28a)](_0x564298(0x225)));}function toggleKnowledgeBase(_0x5f5d12,_0x4d6734){const _0x25ec83=_0x1d2ea6,_0x48e158=_0x4d6734===_0x25ec83(0x279)?getGlobalKnowledgeBases():getLocalKnowledgeBases();_0x48e158[_0x5f5d12]&&(_0x48e158[_0x5f5d12]['enabled']=!_0x48e158[_0x5f5d12]['enabled'],saveSettings(),console[_0x25ec83(0x26d)](_0x25ec83(0x2e5)+_0x5f5d12+_0x25ec83(0x2d6)+_0x4d6734+_0x25ec83(0x219)+(_0x48e158[_0x5f5d12]['enabled']?'启用':'禁用')));}function generateHash(_0x20dcc3){const _0x13112a=_0x1d2ea6;let _0x242d78=0x0;for(let _0x5b3318=0x0;_0x5b3318<_0x20dcc3[_0x13112a(0x272)];_0x5b3318++){const _0x2ee60e=_0x20dcc3[_0x13112a(0x2cd)](_0x5b3318);_0x242d78=(_0x242d78<<0x5)-_0x242d78+_0x2ee60e,_0x242d78=_0x242d78&_0x242d78;}return Math[_0x13112a(0x1ea)](_0x242d78)[_0x13112a(0x290)](0x24);}async function queryVectors(_0x1a8c54,_0x396b03={}){const _0x3777ba=_0x1d2ea6,{includeBases:includeBases=null}=_0x396b03;console['log'](_0x3777ba(0x1e1)+(includeBases?'指定知识库':_0x3777ba(0x1f4))+')');const _0x523527=getCharacterStableId();let _0x1778bf;if(includeBases)_0x1778bf=includeBases,console[_0x3777ba(0x26d)](_0x3777ba(0x206)+_0x1778bf[_0x3777ba(0x272)]+_0x3777ba(0x1e4));else{const _0x2a9fbb=getLocalKnowledgeBases(),_0x16a505=getGlobalKnowledgeBases(),_0x52202a=Object['values'](_0x2a9fbb)[_0x3777ba(0x1e3)](_0x957a69=>_0x957a69['enabled']),_0x266d07=Object[_0x3777ba(0x1f7)](_0x16a505)[_0x3777ba(0x1e3)](_0xaa1caa=>_0xaa1caa[_0x3777ba(0x215)]);_0x1778bf=[..._0x52202a[_0x3777ba(0x287)](_0x2efa24=>({..._0x2efa24,'scope':'local'})),..._0x266d07[_0x3777ba(0x287)](_0x575a4d=>({..._0x575a4d,'scope':_0x3777ba(0x279)}))];}if(_0x1778bf[_0x3777ba(0x272)]===0x0&&!includeBases){console['log'](_0x3777ba(0x234));const _0x5385c2=await _0x2d61b9();if(!_0x5385c2)return[];_0x1778bf[_0x3777ba(0x2a0)]({'id':null,'name':'旧版宝库\x20(Legacy)','scope':_0x3777ba(0x23e)});}if(_0x1778bf[_0x3777ba(0x272)]===0x0)return console[_0x3777ba(0x26d)](_0x3777ba(0x1ce)),[];const _0x3d9ce9=(await getEmbeddings([_0x1a8c54]))[0x0];if(!_0x3d9ce9)throw new Error(_0x3777ba(0x1f1));let _0x42775f=[];const _0x41598e=_0x1778bf[_0x3777ba(0x287)](_0x5f315c=>{const _0x2d08e5=_0x3777ba;let _0x110adb;if(_0x5f315c[_0x2d08e5(0x21e)]===_0x2d08e5(0x23e))_0x110adb=_0x2d61b9();else{const _0x39e64f=_0x5f315c[_0x2d08e5(0x21e)]===_0x2d08e5(0x279)?_0x5f315c['owner']||GLOBAL_SCOPE_ID:_0x523527;_0x110adb=Promise['resolve'](_0x39e64f+'_'+_0x5f315c['id']);}return _0x110adb[_0x2d08e5(0x231)](_0x34a6fa=>{const _0x18dbed=_0x2d08e5;if(!_0x34a6fa)return[];console['log'](_0x18dbed(0x202)+_0x5f315c[_0x18dbed(0x2dd)]+_0x18dbed(0x2b0)+_0x34a6fa+')');const _0x143836={'collectionId':_0x34a6fa,'searchText':_0x1a8c54,'topK':settings['advanced']['maxResults'],'threshold':settings[_0x18dbed(0x285)]['matchThreshold'],'source':_0x18dbed(0x20d),'embeddings':{[_0x1a8c54]:_0x3d9ce9}};return fetch(_0x18dbed(0x264),{'method':'POST','headers':context['getRequestHeaders'](),'body':JSON[_0x18dbed(0x27b)](_0x143836)})[_0x18dbed(0x231)](async _0x52bb78=>{const _0x579880=_0x18dbed;if(!_0x52bb78['ok']){const _0xecc60=await _0x52bb78[_0x579880(0x25d)]();return console[_0x579880(0x28a)]('[翰林院-日志]\x20查询知识库\x20'+_0x34a6fa+'\x20失败:',_0xecc60),[];}const _0x4b2039=await _0x52bb78[_0x579880(0x24d)]();let _0x293383=[];if(Array[_0x579880(0x25c)](_0x4b2039))_0x293383=_0x4b2039;else{if(_0x4b2039&&_0x4b2039['metadata']&&Array[_0x579880(0x25c)](_0x4b2039[_0x579880(0x282)]))_0x293383=_0x4b2039[_0x579880(0x282)];else{if(_0x4b2039&&_0x4b2039[_0x579880(0x269)]&&Array[_0x579880(0x25c)](_0x4b2039['results']))_0x293383=_0x4b2039[_0x579880(0x269)];else _0x4b2039&&_0x4b2039['data']&&Array['isArray'](_0x4b2039[_0x579880(0x275)])&&(_0x293383=_0x4b2039['data']);}}const _0x10e337=_0x293383[_0x579880(0x287)](_0x1de2ba=>{const _0x228993=_0x579880;if(!_0x1de2ba||typeof _0x1de2ba['text']!==_0x228993(0x2de))return null;const _0x5ef717={'source':_0x228993(0x22b),'sourceName':'未知'},_0x2bb6ce=_0x1de2ba['text']['match'](/^<([^>]+)>/),_0x4a7c62=_0x2bb6ce?_0x2bb6ce[0x1]:'';switch(_0x4a7c62){case _0x228993(0x1cb):_0x5ef717[_0x228993(0x22a)]='chat_history';const _0xb1e583=_0x1de2ba[_0x228993(0x25d)][_0x228993(0x1f6)](/楼层:\s*#(\d+),\s*第(\d+)部分/);_0xb1e583&&_0xb1e583[0x1]&&_0xb1e583[0x2]&&(_0x5ef717[_0x228993(0x2b2)]=parseInt(_0xb1e583[0x1],0xa),_0x5ef717[_0x228993(0x220)]=parseInt(_0xb1e583[0x2],0xa),_0x5ef717[_0x228993(0x2c1)]=_0x228993(0x1ef)+_0x5ef717['floor']);break;case _0x228993(0x23c):_0x5ef717['source']=_0x228993(0x256);const _0x44c9f9=_0x1de2ba[_0x228993(0x25d)][_0x228993(0x1f6)](/\[来源:\s*([^,]+),\s*条目:\s*([^,]+),\s*第(\d+)部分\]/);_0x44c9f9&&_0x44c9f9[0x1]&&_0x44c9f9[0x2]&&_0x44c9f9[0x3]&&(_0x5ef717[_0x228993(0x293)]=_0x44c9f9[0x1][_0x228993(0x2ca)](),_0x5ef717['entryName']=_0x44c9f9[0x2][_0x228993(0x2ca)](),_0x5ef717[_0x228993(0x220)]=parseInt(_0x44c9f9[0x3],0xa),_0x5ef717['sourceName']=_0x5ef717[_0x228993(0x293)]+':\x20'+_0x5ef717[_0x228993(0x1e8)]);break;case _0x228993(0x235):_0x5ef717[_0x228993(0x22a)]=_0x228993(0x259);const _0x5a3b05=_0x1de2ba[_0x228993(0x25d)]['match'](/\[来源:\s*([^,]+),.*第(\d+)部分\]/);_0x5a3b05&&_0x5a3b05[0x1]&&_0x5a3b05[0x2]&&(_0x5ef717[_0x228993(0x2c1)]=_0x5a3b05[0x1][_0x228993(0x2ca)](),_0x5ef717['part']=parseInt(_0x5a3b05[0x2],0xa));break;case _0x228993(0x28c):_0x5ef717[_0x228993(0x22a)]='novel';const _0x397f91=_0x1de2ba[_0x228993(0x25d)]['match'](/\[来源:\s*([^,]+),\s*([^,]+),\s*([^,]+),\s*([^\]]+)\]/);_0x397f91&&(_0x5ef717['sourceName']=_0x397f91[0x1][_0x228993(0x2ca)](),_0x5ef717[_0x228993(0x2d7)]=_0x397f91[0x2][_0x228993(0x2ca)](),_0x5ef717[_0x228993(0x27c)]=_0x397f91[0x3]['trim'](),_0x5ef717['section']=_0x397f91[0x4][_0x228993(0x2ca)]());break;}return{..._0x1de2ba,'score':_0x1de2ba['score']||0x1,'metadata':_0x5ef717};})[_0x579880(0x1e3)](Boolean);return console[_0x579880(0x26d)](_0x579880(0x1fe)+_0x5f315c[_0x579880(0x2dd)]+_0x579880(0x21d)+_0x10e337[_0x579880(0x272)]+_0x579880(0x2b5)),_0x10e337;})['catch'](_0x525b72=>{const _0x29f9c9=_0x18dbed;return console[_0x29f9c9(0x28a)](_0x29f9c9(0x21a)+_0x34a6fa+_0x29f9c9(0x29d),_0x525b72),[];});});}),_0x202a94=await Promise[_0x3777ba(0x2c0)](_0x41598e);_0x42775f=_0x202a94[_0x3777ba(0x23d)](),console[_0x3777ba(0x26d)](_0x3777ba(0x2b1)+_0x42775f['length']+_0x3777ba(0x2e7));const _0x284c42=[],_0xb11fa3=new Set();for(const _0x5d6b5d of _0x42775f){if(_0x5d6b5d&&typeof _0x5d6b5d==='object'&&_0x5d6b5d[_0x3777ba(0x25d)]&&typeof _0x5d6b5d[_0x3777ba(0x25d)]==='string'){const _0x21b048=_0x5d6b5d[_0x3777ba(0x25d)]['trim']();_0x21b048[_0x3777ba(0x272)]>0x0&&!_0xb11fa3[_0x3777ba(0x28f)](_0x21b048)&&(_0xb11fa3[_0x3777ba(0x29b)](_0x21b048),_0x284c42[_0x3777ba(0x2a0)](_0x5d6b5d));}}console[_0x3777ba(0x26d)]('[翰林院-日志]\x20去重后剩余\x20'+_0x284c42['length']+_0x3777ba(0x2b5)),_0x284c42[_0x3777ba(0x2d2)]((_0x2281ea,_0x13b49c)=>(_0x13b49c[_0x3777ba(0x2a5)]||0x0)-(_0x2281ea[_0x3777ba(0x2a5)]||0x0));const _0x42148e=[..._0x284c42];return console[_0x3777ba(0x26d)]('[翰林院-修复]\x20最终返回数组长度:\x20'+_0x42148e[_0x3777ba(0x272)]),console[_0x3777ba(0x26d)]('[翰林院-修复]\x20最终返回数组样本:',JSON[_0x3777ba(0x27b)](_0x42148e[_0x3777ba(0x266)](0x0,0x1),null,0x2)),_0x42148e;}async function insertVectors(_0x1b4fb7,_0x18ee5c=null,_0x5c5170){const _0x24d3b0=_0x1d2ea6;if(!_0x5c5170)throw new Error(_0x24d3b0(0x27a));if(_0x1b4fb7[_0x24d3b0(0x272)]===0x0)return{'success':!![],'count':0x0};const _0x560a9a=_0x1b4fb7['map']((_0x1dfb73,_0x250312)=>({'hash':generateHash(_0x1dfb73[_0x24d3b0(0x25d)]+Date[_0x24d3b0(0x1fc)]()+_0x250312),'text':_0x1dfb73[_0x24d3b0(0x25d)],'metadata':_0x1dfb73['metadata']||{'source':'unknown','timestamp':new Date()[_0x24d3b0(0x1db)]()}})),_0x4e378f=_0x560a9a[_0x24d3b0(0x238)]((_0x1cc9b2,_0x8f6b3a,_0x57a11a)=>{const _0x5190d8=_0x24d3b0;return _0x1cc9b2[_0x8f6b3a[_0x5190d8(0x25d)]]=_0x1b4fb7[_0x57a11a][_0x5190d8(0x270)],_0x1cc9b2;},{}),_0x14c277={'collectionId':_0x5c5170,'items':_0x560a9a,'source':_0x24d3b0(0x20d),'embeddings':_0x4e378f},_0xebab35=await fetch(_0x24d3b0(0x2e4),{'method':_0x24d3b0(0x20b),'headers':context[_0x24d3b0(0x1ff)](),'body':JSON['stringify'](_0x14c277),'signal':_0x18ee5c});if(!_0xebab35['ok']){const _0x849de5=await _0xebab35['text']();console['error'](_0x24d3b0(0x26b),_0x849de5);throw new Error(_0x24d3b0(0x1fd)+_0xebab35['status']+':\x20'+_0x849de5);}return{'success':!![],'count':_0x560a9a[_0x24d3b0(0x272)]};}async function getVectorCount(_0x3caec2=null,_0x4e78f0=_0x1d2ea6(0x28b)){const _0xe56a29=_0x1d2ea6,_0x3f1f35=getCharacterStableId();if(_0x3caec2){const _0x5c8a17=_0x4e78f0===_0xe56a29(0x279)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x5446e8=_0x5c8a17[_0x3caec2];if(!_0x5446e8)return console[_0xe56a29(0x1d5)](_0xe56a29(0x1d4)+_0x4e78f0+'\x27\x20中未找到ID为\x20'+_0x3caec2+_0xe56a29(0x208)),0x0;const _0x384cfe=_0x4e78f0==='global'?_0x5446e8[_0xe56a29(0x2b4)]||GLOBAL_SCOPE_ID:_0x3f1f35,_0x57828f=_0x384cfe+'_'+_0x3caec2;return await countVectorsInCollection(_0x57828f);}else{console['log'](_0xe56a29(0x1d1));const _0x1f902d=Object[_0xe56a29(0x1f7)](getLocalKnowledgeBases()),_0x8b2306=Object['values'](getGlobalKnowledgeBases()),_0x3cf4ea=[];_0x1f902d[_0xe56a29(0x2aa)](_0x112299=>{const _0x267ff8=_0xe56a29,_0x244d10=_0x3f1f35+'_'+_0x112299['id'];_0x3cf4ea[_0x267ff8(0x2a0)](countVectorsInCollection(_0x244d10));}),_0x8b2306[_0xe56a29(0x2aa)](_0x541048=>{const _0x2a27af=_0xe56a29,_0x456389=_0x541048[_0x2a27af(0x2b4)]||GLOBAL_SCOPE_ID,_0x495c06=_0x456389+'_'+_0x541048['id'];_0x3cf4ea[_0x2a27af(0x2a0)](countVectorsInCollection(_0x495c06));});const _0x3b7d1b=await _0x2d61b9();_0x3cf4ea[_0xe56a29(0x2a0)](countVectorsInCollection(_0x3b7d1b));const _0x49d003=await Promise[_0xe56a29(0x2c0)](_0x3cf4ea),_0x1ac37e=_0x49d003[_0xe56a29(0x238)]((_0x2dbca5,_0x7b1228)=>_0x2dbca5+_0x7b1228,0x0);return console[_0xe56a29(0x26d)](_0xe56a29(0x229)+_0x1ac37e),_0x1ac37e;}}async function countVectorsInCollection(_0x3ed987){const _0x54bd94=_0x1d2ea6;if(!_0x3ed987)return 0x0;console[_0x54bd94(0x26d)](_0x54bd94(0x22f)+_0x3ed987);const _0x50e689={'collectionId':_0x3ed987,'source':'webllm','embeddings':{}};try{const _0x2b3bf1=await fetch(_0x54bd94(0x2c9),{'method':'POST','headers':context[_0x54bd94(0x1ff)](),'body':JSON['stringify'](_0x50e689)});if(!_0x2b3bf1['ok']){if(_0x2b3bf1['status']===0x194)console['log']('[翰林院-日志]\x20集合\x20'+_0x3ed987+_0x54bd94(0x2bd));else{const _0x5a9c48=await _0x2b3bf1['text']();console[_0x54bd94(0x1d5)](_0x54bd94(0x1d7)+_0x3ed987+_0x54bd94(0x2cb)+_0x2b3bf1[_0x54bd94(0x27f)]+'):',_0x5a9c48);}return 0x0;}const _0x5af5af=await _0x2b3bf1[_0x54bd94(0x24d)]();let _0x47354a=0x0;if(Array[_0x54bd94(0x25c)](_0x5af5af))_0x47354a=_0x5af5af[_0x54bd94(0x272)];else _0x5af5af&&_0x5af5af[_0x54bd94(0x2a2)]&&(_0x47354a=_0x5af5af[_0x54bd94(0x2a2)][_0x54bd94(0x272)]);return _0x47354a;}catch(_0x3efe8b){return console[_0x54bd94(0x28a)](_0x54bd94(0x2af)+_0x3ed987+_0x54bd94(0x29d),_0x3efe8b),0x0;}}async function purgeStorage(_0x3cbc6a=null){const _0x47ff85=_0x1d2ea6;console[_0x47ff85(0x26d)](_0x47ff85(0x2c6));const _0x56db91=_0x3cbc6a||await getCollectionId();if(!_0x56db91)return console['error'](_0x47ff85(0x1cc)),toastr[_0x47ff85(0x28a)](_0x47ff85(0x1f5)),![];console[_0x47ff85(0x26d)](_0x47ff85(0x260)+_0x56db91);const _0x278444={'collectionId':_0x56db91};console[_0x47ff85(0x26d)](_0x47ff85(0x233),JSON[_0x47ff85(0x27b)](_0x278444,null,0x2));const _0x17e953=await fetch('/api/vector/purge',{'method':_0x47ff85(0x20b),'headers':context[_0x47ff85(0x1ff)](),'body':JSON[_0x47ff85(0x27b)](_0x278444)});console['log'](_0x47ff85(0x255)+_0x17e953[_0x47ff85(0x27f)]);if(!_0x17e953['ok']){const _0x491f72=await _0x17e953[_0x47ff85(0x25d)]();console[_0x47ff85(0x28a)](_0x47ff85(0x2a8),_0x491f72);}else console[_0x47ff85(0x26d)](_0x47ff85(0x1d6));return _0x17e953['ok'];}function getMessagesForCondensation(_0xd332cd=null){const _0x21ef87=_0x1d2ea6;if(!settings[_0x21ef87(0x1ed)]['enabled'])return showNotification('凝识之权未开启','warning'),[];const {layerStart:_0x2680fd,layerEnd:_0x5b01ab}=settings[_0x21ef87(0x1ed)],_0x2fb15a=_0xd332cd||settings[_0x21ef87(0x1ed)]['messageTypes'],_0x4f0d1d=context[_0x21ef87(0x299)][_0x21ef87(0x272)],_0x403c7d=Math[_0x21ef87(0x22e)](0x0,_0x2680fd-0x1),_0x18f480=_0x5b01ab===0x0||_0x5b01ab>_0x4f0d1d?_0x4f0d1d:Math[_0x21ef87(0x21c)](_0x4f0d1d,_0x5b01ab),_0x9cab7b=context[_0x21ef87(0x299)]['slice'](_0x403c7d,_0x18f480);return _0x9cab7b[_0x21ef87(0x1e3)](_0x3a0988=>{const _0x2cddda=_0x21ef87,_0x1b7b51=_0x3a0988[_0x2cddda(0x1e0)]===!![],_0x4e1c53=_0x3a0988[_0x2cddda(0x1e0)]===![];if(!_0x3a0988[_0x2cddda(0x204)]||!_0x3a0988[_0x2cddda(0x204)][_0x2cddda(0x2ca)]())return![];return _0x2fb15a[_0x2cddda(0x222)]&&_0x1b7b51||_0x2fb15a['ai']&&_0x4e1c53;});}async function processCondensation(_0x582019,_0x1be7bd=()=>{},_0x5a6f6f=null){const _0x1a4d5a=_0x1d2ea6;if(!_0x582019||_0x582019[_0x1a4d5a(0x272)]===0x0)return{'success':![],'error':'No\x20messages\x20to\x20process.'};try{let _0x507caf,_0x4c65df;const _0x174a4c=getCharacterName()||_0x1a4d5a(0x1ee);if(_0x5a6f6f){const _0x1d5824=_0x5a6f6f[_0x1a4d5a(0x216)]??'?',_0x830c09=_0x5a6f6f[_0x1a4d5a(0x267)]===0x0?'末':_0x5a6f6f['end']??'?';_0x507caf=_0x174a4c+':\x20'+_0x1d5824+'楼-'+_0x830c09+'楼';}else{const _0x314bf6=new Date()['toLocaleString'](_0x1a4d5a(0x227),{'hour12':![]});_0x507caf=_0x1a4d5a(0x22d)+_0x314bf6;}const _0x28a1e0=Object[_0x1a4d5a(0x1f7)](getLocalKnowledgeBases()),_0x1a17d6=_0x28a1e0['find'](_0x19fc81=>_0x19fc81['name']===_0x507caf);if(_0x1a17d6)_0x4c65df=_0x1a17d6['id'],_0x1be7bd(_0x1a4d5a(0x224)+_0x507caf+_0x1a4d5a(0x2c7),_0x1a4d5a(0x213));else{_0x1be7bd('[翰林院-核心]\x20准备为任务\x20\x22'+_0x507caf+_0x1a4d5a(0x297),_0x1a4d5a(0x213));const _0x215a13=addKnowledgeBase(_0x507caf,_0x1a4d5a(0x2ce));_0x4c65df=_0x215a13['id'];}const _0x5137c6=getCharacterStableId(),_0xcad96b=_0x5137c6+'_'+_0x4c65df;_0x1be7bd('[翰林院-核心]\x20凝识任务已锁定知识库:\x20'+_0x507caf+_0x1a4d5a(0x237)+_0xcad96b+')',_0x1a4d5a(0x218));const _0x52da1d=[],_0xa13e5b=context[_0x1a4d5a(0x299)];for(const _0x1c4b32 of _0x582019){const _0xe6d3e4=(_0x1c4b32['mes']||'')[_0x1a4d5a(0x28d)](/<[^>]*>/g,'')[_0x1a4d5a(0x2ca)]();if(_0xe6d3e4[_0x1a4d5a(0x272)]===0x0)continue;let _0x59f5e6;if(_0x1c4b32[_0x1a4d5a(0x2b2)]!==undefined&&_0x1c4b32[_0x1a4d5a(0x2b2)]!==null)_0x59f5e6=_0x1c4b32[_0x1a4d5a(0x2b2)];else{const _0x59f9f3=_0xa13e5b[_0x1a4d5a(0x1dc)](_0x33d54a=>_0x33d54a===_0x1c4b32);_0x59f5e6=_0x59f9f3!==-0x1?_0x59f9f3+0x1:-0x1;}const _0x484a09=new Date(_0x1c4b32['send_date']),_0x161ee9=isNaN(_0x484a09[_0x1a4d5a(0x29c)]())?new Date()[_0x1a4d5a(0x1db)]():_0x484a09[_0x1a4d5a(0x1db)](),_0x1a726e=splitIntoChunks(_0xe6d3e4,'chat_history',{'floor':_0x59f5e6,'is_user':_0x1c4b32['is_user'],'timestamp':_0x161ee9});_0x52da1d[_0x1a4d5a(0x2a0)](..._0x1a726e);}if(_0x52da1d[_0x1a4d5a(0x272)]===0x0)return{'success':!![],'count':0x0};_0x1be7bd('[翰林院-核心]\x20已将\x20'+_0x582019[_0x1a4d5a(0x272)]+_0x1a4d5a(0x203)+_0x52da1d['length']+_0x1a4d5a(0x2da),_0x1a4d5a(0x213));const _0x102715=settings['retrieval']['batchSize']||0x5;let _0x1ccb2a=0x0;for(let _0x4f56d8=0x0;_0x4f56d8<_0x52da1d['length'];_0x4f56d8+=_0x102715){const _0x3323ba=_0x52da1d[_0x1a4d5a(0x266)](_0x4f56d8,_0x4f56d8+_0x102715),_0x139e6a=_0x3323ba['map'](_0x4a34ec=>_0x4a34ec[_0x1a4d5a(0x25d)]),_0x17336f=await getEmbeddings(_0x139e6a);if(_0x3323ba['length']!==_0x17336f[_0x1a4d5a(0x272)])throw new Error(_0x1a4d5a(0x1e2));const _0x3acee9=_0x3323ba[_0x1a4d5a(0x287)]((_0x59ae7f,_0x55c2cd)=>({..._0x59ae7f,'vector':_0x17336f[_0x55c2cd]}));await insertVectors(_0x3acee9,null,_0xcad96b),_0x1ccb2a+=_0x3323ba[_0x1a4d5a(0x272)];}if(_0x5a6f6f){const _0x5bcfbb=_0x5a6f6f[_0x1a4d5a(0x267)]===0x0?context['chat']['length']:_0x5a6f6f['end'],_0x216bb7=getCharacterStableId();!settings[_0x1a4d5a(0x2a4)][_0x216bb7]&&(settings[_0x1a4d5a(0x2a4)][_0x216bb7]={}),settings[_0x1a4d5a(0x2a4)][_0x216bb7][_0xcad96b]={'start':_0x5a6f6f[_0x1a4d5a(0x216)],'end':_0x5bcfbb,'timestamp':new Date()[_0x1a4d5a(0x1db)]()},saveSettings(),_0x1be7bd(_0x1a4d5a(0x291)+_0xcad96b+_0x1a4d5a(0x2d9)+_0x5a6f6f['start']+'-'+_0x5bcfbb,_0x1a4d5a(0x213));}_0x1be7bd('[翰林院-核心]\x20聊天记录凝识完成,成功插入\x20'+_0x1ccb2a+_0x1a4d5a(0x276),_0x1a4d5a(0x218));const _0x47a8ff=_0x582019[_0x1a4d5a(0x287)](_0x14ce26=>{const _0xd5e032=_0x1a4d5a,_0x3cd7e5=_0xa13e5b[_0xd5e032(0x1dc)](_0x4f94ef=>_0x4f94ef===_0x14ce26),_0x1950a3=_0x3cd7e5!==-0x1?_0x3cd7e5+0x1:-0x1,_0xb55544=_0x14ce26[_0xd5e032(0x1e0)]?'用户':getCharacterName()||'AI';return'['+_0xb55544+_0xd5e032(0x271)+_0x1950a3+']\x20的消息已成功凝识。';});return{'success':!![],'count':_0x1ccb2a,'messages':_0x47a8ff};}catch(_0x27b2a8){return console['error'](_0x1a4d5a(0x2d4),_0x27b2a8),_0x1be7bd(_0x1a4d5a(0x24b)+_0x27b2a8[_0x1a4d5a(0x268)],_0x1a4d5a(0x28a)),{'success':![],'error':_0x27b2a8[_0x1a4d5a(0x268)]};}}async function rerankResults(_0x5af45f,_0x54ab5b,_0x3921e9){const _0x5f5954=_0x1d2ea6;let _0x118dfa=_0x5af45f;if(_0x3921e9['rerank'][_0x5f5954(0x215)]&&_0x5af45f[_0x5f5954(0x272)]>0x0){console[_0x5f5954(0x26d)]('[翰林院-Rerank]\x20开始外部API重排序...');try{const _0x11d658=_0x5af45f['map'](_0x360899=>_0x360899[_0x5f5954(0x25d)]),_0x3879b9=await executeRerank(_0x54ab5b,_0x11d658,_0x3921e9[_0x5f5954(0x24e)]),_0x21d292=_0x5af45f['map']((_0x47bf47,_0x563d5e)=>({..._0x47bf47,'original_index':_0x563d5e}));_0x118dfa=_0x21d292['map'](_0x368577=>{const _0x1e5ac0=_0x5f5954,_0x4c277c=_0x3879b9[_0x1e5ac0(0x269)][_0x1e5ac0(0x26e)](_0x4790b2=>_0x4790b2['index']===_0x368577[_0x1e5ac0(0x2d8)]),_0x50fb04=_0x4c277c?_0x4c277c[_0x1e5ac0(0x1fb)]:0x0;return{..._0x368577,'rerank_score':_0x50fb04};});if(_0x3921e9['rerank'][_0x5f5954(0x2e1)])showNotification(_0x5f5954(0x221),_0x5f5954(0x218));}catch(_0x41313d){console[_0x5f5954(0x28a)]('[翰林院-Rerank]\x20外部Rerank失败,将仅使用内部加权。',_0x41313d);if(_0x3921e9[_0x5f5954(0x24e)][_0x5f5954(0x2e1)])showNotification(_0x5f5954(0x292)+_0x41313d['message'],_0x5f5954(0x28a));_0x118dfa[_0x5f5954(0x2aa)](_0x42862c=>_0x42862c[_0x5f5954(0x1ec)]=0x0);}}else _0x118dfa[_0x5f5954(0x2aa)](_0x2702c4=>_0x2702c4['rerank_score']=0x0);console[_0x5f5954(0x26d)](_0x5f5954(0x2ac));const _0x1643e2=context[_0x5f5954(0x299)][_0x5f5954(0x272)],_0x2743bb=_0x3921e9[_0x5f5954(0x24e)][_0x5f5954(0x2be)],_0x73b4e0=_0x118dfa['map'](_0x28a1b6=>{const _0x513aab=_0x5f5954;let _0x25d7f4=0x1;const _0x5ad71c=_0x28a1b6[_0x513aab(0x282)]||{};switch(_0x5ad71c[_0x513aab(0x22a)]){case _0x513aab(0x256):_0x25d7f4*=1.2;break;case _0x513aab(0x259):_0x25d7f4*=1.1;break;case _0x513aab(0x2ce):if(_0x5ad71c['floor']&&_0x1643e2>0x0){const _0x525c56=_0x5ad71c[_0x513aab(0x2b2)]/_0x1643e2;_0x25d7f4*=0x1+_0x525c56;}break;}const _0x4d7d45=_0x28a1b6[_0x513aab(0x1ec)]*_0x2743bb+(_0x28a1b6[_0x513aab(0x2a5)]||0x0)*(0x1-_0x2743bb),_0x2dd2ba=_0x4d7d45*_0x25d7f4;return{'text':_0x28a1b6['text'],'score':_0x28a1b6[_0x513aab(0x2a5)],'rerank_score':_0x28a1b6['rerank_score'],'final_score':_0x2dd2ba,'metadata':_0x28a1b6['metadata']};});_0x73b4e0[_0x5f5954(0x2d2)]((_0x331b25,_0x30c1e8)=>(_0x30c1e8[_0x5f5954(0x2bc)]||0x0)-(_0x331b25[_0x5f5954(0x2bc)]||0x0)),console[_0x5f5954(0x26d)](_0x5f5954(0x21b));if(_0x3921e9[_0x5f5954(0x24e)][_0x5f5954(0x2d1)]){const _0x1da9d7=superSort(_0x73b4e0);return _0x1da9d7[_0x5f5954(0x266)](0x0,_0x3921e9['rerank']['top_n']);}return _0x73b4e0['slice'](0x0,_0x3921e9[_0x5f5954(0x24e)][_0x5f5954(0x251)]);}async function rearrangeChat(_0x2acfa8,_0x17cad4,_0x2cd366,_0x446282){const _0x1ec60f=_0x1d2ea6,_0x2fd192={'novel':'HANLINYUAN_RAG_NOVEL','chat_history':_0x1ec60f(0x21f),'lorebook':_0x1ec60f(0x1cf),'manual':_0x1ec60f(0x209)};Object[_0x1ec60f(0x1f7)](_0x2fd192)[_0x1ec60f(0x2aa)](_0x3ab711=>setExtensionPrompt(_0x3ab711,'',0x0,0x0,![],0x0));if(_0x446282==='quiet'||!settings['retrieval'][_0x1ec60f(0x215)])return;const _0x2e869d=_0x2acfa8[_0x1ec60f(0x266)](-settings[_0x1ec60f(0x285)][_0x1ec60f(0x29a)]);if(_0x2e869d[_0x1ec60f(0x272)]===0x0)return;const _0x28955b=_0x2e869d[_0x1ec60f(0x287)](_0x3b1265=>_0x3b1265[_0x1ec60f(0x204)])[_0x1ec60f(0x26c)]('\x20')['replace'](/<[^>]*>/g,'')[_0x1ec60f(0x2ca)]();if(!_0x28955b)return;try{const _0x2692a2=0x2,_0x4b8531=settings['settingsVersion']||0x1;let _0x5a5e67=![];if(_0x4b8531<_0x2692a2){console['log']('[翰林院-户口普查]\x20检测到旧版设置\x20(V'+_0x4b8531+_0x1ec60f(0x284)),toastr[_0x1ec60f(0x213)](_0x1ec60f(0x2ae),_0x1ec60f(0x289));const _0x1b177d=getKnowledgeBases();for(const _0x1edbdb of Object[_0x1ec60f(0x1f7)](_0x1b177d)){const _0x56547e=_0x1edbdb[_0x1ec60f(0x2dd)],_0x3ccc8b=_0x1edbdb[_0x1ec60f(0x22a)];if(_0x56547e[_0x1ec60f(0x1eb)](_0x1ec60f(0x2df)))_0x1edbdb[_0x1ec60f(0x22a)]=_0x1ec60f(0x259);else{if(_0x56547e[_0x1ec60f(0x1eb)]('小说:'))_0x1edbdb[_0x1ec60f(0x22a)]=_0x1ec60f(0x1d3);else _0x56547e['includes']('楼-')&&_0x56547e[_0x1ec60f(0x2a7)]('楼')&&_0x56547e[_0x1ec60f(0x2a7)](':')?_0x1edbdb[_0x1ec60f(0x22a)]=_0x1ec60f(0x2ce):_0x1edbdb['source']=_0x1ec60f(0x256);}_0x3ccc8b!==_0x1edbdb['source']&&console[_0x1ec60f(0x26d)](_0x1ec60f(0x283)+_0x56547e+_0x1ec60f(0x1dd)+(_0x3ccc8b||'无')+_0x1ec60f(0x244)+_0x1edbdb[_0x1ec60f(0x22a)]+']');}settings[_0x1ec60f(0x298)]=_0x2692a2,_0x5a5e67=!![];}_0x5a5e67&&(console['log'](_0x1ec60f(0x2a6)),saveSettings());let _0x2e87da=[];const _0x2becf2=settings[_0x1ec60f(0x24e)]['priorityRetrieval'];if(_0x2becf2[_0x1ec60f(0x215)]){console['log'](_0x1ec60f(0x265));const _0x53add5=Object['values'](getKnowledgeBases())[_0x1ec60f(0x1e3)](_0x6a522=>_0x6a522[_0x1ec60f(0x215)]),_0x3aab4e=Object['keys'](_0x2becf2[_0x1ec60f(0x1f0)])[_0x1ec60f(0x1e3)](_0x363c58=>_0x2becf2[_0x1ec60f(0x1f0)][_0x363c58]&&_0x2becf2['sources'][_0x363c58][_0x1ec60f(0x215)]),_0x81811d=[];let _0x25a0eb=[..._0x53add5];for(const _0x47b4d2 of _0x3aab4e){const _0x3c53bf=_0x2becf2[_0x1ec60f(0x1f0)][_0x47b4d2],_0x3ad4f9=_0x25a0eb[_0x1ec60f(0x1e3)](_0x145ec2=>_0x145ec2['source']===_0x47b4d2);_0x25a0eb=_0x25a0eb[_0x1ec60f(0x1e3)](_0x1b1ef1=>!_0x3ad4f9[_0x1ec60f(0x2a7)](_0x1b1ef1));if(_0x3ad4f9[_0x1ec60f(0x272)]>0x0){console[_0x1ec60f(0x26d)](_0x1ec60f(0x24a)+_0x47b4d2+'\x20('+_0x3ad4f9[_0x1ec60f(0x272)]+'个库)');const _0x34b2fb=queryVectors(_0x28955b,{'includeBases':_0x3ad4f9})[_0x1ec60f(0x231)](_0x3c6966=>{const _0x13a5a2=_0x1ec60f;console[_0x13a5a2(0x26d)](_0x13a5a2(0x200)+_0x47b4d2+_0x13a5a2(0x21d)+_0x3c6966[_0x13a5a2(0x272)]+'\x20条结果。');let _0x177c60=_0x3c6966[_0x13a5a2(0x1e3)](_0xae513f=>_0xae513f[_0x13a5a2(0x282)]?.['source']===_0x47b4d2);return _0x177c60=_0x177c60[_0x13a5a2(0x266)](0x0,_0x3c53bf[_0x13a5a2(0x2c5)]),console[_0x13a5a2(0x26d)](_0x13a5a2(0x22c)+_0x47b4d2+_0x13a5a2(0x261)+_0x177c60[_0x13a5a2(0x272)]+'\x20条结果。'),settings[_0x13a5a2(0x24e)][_0x13a5a2(0x2d1)]&&(_0x177c60=superSort(_0x177c60)),_0x177c60;});_0x81811d[_0x1ec60f(0x2a0)](_0x34b2fb);}}const _0x24827d=_0x25a0eb;if(_0x24827d[_0x1ec60f(0x272)]>0x0){console['log'](_0x1ec60f(0x2e2)+_0x24827d[_0x1ec60f(0x272)]+_0x1ec60f(0x239));const _0x5d10bb=queryVectors(_0x28955b,{'includeBases':_0x24827d})[_0x1ec60f(0x231)](async _0x155aad=>{const _0x2bcf50=_0x1ec60f;console[_0x2bcf50(0x26d)]('[翰林院]\x20常规组返回\x20'+_0x155aad[_0x2bcf50(0x272)]+_0x2bcf50(0x2b5)),console['log']('[翰林院]\x20开始处理常规池...');const _0x57309b=await rerankResults(_0x155aad,_0x28955b,settings);return console[_0x2bcf50(0x26d)](_0x2bcf50(0x1cd)+(_0x57309b||[])[_0x2bcf50(0x272)]+_0x2bcf50(0x2b5)),_0x57309b;});_0x81811d[_0x1ec60f(0x2a0)](_0x5d10bb);}const _0x5cae65=await Promise[_0x1ec60f(0x2c0)](_0x81811d);_0x2e87da=_0x5cae65[_0x1ec60f(0x23d)]();}else{console[_0x1ec60f(0x26d)](_0x1ec60f(0x1e7));const _0x6c67e0=await queryVectors(_0x28955b);_0x2e87da=await rerankResults(_0x6c67e0,_0x28955b,settings);}if(!_0x2e87da||_0x2e87da['length']===0x0){console[_0x1ec60f(0x26d)](_0x1ec60f(0x246));return;}console[_0x1ec60f(0x26d)](_0x1ec60f(0x210)+_0x2e87da[_0x1ec60f(0x272)]+_0x1ec60f(0x2b5));const _0x1dc8ab={'novel':[],'chat_history':[],'lorebook':[],'manual':[]};_0x2e87da['forEach'](_0x4d8e2d=>{const _0x214f1c=_0x1ec60f,_0x4e8990=_0x4d8e2d['metadata']?.[_0x214f1c(0x22a)];_0x4e8990&&_0x1dc8ab[_0x214f1c(0x24f)](_0x4e8990)&&_0x1dc8ab[_0x4e8990]['push'](_0x4d8e2d);});for(const _0x3d02ee in _0x1dc8ab){const _0xb14c05=_0x1dc8ab[_0x3d02ee];if(_0xb14c05[_0x1ec60f(0x272)]===0x0)continue;const _0x3a4865=settings[_0x1ec60f(0x1ca)+_0x3d02ee[_0x1ec60f(0x28d)]('_history','')];if(!_0x3a4865){console[_0x1ec60f(0x1d5)]('[翰林院]\x20未找到来源\x20\x27'+_0x3d02ee+_0x1ec60f(0x1de));continue;}const _0x583754=_0xb14c05[_0x1ec60f(0x287)](_0x35a5c5=>_0x35a5c5[_0x1ec60f(0x25d)])[_0x1ec60f(0x26c)]('\x0a\x0a'),_0x2ec5e1='{{'+_0x3d02ee[_0x1ec60f(0x28d)](_0x1ec60f(0x226),'')+_0x1ec60f(0x2bf);let _0x535ecd=_0x3a4865[_0x1ec60f(0x25e)][_0x1ec60f(0x28d)](_0x2ec5e1,_0x583754);_0x535ecd['trim']()&&(_0x535ecd='%%'+_0x2fd192[_0x3d02ee]+'%%'+_0x535ecd),setExtensionPrompt(_0x2fd192[_0x3d02ee],_0x535ecd,_0x3a4865[_0x1ec60f(0x295)],_0x3a4865[_0x1ec60f(0x23f)],![],_0x3a4865['depth_role']),console['log'](_0x1ec60f(0x20a)+_0x3d02ee+'\x27\x20注入\x20'+_0xb14c05['length']+'\x20条内容。');}}catch(_0xf07536){console[_0x1ec60f(0x28a)](_0x1ec60f(0x286),_0xf07536);if(settings['retrieval'][_0x1ec60f(0x2e1)])showNotification(_0x1ec60f(0x25b)+_0xf07536[_0x1ec60f(0x268)],_0x1ec60f(0x28a));}}async function moveKnowledgeBase(_0x5135c3,_0x45bf7a){const _0x589612=_0x1d2ea6,_0x52e2bf=_0x45bf7a===_0x589612(0x279)?_0x589612(0x28b):_0x589612(0x279),_0x16bc8e=getCharacterStableId();if(!_0x16bc8e&&_0x52e2bf==='local'){toastr[_0x589612(0x28a)](_0x589612(0x258));return;}const _0x33a72e=_0x45bf7a==='global'?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0xe68761=_0x52e2bf===_0x589612(0x279)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x263437=_0x33a72e[_0x5135c3];if(!_0x263437){const _0x9a5408=_0x589612(0x263)+_0x45bf7a+_0x589612(0x24c)+_0x5135c3+_0x589612(0x208);console['error'](_0x589612(0x262)+_0x9a5408),toastr[_0x589612(0x28a)](_0x589612(0x20f));return;}_0x45bf7a===_0x589612(0x28b)&&_0x52e2bf===_0x589612(0x279)&&!_0x263437['owner']&&(console[_0x589612(0x26d)](_0x589612(0x1f2)+_0x5135c3+_0x589612(0x223)+_0x16bc8e),_0x263437[_0x589612(0x2b4)]=_0x16bc8e);delete _0x33a72e[_0x5135c3],_0xe68761[_0x5135c3]=_0x263437,saveSettings();const _0x17b106='知识库【'+_0x263437[_0x589612(0x2dd)]+'】已成功移动到'+(_0x52e2bf===_0x589612(0x279)?'全局':'局部')+'。';console[_0x589612(0x26d)](_0x589612(0x262)+_0x17b106);}async function getAllVectorsFromCollection(_0x45d2a9){const _0x36d2c1=_0x1d2ea6,_0x3574b1='*',_0x52a280={'collectionId':_0x45d2a9,'searchText':_0x3574b1,'topK':0x2710,'threshold':0x0,'source':_0x36d2c1(0x20d),'embeddings':{}},_0x2d9eec=(await getEmbeddings([_0x3574b1]))[0x0];_0x52a280['embeddings']={[_0x3574b1]:_0x2d9eec};const _0x2411f9=await fetch(_0x36d2c1(0x264),{'method':_0x36d2c1(0x20b),'headers':context[_0x36d2c1(0x1ff)](),'body':JSON[_0x36d2c1(0x27b)](_0x52a280)});if(!_0x2411f9['ok']){if(_0x2411f9[_0x36d2c1(0x27f)]===0x194)return console[_0x36d2c1(0x26d)](_0x36d2c1(0x26f)+_0x45d2a9+_0x36d2c1(0x1e6)),[];const _0x121922=await _0x2411f9['text']();throw new Error(_0x36d2c1(0x20e)+_0x45d2a9+_0x36d2c1(0x2b3)+_0x121922);}const _0x3f46e2=await _0x2411f9['json']();return _0x3f46e2[_0x36d2c1(0x282)]||_0x3f46e2[_0x36d2c1(0x269)]||_0x3f46e2[_0x36d2c1(0x275)]||[];} +'use strict';const _0x58d31a=_0x53b6;function _0x1622(){const _0x44770a=['settingsVersion','[翰林院]\x20常规组返回\x20','unknown','part','substring','翰林院通告','\x22\x20已删除。','success','/api/vector/list',']\x20更正为\x20[','9770fBLQzy','toISOString','owner','queryMessageCount','在源作用域\x20\x27','rerank_score','stringify','status','[翰林院-日志]\x20所有知识库查询完毕,共获得\x20','\x20记录凝识范围:\x20','oldId','initialized','[翰林院-户口普查]\x20知识库\x20\x22','trim','key','[来源:\x20','includes','小说:','max','翰林院忆识核心已启动\x20(V5.2-集成版),已注册到全局\x20hanlinyuanRagProcessor\x20对象。','warning','[翰林院-核心]\x20凝识任务已锁定知识库:\x20','小说录入','floor','\x20条结果。','is_user','[翰林院-日志]\x20发送到\x20/api/vector/purge\x20的请求体:','未分类世界书',',将清空集合:\x20','message','296oKIudR','聊天记录','[翰林院-核心]\x20准备删除知识库\x20','test','HANLINYUAN_RAG_LOREBOOK','聊天记录\x20#','[翰林院-修复]\x20最终返回数组长度:\x20','[翰林院-核心]\x20已将\x20','用户取消了迁移操作','end','has','外部Rerank完成','toString','map','检测到旧版数据,正在进行一次性户口普查...','\x20个块。','\x27\x20中未找到ID为\x20','error','[翰林院-日志]\x20清空宝库API调用成功。','\x20的知识库。',',\x20第1卷,\x20第1章,\x20第','score','\x20列表API时出现问题\x20(状态:\x20','maxResults','[翰林院-日志]\x20统计集合\x20','POST','data','知识库名称不能为空','knowledgeBases','179090OcfiBh','[翰林院-计数]\x20在作用域\x20\x27','vectors_rearrangeChat','injection_','\x22,将数据合并入库。','chapter','所有启用库','keys','[翰林院-日志]\x20集合\x20','aborted','forEach','Rerank失败:\x20','42WlHeXY','start','json','scope','HANLINYUAN_RAG_CHAT','getRequestHeaders','手动录入:\x20','部分]','[翰林院]\x20最终无可用结果,注入中止。','hasOwnProperty','第1章','/api/vector/insert','[翰林院]\x20已从\x20','now','\x5c$&','[翰林院-日志]\x20清空目标集合ID:\x20',',\x20向量化录入时间:\x20','reranked','min','range','[翰林院-日志]\x20开始获取所有知识库的向量总数...','[翰林院-日志]\x20无法确定要清空的目标集合ID。','5951CTTLpp','\x20(集合ID:\x20','mes','comment','charCodeAt','\x22\x20创建专属知识库...','\x20条消息分解为\x20','\x0a$1','[翰林院]\x20创建优先查询组:\x20','移动失败:没有当前角色,无法移入局部知识库。','世界书','\x20个向量条目。','个库)','metadata','global','toLowerCase','(已锁定:\x20','微言录总结','enabled','小说:\x20','push','世界书条目','advanced','正在智能分块...','vector','\x20及其向量数据。','find','lorebook','log','379748NPvGyV','task_','flat','[翰林院-日志]\x20查询知识库\x20','replace','match','abs','27405tTGBRP','matchThreshold','extensionSettings','random','[翰林院-日志]\x20清空宝库API错误:','\x20(范围:\x20','AbortError','zh-CN','manual','统一检索部分的Rerank已完成','删除知识库失败,未能清空后端数据。','[翰林院-迁移]\x20用户取消了迁移操作。','旧版宝库\x20(Legacy)','[翰林院-核心]\x20聊天记录凝识失败:\x20','isArray','未知角色','[翰林院-配置]\x20为旧版知识库\x20','\x20个特定知识库。','\x22\x20已从\x20[','514728YaAESa','操作已取消。','condensation','results','/api/vector/query','[翰林院-核心]\x20ingestTextToHanlinyuan\x20失败:','sjshu','add','\x20池精确提取\x20','\x27\x20注入\x20','values','insertVectors\x20必须接收一个有效的\x20collectionId\x20参数。','[翰林院-Rerank]\x20外部Rerank失败,将仅使用内部加权。',',\x20第','legacy','[翰林院-核心]\x20准备为任务\x20\x22','priorityRetrieval','join','[翰林院-迁移]\x20集合\x20','凝识之权未开启','[翰林院-分块]\x20未知的来源类型\x20\x27','\x20时发生网络错误:','notify','length','text','移动失败:未找到源条目。','final_score','[翰林院]\x20最终准备注入\x20','[翰林院-日志]\x20查询白名单已提供,将查询\x20','】已成功移动到','[翰林院-修复]\x20最终返回数组样本:','\x20失败:\x20','无法确定要清空的目标宝库。','user','rearrangeChat','[翰林院-日志]\x20忆识存入API错误:','[翰林院-日志]\x20开始向量查询...\x20(目标:\x20','hashes',')\x20的状态已切换为:\x20','findIndex'];_0x1622=function(){return _0x44770a;};return _0x1622();}(function(_0x596dc9,_0x1b5a25){const _0x14a3a1=_0x53b6,_0x313834=_0x596dc9();while(!![]){try{const _0x42322b=parseInt(_0x14a3a1(0x1ef))/0x1*(parseInt(_0x14a3a1(0x19a))/0x2)+parseInt(_0x14a3a1(0x206))/0x3+-parseInt(_0x14a3a1(0x233))/0x4+parseInt(_0x14a3a1(0x23a))/0x5*(parseInt(_0x14a3a1(0x1a6))/0x6)+parseInt(_0x14a3a1(0x1d5))/0x7*(parseInt(_0x14a3a1(0x17d))/0x8)+parseInt(_0x14a3a1(0x24d))/0x9+-parseInt(_0x14a3a1(0x27f))/0xa*(parseInt(_0x14a3a1(0x1bc))/0xb);if(_0x42322b===_0x1b5a25)break;else _0x313834['push'](_0x313834['shift']());}catch(_0x3c946f){_0x313834['push'](_0x313834['shift']());}}}(_0x1622,0x50f29));import{extension_prompt_roles,setExtensionPrompt}from'/script.js';import*as _0x4b95b8 from'./utils/context-utils.js';import{getCollectionIdInfo,getCharacterId,getCharacterStableId}from'./utils/context-utils.js';import{defaultSettings as _0x2e18e9}from'./rag-settings.js';import*as _0x373cd3 from'./ingestion-manager.js';import{getEmbeddings,fetchEmbeddingModels as _0x1849a7,fetchRerankModels as _0x3bc1c3,executeRerank,testApiConnection as _0x30722b}from'./rag-api.js';import{superSort}from'./super-sorter.js';const MODULE_NAME=_0x58d31a(0x216),OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME=_0x58d31a(0x19c),GLOBAL_SCOPE_ID='_global';let context=null,settings=null,lockedCollectionId=null;function filterWorldbooks(_0x539dec,_0x3a0bf1){const _0x59ffde=_0x58d31a;if(!_0x539dec||!_0x539dec[_0x59ffde(0x28c)]())return _0x3a0bf1;const _0x27dfd2=_0x539dec[_0x59ffde(0x225)]()[_0x59ffde(0x28c)]();return _0x3a0bf1['filter'](_0x39d823=>{const _0x4ecdc6=_0x59ffde;return _0x39d823[_0x4ecdc6(0x225)]()[_0x4ecdc6(0x28f)](_0x27dfd2)||containsPinyinMatch(_0x39d823,_0x27dfd2);});}function filterWorldbookEntries(_0x450631,_0x5ed999){const _0x2cd35c=_0x58d31a;if(!_0x450631||!_0x450631['trim']())return _0x5ed999;const _0x24b2dc=_0x450631[_0x2cd35c(0x225)]()[_0x2cd35c(0x28c)]();return _0x5ed999[_0x2cd35c(0x1cf)](_0x4ee205=>{const _0x5189ac=_0x2cd35c,_0x32842a=[_0x4ee205[_0x5189ac(0x1bf)]||'',_0x4ee205[_0x5189ac(0x28d)]||'',_0x4ee205['content']||''][_0x5189ac(0x25e)]('\x20')['toLowerCase']();return _0x32842a['includes'](_0x24b2dc)||containsPinyinMatch(_0x4ee205[_0x5189ac(0x1bf)]||'',_0x24b2dc);});}function containsPinyinMatch(_0x4c2bc4,_0x452a22){const _0x40548c=_0x58d31a,_0x40da67={'世界书':_0x40548c(0x253),'条目':_0x40548c(0x1f1),'编纂':_0x40548c(0x21a),'搜索':'sousuo'},_0x2c4c09=_0x40da67[_0x4c2bc4];return _0x2c4c09&&_0x2c4c09[_0x40548c(0x28f)](_0x452a22);}function highlightSearchMatch(_0x515c83,_0x266bdd){const _0x4a64b1=_0x58d31a;if(!_0x266bdd||!_0x266bdd['trim']())return _0x515c83;const _0x2a17fd=new RegExp('('+_0x266bdd[_0x4a64b1(0x237)](/[.*+?^${}()|[\]\\]/g,_0x4a64b1(0x1b4))+')','gi');return _0x515c83[_0x4a64b1(0x237)](_0x2a17fd,_0x4a64b1(0x21d));}function debounce(_0x5aa464,_0x5d6b00){let _0x5cbd9b;return function _0x51a303(..._0x45ab36){const _0x2196d3=()=>{clearTimeout(_0x5cbd9b),_0x5aa464(..._0x45ab36);};clearTimeout(_0x5cbd9b),_0x5cbd9b=setTimeout(_0x2196d3,_0x5d6b00);};}export{initialize,getSettings,saveSettings,resetSettings,_0x30722b as testApiConnection,_0x1849a7 as fetchEmbeddingModels,_0x3bc1c3 as fetchRerankModels,getVectorCount,purgeStorage,getMessagesForCondensation,processCondensation,ingestTextToHanlinyuan,getCollectionId,toggleSessionLock,isSessionLocked,getLockedSessionInfo,addKnowledgeBase,removeKnowledgeBase,getLocalKnowledgeBases,getGlobalKnowledgeBases,toggleKnowledgeBase,moveKnowledgeBase,filterWorldbooks,filterWorldbookEntries,highlightSearchMatch,debounce};function initialize(){const _0x41579c=_0x58d31a;context=SillyTavern['getContext']();if(!context){console[_0x41579c(0x18e)](_0x41579c(0x204));return;}settings=getSettings(),!window[_0x41579c(0x1c8)]&&(window[_0x41579c(0x1c8)]={}),window[_0x41579c(0x1c8)][_0x41579c(0x26f)]=rearrangeChat,window[_0x41579c(0x1c8)][_0x41579c(0x28a)]=!![],console['log'](_0x41579c(0x292));}async function ingestTextToHanlinyuan(_0x1d76c7,_0x382fcc=_0x58d31a(0x242),_0x23eb41={},_0x466453=()=>{},_0x32b9f4=null,_0xdee15b=()=>{},_0x56dd99=()=>{},_0x32cf6e=null,_0x2173be=0x0){const _0x4a4703=_0x58d31a;if(!_0x1d76c7||!_0x1d76c7[_0x4a4703(0x28c)]())return{'success':![],'error':_0x4a4703(0x1cc)};if(!settings)return{'success':![],'error':'核心未初始化'};try{const _0x37504d=getCollectionIdInfo(),_0x545a65=await _0x23dff3();if(_0x37504d['oldId']&&_0x37504d['oldId']===_0x545a65&&_0x37504d[_0x4a4703(0x289)]!==_0x37504d[_0x4a4703(0x1d4)]){const _0x57f18e=confirm(_0x4a4703(0x1e1));if(_0x57f18e)_0xdee15b('[翰林院-迁移]\x20用户确认迁移,正在处理旧宝库:\x20'+_0x37504d[_0x4a4703(0x289)],_0x4a4703(0x205)),await purgeStorage(_0x37504d['oldId']),_0xdee15b('[翰林院-迁移]\x20旧宝库已清空。',_0x4a4703(0x27c));else return _0xdee15b(_0x4a4703(0x245),_0x4a4703(0x1c4)),toastr['info'](_0x4a4703(0x24e)),{'success':![],'error':_0x4a4703(0x185)};}let _0xbf02df,_0x2ff584;const _0x61d7f9=new Date()['toLocaleString'](_0x4a4703(0x241),{'hour12':![]}),_0x1d5b37=getCharacterName()||_0x4a4703(0x249);switch(_0x382fcc){case'chat_history':const _0x466861=_0x23eb41[_0x4a4703(0x1b9)]||{},_0x15eead=_0x466861[_0x4a4703(0x1a7)]??'?',_0x1a5600=_0x466861[_0x4a4703(0x186)]===0x0?'末':_0x466861['end']??'?';_0xbf02df=_0x1d5b37+':\x20'+_0x15eead+'楼-'+_0x1a5600+'楼';break;case _0x4a4703(0x231):const _0x4cf7b6=_0x23eb41['bookName']||_0x4a4703(0x29a);if(_0x23eb41['entryName']&&_0x23eb41[_0x4a4703(0x1f2)][_0x4a4703(0x28f)](_0x4a4703(0x227)))_0x23eb41[_0x4a4703(0x1f2)]=_0x4a4703(0x1e2);else _0x23eb41[_0x4a4703(0x1f2)]&&_0x23eb41[_0x4a4703(0x1f2)][_0x4a4703(0x28f)]('宏史卷总结')&&(_0x23eb41['entryName']='对话记录大总结');const _0x5942c2=_0x23eb41[_0x4a4703(0x1f2)]||'未知条目';_0xbf02df=_0x4cf7b6+':\x20'+_0x5942c2;break;case'novel':_0xbf02df=_0x4a4703(0x229)+(_0x23eb41[_0x4a4703(0x1d0)]||'未知小说');break;case _0x4a4703(0x242):default:_0xbf02df=_0x4a4703(0x1ac)+_0x61d7f9;break;}const _0x131eb1=Object[_0x4a4703(0x257)](getKnowledgeBases()),_0x5b281a=_0x131eb1[_0x4a4703(0x230)](_0x2f6a9e=>_0x2f6a9e[_0x4a4703(0x1f4)]===_0xbf02df);if(_0x5b281a)_0x2ff584=_0x5b281a['id'],_0xdee15b('[翰林院-核心]\x20检测到同名知识库\x20\x22'+_0xbf02df+_0x4a4703(0x19e),'info');else{_0xdee15b('[翰林院-核心]\x20准备为任务\x20\x22'+_0xbf02df+_0x4a4703(0x1c1),'info');const _0x8934a7=addKnowledgeBase(_0xbf02df,_0x382fcc);_0x2ff584=_0x8934a7['id'];}const _0x1956ad=getCharacterStableId(),_0x3dda90=_0x1956ad+'_'+_0x2ff584;_0xdee15b('[翰林院-核心]\x20已创建并锁定知识库:\x20'+_0xbf02df+_0x4a4703(0x1bd)+_0x3dda90+')',_0x4a4703(0x27c)),_0xdee15b(_0x4a4703(0x1f5)+_0x3dda90,_0x4a4703(0x1c4)),_0x466453({'message':_0x4a4703(0x22d),'processed':0x0,'total':0x1});const _0x13af12=splitIntoChunks(_0x1d76c7,_0x382fcc,_0x23eb41),_0x3fe8c3=_0x13af12[_0x4a4703(0x264)];if(_0x32b9f4?.[_0x4a4703(0x1a3)])throw new Error('AbortError');_0xdee15b('[翰林院-核心]\x20将来源\x27'+_0xbf02df+_0x4a4703(0x1e4)+_0x3fe8c3+_0x4a4703(0x18c),_0x4a4703(0x1c4));if(_0x3fe8c3===0x0)return{'success':!![],'count':0x0};const _0x572f63=settings[_0x4a4703(0x219)][_0x4a4703(0x1e9)]||0x5;let _0x1be833=_0x2173be;for(let _0x254274=_0x2173be;_0x254274<_0x3fe8c3;_0x254274+=_0x572f63){if(_0x32b9f4?.[_0x4a4703(0x1a3)])throw new Error('AbortError');const _0x309ea1=_0x13af12[_0x4a4703(0x20c)](_0x254274,_0x254274+_0x572f63);_0x466453({'message':_0x4a4703(0x1e3)+(_0x254274+0x1)+'-'+(_0x254274+_0x309ea1[_0x4a4703(0x264)])+'\x20块','processed':_0x254274,'total':_0x3fe8c3});const _0x4bbcbb=_0x309ea1[_0x4a4703(0x18a)](_0x16dc9f=>_0x16dc9f[_0x4a4703(0x265)]),_0x130372=await getEmbeddings(_0x4bbcbb,_0x32b9f4);if(_0x32b9f4?.['aborted'])throw new Error(_0x4a4703(0x240));if(_0x309ea1[_0x4a4703(0x264)]!==_0x130372[_0x4a4703(0x264)])throw new Error('文本块和向量数量不匹配');const _0x5ee4f5=_0x309ea1[_0x4a4703(0x18a)]((_0x5e88ce,_0xaaa16)=>({..._0x5e88ce,'vector':_0x130372[_0xaaa16]}));await insertVectors(_0x5ee4f5,_0x32b9f4,_0x3dda90),_0x1be833+=_0x309ea1[_0x4a4703(0x264)],_0x32cf6e&&_0x373cd3['saveProgress'](_0x32cf6e,_0x1be833,_0x3fe8c3),await _0x56dd99();}return _0x32cf6e&&_0x373cd3[_0x4a4703(0x20b)](_0x32cf6e),_0xdee15b(_0x4a4703(0x1d3)+_0x1be833+_0x4a4703(0x221),_0x4a4703(0x27c)),{'success':!![],'count':_0x1be833};}catch(_0x1f0223){if(_0x1f0223[_0x4a4703(0x1f4)]===_0x4a4703(0x240)){_0xdee15b(_0x4a4703(0x1da),_0x4a4703(0x205));throw _0x1f0223;}return console[_0x4a4703(0x18e)](_0x4a4703(0x252),_0x1f0223),_0xdee15b(_0x4a4703(0x209)+_0x1f0223[_0x4a4703(0x17c)],'error'),{'success':![],'error':_0x1f0223[_0x4a4703(0x17c)]};}}function getSettings(){const _0x1fd69f=_0x58d31a;if(!context||!context[_0x1fd69f(0x23c)])return structuredClone(_0x2e18e9);let _0x2dadba=context['extensionSettings'][MODULE_NAME];!_0x2dadba&&(_0x2dadba={},context[_0x1fd69f(0x23c)][MODULE_NAME]=_0x2dadba);_0x2dadba[_0x1fd69f(0x20a)]===undefined&&(_0x2dadba[_0x1fd69f(0x20a)]={});_0x2dadba[_0x1fd69f(0x199)]===undefined&&(_0x2dadba['knowledgeBases']={});for(const _0x16fc98 in _0x2e18e9){if(_0x2dadba[_0x16fc98]===undefined)_0x2dadba[_0x16fc98]=structuredClone(_0x2e18e9[_0x16fc98]);else{if(typeof _0x2e18e9[_0x16fc98]==='object'&&!Array['isArray'](_0x2e18e9[_0x16fc98])&&_0x2e18e9[_0x16fc98]!==null)for(const _0x209e6b in _0x2e18e9[_0x16fc98]){_0x2dadba[_0x16fc98][_0x209e6b]===undefined&&(_0x2dadba[_0x16fc98][_0x209e6b]=_0x2e18e9[_0x16fc98][_0x209e6b]);}}}return _0x2dadba;}function saveSettings(){const _0x555599=_0x58d31a;if(context)context[_0x555599(0x1eb)]();}function resetSettings(){context&&(context['extensionSettings'][MODULE_NAME]=structuredClone(_0x2e18e9),saveSettings());}function showNotification(_0x2cb3cd,_0x38f328=_0x58d31a(0x1c4)){toastr[_0x38f328](_0x2cb3cd);}function getTagForSource(_0xfef1de){const _0x4084eb=_0x58d31a;switch(_0xfef1de){case _0x4084eb(0x1dd):return _0x4084eb(0x17e);case'lorebook':return _0x4084eb(0x220);case _0x4084eb(0x242):return'手动录入';case _0x4084eb(0x1d9):return _0x4084eb(0x295);default:return'资料';}}function splitIntoChunks(_0x2d938c,_0x200900,_0x351e70={}){const _0xc05d27=_0x58d31a;switch(_0x200900){case _0xc05d27(0x1d9):return _chunkForNovel(_0x2d938c,_0x351e70);case'chat_history':return _chunkForChatHistory(_0x2d938c,_0x351e70);case'lorebook':return _chunkForLorebook(_0x2d938c,_0x351e70);case'manual':return _chunkForManual(_0x2d938c,_0x351e70);default:console[_0xc05d27(0x205)](_0xc05d27(0x261)+_0x200900+'\x27,使用通用分块逻辑。');return _chunkForManual(_0x2d938c,{..._0x351e70,'sourceName':_0x351e70[_0xc05d27(0x1d0)]||'未知来源'});}}function _chunkForNovel(_0x325958,_0xce1e7b){const _0x2c8441=_0x58d31a,{chunkSize:_0x13f95e,overlap:_0x14e5f0}=settings[_0x2c8441(0x22c)],{sourceName:sourceName='小说'}=_0xce1e7b,_0x4e86ac=[];if(!_0x325958||_0x13f95e<=0x0)return _0x4e86ac;const _0x52b9ce=/(第\s*[一二三四五六七八九十百千万零\d]+\s*卷)/gim,_0x3250c6=/(第\s*[一二三四五六七八九十百千万零\d]+\s*[章回节部])|^(Chapter\s+\d+)/gim;let _0x1e061f=0x0;const _0xa9849d=_0x325958['split']('\x0a');let _0x56b681='第1卷',_0x241726='第1章',_0x50ed63=[];function _0x238a47(){const _0x4d89ff=_0x2c8441;if(_0x50ed63[_0x4d89ff(0x264)]===0x0)return;const _0x35b7f4=_0x50ed63['join']('\x0a');let _0x387535=0x0,_0x1b9f8a=0x1;while(_0x387535<_0x35b7f4[_0x4d89ff(0x264)]){const _0x14aa58=Math[_0x4d89ff(0x1b8)](_0x387535+_0x13f95e,_0x35b7f4[_0x4d89ff(0x264)]),_0xa0409e=_0x35b7f4[_0x4d89ff(0x279)](_0x387535,_0x14aa58);if(_0xa0409e[_0x4d89ff(0x28c)]()[_0x4d89ff(0x264)]>0x0){const _0x260cc4={'source':_0x4d89ff(0x1d9),'sourceName':sourceName,'timestamp':new Date()[_0x4d89ff(0x280)](),'globalIndex':_0x1e061f++,'volume':_0x56b681,'chapter':_0x241726,'section':_0x1b9f8a},_0x53fc9a=getTagForSource('novel'),_0x32e214=_0x4d89ff(0x28e)+sourceName+',\x20'+_0x56b681+',\x20'+_0x241726+',\x20第'+_0x1b9f8a+'节]',_0x3a56c2='<'+_0x53fc9a+'>\x0a'+_0x32e214+'\x0a'+_0xa0409e+_0x4d89ff(0x1c3)+_0x53fc9a+'>';_0x4e86ac[_0x4d89ff(0x22a)]({'text':_0x3a56c2,'metadata':_0x260cc4}),_0x1b9f8a++;}_0x387535+=_0x13f95e-_0x14e5f0;if(_0x387535>=_0x35b7f4[_0x4d89ff(0x264)])break;}_0x50ed63=[];}for(const _0x171b95 of _0xa9849d){const _0x4e6fc0=_0x171b95[_0x2c8441(0x28c)]();if(_0x52b9ce[_0x2c8441(0x180)](_0x4e6fc0))_0x238a47(),_0x56b681=_0x4e6fc0,_0x241726='第1章';else _0x3250c6[_0x2c8441(0x180)](_0x4e6fc0)?(_0x238a47(),_0x241726=_0x4e6fc0):_0x50ed63[_0x2c8441(0x22a)](_0x171b95);}_0x238a47();if(_0x4e86ac[_0x2c8441(0x264)]===0x0&&_0x325958[_0x2c8441(0x264)]>0x0){let _0x175af8=0x0,_0x45b5b7=0x1;while(_0x175af8<_0x325958[_0x2c8441(0x264)]){const _0x3722c5=Math[_0x2c8441(0x1b8)](_0x175af8+_0x13f95e,_0x325958[_0x2c8441(0x264)]),_0x427030=_0x325958[_0x2c8441(0x279)](_0x175af8,_0x3722c5),_0x348198={'source':_0x2c8441(0x1d9),'sourceName':sourceName,'timestamp':new Date()['toISOString'](),'globalIndex':_0x4e86ac[_0x2c8441(0x264)],'volume':'第1卷','chapter':_0x2c8441(0x1b0),'section':_0x45b5b7},_0x4a6e44=getTagForSource('novel'),_0x30c90f=_0x2c8441(0x28e)+sourceName+_0x2c8441(0x191)+_0x45b5b7+'节]',_0x5c75f1='<'+_0x4a6e44+'>\x0a'+_0x30c90f+'\x0a'+_0x427030+'\x0a';_0x4e86ac[_0x2c8441(0x22a)]({'text':_0x5c75f1,'metadata':_0x348198}),_0x45b5b7++,_0x175af8+=_0x13f95e-_0x14e5f0;}}return _0x4e86ac;}function _chunkForChatHistory(_0x406a5a,_0x1ae9c4){const _0x5eb32a=_0x58d31a,{chunkSize:_0x4de07c,overlap:_0x5db0f3}=settings['advanced'],{floor:_0x326a0c,is_user:_0x4f1d7d,timestamp:_0x5b402b}=_0x1ae9c4,_0x310555=[];if(!_0x406a5a||_0x4de07c<=0x0)return _0x310555;let _0x7174cc=0x1,_0x250368=0x0;while(_0x250368<_0x406a5a[_0x5eb32a(0x264)]){const _0x5e42f3=Math['min'](_0x250368+_0x4de07c,_0x406a5a[_0x5eb32a(0x264)]),_0x3aaeb5=_0x406a5a[_0x5eb32a(0x279)](_0x250368,_0x5e42f3),_0xd4b1b8=_0x5eb32a(0x1ce)+_0x326a0c+_0x5eb32a(0x25a)+_0x7174cc+_0x5eb32a(0x1ad),_0x33434e=getTagForSource(_0x5eb32a(0x1dd)),_0x9bdbbc='<'+_0x33434e+'>\x0a'+_0xd4b1b8+'\x0a'+_0x3aaeb5+'\x0a';_0x310555[_0x5eb32a(0x22a)]({'text':_0x9bdbbc,'metadata':{'source':'chat_history','sourceName':_0x5eb32a(0x182)+_0x326a0c,'floor':_0x326a0c,'part':_0x7174cc,'is_user':_0x4f1d7d,'timestamp':_0x5b402b}}),_0x7174cc++,_0x250368+=_0x4de07c-_0x5db0f3;if(_0x250368>=_0x406a5a[_0x5eb32a(0x264)])break;}return _0x310555;}function _chunkForLorebook(_0xa8717a,_0xc4601){const _0x154a55=_0x58d31a,{chunkSize:_0x1cbeb8,overlap:_0x13228a}=settings['advanced'],{bookName:bookName=_0x154a55(0x220),entryName:entryName=_0x154a55(0x22b)}=_0xc4601,_0x16c118=[];if(!_0xa8717a||_0x1cbeb8<=0x0)return _0x16c118;let _0x1092cc=0x1,_0x533672=0x0;while(_0x533672<_0xa8717a[_0x154a55(0x264)]){const _0xfbe3dc=Math[_0x154a55(0x1b8)](_0x533672+_0x1cbeb8,_0xa8717a[_0x154a55(0x264)]),_0x347ad2=_0xa8717a[_0x154a55(0x279)](_0x533672,_0xfbe3dc),_0x3d4f24=_0x154a55(0x28e)+bookName+_0x154a55(0x213)+entryName+',\x20第'+_0x1092cc+_0x154a55(0x1ad),_0xb252d6=getTagForSource(_0x154a55(0x231)),_0x43ee5d='<'+_0xb252d6+'>\x0a'+_0x3d4f24+'\x0a'+_0x347ad2+_0x154a55(0x1c3)+_0xb252d6+'>';_0x16c118[_0x154a55(0x22a)]({'text':_0x43ee5d,'metadata':{'source':_0x154a55(0x231),'sourceName':bookName+':\x20'+entryName,'bookName':bookName,'entryName':entryName,'part':_0x1092cc,'timestamp':new Date()['toISOString']()}}),_0x1092cc++,_0x533672+=_0x1cbeb8-_0x13228a;if(_0x533672>=_0xa8717a[_0x154a55(0x264)])break;}return _0x16c118;}function _chunkForManual(_0x3485b0,_0x38a717){const _0x5dc93e=_0x58d31a,{chunkSize:_0x20b9f1,overlap:_0x5d44dd}=settings[_0x5dc93e(0x22c)],{sourceName:sourceName=_0x5dc93e(0x210)}=_0x38a717,_0x31c8c5=[];if(!_0x3485b0||_0x20b9f1<=0x0)return _0x31c8c5;const _0x5061b7=new Date(),_0x7a759c=_0x5061b7[_0x5dc93e(0x1ee)](_0x5dc93e(0x241));let _0x3aa5d0=0x1,_0x5f567f=0x0;while(_0x5f567f<_0x3485b0[_0x5dc93e(0x264)]){const _0x4e57c7=Math['min'](_0x5f567f+_0x20b9f1,_0x3485b0[_0x5dc93e(0x264)]),_0x5b96c9=_0x3485b0['substring'](_0x5f567f,_0x4e57c7),_0x1708fe='[来源:\x20'+sourceName+_0x5dc93e(0x1b6)+_0x7a759c+_0x5dc93e(0x25a)+_0x3aa5d0+_0x5dc93e(0x1ad),_0xdb8f6d=getTagForSource('manual'),_0x2bc1cd='<'+_0xdb8f6d+'>\x0a'+_0x1708fe+'\x0a'+_0x5b96c9+_0x5dc93e(0x1c3)+_0xdb8f6d+'>';_0x31c8c5[_0x5dc93e(0x22a)]({'text':_0x2bc1cd,'metadata':{'source':_0x5dc93e(0x242),'sourceName':sourceName,'part':_0x3aa5d0,'timestamp':_0x5061b7[_0x5dc93e(0x280)]()}}),_0x3aa5d0++,_0x5f567f+=_0x20b9f1-_0x5d44dd;if(_0x5f567f>=_0x3485b0[_0x5dc93e(0x264)])break;}return _0x31c8c5;}import{getCollectionId as _0x23dff3,getCharacterName}from'./utils/context-utils.js';async function getCollectionId(){return lockedCollectionId||await _0x23dff3();}async function toggleSessionLock(){return lockedCollectionId?(lockedCollectionId=null,![]):(lockedCollectionId=await _0x23dff3(),!![]);}function isSessionLocked(){return lockedCollectionId!==null;}function getLockedSessionInfo(){const _0x501c8b=_0x58d31a;if(!lockedCollectionId)return null;return{'id':lockedCollectionId,'name':_0x501c8b(0x226)+lockedCollectionId[_0x501c8b(0x279)](0x0,0x8)+'...)'};}function getLocalKnowledgeBases(){const _0x34d31c=_0x58d31a,_0x43dcac=getCharacterStableId();return!settings[_0x34d31c(0x199)][_0x43dcac]&&(settings[_0x34d31c(0x199)][_0x43dcac]={}),settings[_0x34d31c(0x199)][_0x43dcac];}function getGlobalKnowledgeBases(){const _0x339e72=_0x58d31a;return!settings[_0x339e72(0x199)][GLOBAL_SCOPE_ID]&&(settings[_0x339e72(0x199)][GLOBAL_SCOPE_ID]={}),settings[_0x339e72(0x199)][GLOBAL_SCOPE_ID];}function getKnowledgeBases(){const _0x22bc0a=getLocalKnowledgeBases(),_0x198fce=getGlobalKnowledgeBases();return{..._0x198fce,..._0x22bc0a};}function addKnowledgeBase(_0x257e43,_0x158af9='manual'){const _0xf07685=_0x58d31a;if(!_0x257e43||!_0x257e43['trim']())throw new Error(_0xf07685(0x198));const _0x5d6491=getCharacterStableId(),_0x2362ac=getLocalKnowledgeBases(),_0x15a996=_0xf07685(0x234)+Date[_0xf07685(0x1b3)]()+'_'+Math[_0xf07685(0x23d)]()[_0xf07685(0x189)](0x24)[_0xf07685(0x279)](0x2,0x9),_0x2dba56={'id':_0x15a996,'name':_0x257e43[_0xf07685(0x28c)](),'enabled':!![],'createdAt':new Date()[_0xf07685(0x280)](),'owner':_0x5d6491,'source':_0x158af9};return _0x2362ac[_0x15a996]=_0x2dba56,saveSettings(),console[_0xf07685(0x232)](_0xf07685(0x1f6)+_0x5d6491+'\x20添加新知识库:\x20'+_0x257e43+_0xf07685(0x1ff)+_0x15a996+')'),_0x2dba56;}async function removeKnowledgeBase(_0x2701bc,_0x23e100){const _0x51dbe8=_0x58d31a,_0x17a79d=getCharacterStableId(),_0x49461c=_0x23e100===_0x51dbe8(0x224)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x2dc46c=_0x49461c[_0x2701bc],_0x294eb1=_0x2dc46c?.['name']||_0x2701bc;if(!_0x2dc46c){console[_0x51dbe8(0x205)]('[翰林院-核心]\x20尝试删除一个不存在的知识库:\x20'+_0x2701bc+_0x51dbe8(0x23f)+_0x23e100+')');return;}const _0x17e58e=_0x23e100===_0x51dbe8(0x224)?_0x2dc46c[_0x51dbe8(0x281)]||GLOBAL_SCOPE_ID:_0x17a79d,_0x1c60db=_0x17e58e+'_'+_0x2701bc;console['log'](_0x51dbe8(0x17f)+_0x2701bc+_0x51dbe8(0x17b)+_0x1c60db);const _0x177240=await purgeStorage(_0x1c60db);_0x177240?(delete _0x49461c[_0x2701bc],saveSettings(),console[_0x51dbe8(0x232)](_0x51dbe8(0x1db)+_0x2701bc+_0x51dbe8(0x22f)),toastr[_0x51dbe8(0x27c)](_0x51dbe8(0x1e0)+_0x294eb1+_0x51dbe8(0x27b))):(console[_0x51dbe8(0x18e)]('[翰林院-核心]\x20清空向量集合\x20'+_0x1c60db+'\x20失败,删除操作中止。'),toastr['error'](_0x51dbe8(0x244)));}function toggleKnowledgeBase(_0x1ac22c,_0x10e82c){const _0x435bf0=_0x58d31a,_0xea3a6d=_0x10e82c===_0x435bf0(0x224)?getGlobalKnowledgeBases():getLocalKnowledgeBases();_0xea3a6d[_0x1ac22c]&&(_0xea3a6d[_0x1ac22c][_0x435bf0(0x228)]=!_0xea3a6d[_0x1ac22c][_0x435bf0(0x228)],saveSettings(),console[_0x435bf0(0x232)](_0x435bf0(0x21b)+_0x1ac22c+_0x435bf0(0x23f)+_0x10e82c+_0x435bf0(0x273)+(_0xea3a6d[_0x1ac22c][_0x435bf0(0x228)]?'启用':'禁用')));}function generateHash(_0x4773c8){const _0x167c79=_0x58d31a;let _0x1467cf=0x0;for(let _0x361110=0x0;_0x361110<_0x4773c8['length'];_0x361110++){const _0x1ef1e6=_0x4773c8[_0x167c79(0x1c0)](_0x361110);_0x1467cf=(_0x1467cf<<0x5)-_0x1467cf+_0x1ef1e6,_0x1467cf=_0x1467cf&_0x1467cf;}return Math[_0x167c79(0x239)](_0x1467cf)['toString'](0x24);}function _0x53b6(_0x470fb9,_0x1fd1c9){const _0x1622f5=_0x1622();return _0x53b6=function(_0x53b69d,_0x3469c5){_0x53b69d=_0x53b69d-0x17b;let _0x14e9bf=_0x1622f5[_0x53b69d];return _0x14e9bf;},_0x53b6(_0x470fb9,_0x1fd1c9);}async function queryVectors(_0x5b0b6d,_0x456ef5={}){const _0x170b01=_0x58d31a,{includeBases:includeBases=null}=_0x456ef5;console['log'](_0x170b01(0x271)+(includeBases?'指定知识库':_0x170b01(0x1a0))+')');const _0x8a8278=getCharacterStableId();let _0x2cf293;if(includeBases)_0x2cf293=includeBases,console[_0x170b01(0x232)](_0x170b01(0x269)+_0x2cf293[_0x170b01(0x264)]+_0x170b01(0x24b));else{const _0x3905b6=getLocalKnowledgeBases(),_0x1d3e32=getGlobalKnowledgeBases(),_0x2bda21=Object[_0x170b01(0x257)](_0x3905b6)[_0x170b01(0x1cf)](_0x38bada=>_0x38bada[_0x170b01(0x228)]),_0xe9c8fc=Object[_0x170b01(0x257)](_0x1d3e32)[_0x170b01(0x1cf)](_0x522f2b=>_0x522f2b[_0x170b01(0x228)]);_0x2cf293=[..._0x2bda21['map'](_0x1f4684=>({..._0x1f4684,'scope':'local'})),..._0xe9c8fc[_0x170b01(0x18a)](_0x544079=>({..._0x544079,'scope':'global'}))];}if(_0x2cf293[_0x170b01(0x264)]===0x0&&!includeBases){console['log'](_0x170b01(0x217));const _0x524db3=await _0x23dff3();if(!_0x524db3)return[];_0x2cf293[_0x170b01(0x22a)]({'id':null,'name':_0x170b01(0x246),'scope':'legacy'});}if(_0x2cf293['length']===0x0)return console[_0x170b01(0x232)]('[翰林院-日志]\x20没有可供查询的知识库,查询中止。'),[];const _0x5696c1=(await getEmbeddings([_0x5b0b6d]))[0x0];if(!_0x5696c1)throw new Error('未能生成查询向量。');let _0x9644f=[];const _0x22a314=_0x2cf293['map'](_0x4e0a58=>{const _0x20aeeb=_0x170b01;let _0x5570dc;if(_0x4e0a58[_0x20aeeb(0x1a9)]===_0x20aeeb(0x25b))_0x5570dc=_0x23dff3();else{const _0x1c3540=_0x4e0a58[_0x20aeeb(0x1a9)]===_0x20aeeb(0x224)?_0x4e0a58[_0x20aeeb(0x281)]||GLOBAL_SCOPE_ID:_0x8a8278;_0x5570dc=Promise['resolve'](_0x1c3540+'_'+_0x4e0a58['id']);}return _0x5570dc[_0x20aeeb(0x1cb)](_0x49584e=>{const _0x337bb4=_0x20aeeb;if(!_0x49584e)return[];console[_0x337bb4(0x232)](_0x337bb4(0x1d8)+_0x4e0a58['name']+'\x20(ID:\x20'+_0x49584e+')');const _0x33a6f1={'collectionId':_0x49584e,'searchText':_0x5b0b6d,'topK':settings[_0x337bb4(0x22c)][_0x337bb4(0x194)],'threshold':settings[_0x337bb4(0x22c)][_0x337bb4(0x23b)],'source':_0x337bb4(0x207),'embeddings':{[_0x5b0b6d]:_0x5696c1}};return fetch(_0x337bb4(0x251),{'method':_0x337bb4(0x196),'headers':context[_0x337bb4(0x1ab)](),'body':JSON[_0x337bb4(0x285)](_0x33a6f1)})[_0x337bb4(0x1cb)](async _0x44b22c=>{const _0x3fa4e9=_0x337bb4;if(!_0x44b22c['ok']){const _0x448b70=await _0x44b22c[_0x3fa4e9(0x265)]();return console[_0x3fa4e9(0x18e)](_0x3fa4e9(0x236)+_0x49584e+'\x20失败:',_0x448b70),[];}const _0x1a89e6=await _0x44b22c['json']();let _0x32ebd7=[];if(Array['isArray'](_0x1a89e6))_0x32ebd7=_0x1a89e6;else{if(_0x1a89e6&&_0x1a89e6[_0x3fa4e9(0x223)]&&Array[_0x3fa4e9(0x248)](_0x1a89e6[_0x3fa4e9(0x223)]))_0x32ebd7=_0x1a89e6[_0x3fa4e9(0x223)];else{if(_0x1a89e6&&_0x1a89e6['results']&&Array[_0x3fa4e9(0x248)](_0x1a89e6[_0x3fa4e9(0x250)]))_0x32ebd7=_0x1a89e6['results'];else _0x1a89e6&&_0x1a89e6[_0x3fa4e9(0x197)]&&Array[_0x3fa4e9(0x248)](_0x1a89e6[_0x3fa4e9(0x197)])&&(_0x32ebd7=_0x1a89e6[_0x3fa4e9(0x197)]);}}const _0xd2bf7=_0x32ebd7[_0x3fa4e9(0x18a)](_0x46dc1f=>{const _0x3d832b=_0x3fa4e9;if(!_0x46dc1f||typeof _0x46dc1f[_0x3d832b(0x265)]!==_0x3d832b(0x1f0))return null;const _0x14fd9d={'source':_0x3d832b(0x277),'sourceName':'未知'},_0x460a1a=_0x46dc1f[_0x3d832b(0x265)]['match'](/^<([^>]+)>/),_0x3c6968=_0x460a1a?_0x460a1a[0x1]:'';switch(_0x3c6968){case _0x3d832b(0x17e):_0x14fd9d[_0x3d832b(0x1cd)]='chat_history';const _0x2c7823=_0x46dc1f['text'][_0x3d832b(0x238)](/楼层:\s*#(\d+),\s*第(\d+)部分/);_0x2c7823&&_0x2c7823[0x1]&&_0x2c7823[0x2]&&(_0x14fd9d[_0x3d832b(0x296)]=parseInt(_0x2c7823[0x1],0xa),_0x14fd9d[_0x3d832b(0x278)]=parseInt(_0x2c7823[0x2],0xa),_0x14fd9d['sourceName']='聊天记录\x20#'+_0x14fd9d[_0x3d832b(0x296)]);break;case'世界书':_0x14fd9d[_0x3d832b(0x1cd)]=_0x3d832b(0x231);const _0x1dfae1=_0x46dc1f[_0x3d832b(0x265)][_0x3d832b(0x238)](/\[来源:\s*([^,]+),\s*条目:\s*([^,]+),\s*第(\d+)部分\]/);_0x1dfae1&&_0x1dfae1[0x1]&&_0x1dfae1[0x2]&&_0x1dfae1[0x3]&&(_0x14fd9d[_0x3d832b(0x20d)]=_0x1dfae1[0x1][_0x3d832b(0x28c)](),_0x14fd9d[_0x3d832b(0x1f2)]=_0x1dfae1[0x2][_0x3d832b(0x28c)](),_0x14fd9d[_0x3d832b(0x278)]=parseInt(_0x1dfae1[0x3],0xa),_0x14fd9d[_0x3d832b(0x1d0)]=_0x14fd9d['bookName']+':\x20'+_0x14fd9d['entryName']);break;case _0x3d832b(0x210):_0x14fd9d[_0x3d832b(0x1cd)]='manual';const _0x4f75ab=_0x46dc1f[_0x3d832b(0x265)]['match'](/\[来源:\s*([^,]+),.*第(\d+)部分\]/);_0x4f75ab&&_0x4f75ab[0x1]&&_0x4f75ab[0x2]&&(_0x14fd9d[_0x3d832b(0x1d0)]=_0x4f75ab[0x1][_0x3d832b(0x28c)](),_0x14fd9d['part']=parseInt(_0x4f75ab[0x2],0xa));break;case'小说录入':_0x14fd9d[_0x3d832b(0x1cd)]=_0x3d832b(0x1d9);const _0x3a1bea=_0x46dc1f[_0x3d832b(0x265)][_0x3d832b(0x238)](/\[来源:\s*([^,]+),\s*([^,]+),\s*([^,]+),\s*([^\]]+)\]/);_0x3a1bea&&(_0x14fd9d[_0x3d832b(0x1d0)]=_0x3a1bea[0x1][_0x3d832b(0x28c)](),_0x14fd9d['volume']=_0x3a1bea[0x2][_0x3d832b(0x28c)](),_0x14fd9d[_0x3d832b(0x19f)]=_0x3a1bea[0x3][_0x3d832b(0x28c)](),_0x14fd9d['section']=_0x3a1bea[0x4][_0x3d832b(0x28c)]());break;}return{..._0x46dc1f,'score':_0x46dc1f['score']||0x1,'metadata':_0x14fd9d};})[_0x3fa4e9(0x1cf)](Boolean);return console[_0x3fa4e9(0x232)]('[翰林院-V13\x20修复]\x20重建元数据后,知识库\x20'+_0x4e0a58[_0x3fa4e9(0x1f4)]+_0x3fa4e9(0x1e6)+_0xd2bf7[_0x3fa4e9(0x264)]+_0x3fa4e9(0x297)),_0xd2bf7;})[_0x337bb4(0x20e)](_0x203e08=>{const _0x296a67=_0x337bb4;return console[_0x296a67(0x18e)](_0x296a67(0x236)+_0x49584e+_0x296a67(0x262),_0x203e08),[];});});}),_0x58976c=await Promise['all'](_0x22a314);_0x9644f=_0x58976c[_0x170b01(0x235)](),console[_0x170b01(0x232)](_0x170b01(0x287)+_0x9644f['length']+'\x20条初步结果。');const _0x4fbdd5=[],_0x4a603e=new Set();for(const _0x466c38 of _0x9644f){if(_0x466c38&&typeof _0x466c38==='object'&&_0x466c38[_0x170b01(0x265)]&&typeof _0x466c38[_0x170b01(0x265)]===_0x170b01(0x1f0)){const _0x24e5df=_0x466c38[_0x170b01(0x265)]['trim']();_0x24e5df[_0x170b01(0x264)]>0x0&&!_0x4a603e[_0x170b01(0x187)](_0x24e5df)&&(_0x4a603e[_0x170b01(0x254)](_0x24e5df),_0x4fbdd5[_0x170b01(0x22a)](_0x466c38));}}console[_0x170b01(0x232)]('[翰林院-日志]\x20去重后剩余\x20'+_0x4fbdd5[_0x170b01(0x264)]+'\x20条结果。'),_0x4fbdd5['sort']((_0xca3a1d,_0x5262c5)=>(_0x5262c5[_0x170b01(0x192)]||0x0)-(_0xca3a1d['score']||0x0));const _0x3c8ac3=[..._0x4fbdd5];return console[_0x170b01(0x232)](_0x170b01(0x183)+_0x3c8ac3[_0x170b01(0x264)]),console[_0x170b01(0x232)](_0x170b01(0x26b),JSON[_0x170b01(0x285)](_0x3c8ac3['slice'](0x0,0x1),null,0x2)),_0x3c8ac3;}async function insertVectors(_0x2393c8,_0x2f9422=null,_0x279c29){const _0x46de9c=_0x58d31a;if(!_0x279c29)throw new Error(_0x46de9c(0x258));if(_0x2393c8['length']===0x0)return{'success':!![],'count':0x0};const _0x5476c6=_0x2393c8[_0x46de9c(0x18a)]((_0x37c82c,_0x4d68ed)=>({'hash':generateHash(_0x37c82c['text']+Date[_0x46de9c(0x1b3)]()+_0x4d68ed),'text':_0x37c82c[_0x46de9c(0x265)],'metadata':_0x37c82c[_0x46de9c(0x223)]||{'source':'unknown','timestamp':new Date()[_0x46de9c(0x280)]()}})),_0x559ae3=_0x5476c6[_0x46de9c(0x212)]((_0x11507f,_0x278ca8,_0xa75533)=>{const _0x3c5c3d=_0x46de9c;return _0x11507f[_0x278ca8[_0x3c5c3d(0x265)]]=_0x2393c8[_0xa75533][_0x3c5c3d(0x22e)],_0x11507f;},{}),_0x1b0009={'collectionId':_0x279c29,'items':_0x5476c6,'source':'webllm','embeddings':_0x559ae3},_0x2042dc=await fetch(_0x46de9c(0x1b1),{'method':'POST','headers':context[_0x46de9c(0x1ab)](),'body':JSON[_0x46de9c(0x285)](_0x1b0009),'signal':_0x2f9422});if(!_0x2042dc['ok']){const _0xa10c50=await _0x2042dc[_0x46de9c(0x265)]();console[_0x46de9c(0x18e)](_0x46de9c(0x270),_0xa10c50);throw new Error(_0x46de9c(0x203)+_0x2042dc[_0x46de9c(0x286)]+':\x20'+_0xa10c50);}return{'success':!![],'count':_0x5476c6[_0x46de9c(0x264)]};}async function getVectorCount(_0x2924cb=null,_0x15f890=_0x58d31a(0x1d6)){const _0x2e4bdf=_0x58d31a,_0x8516ab=getCharacterStableId();if(_0x2924cb){const _0x4774b3=_0x15f890===_0x2e4bdf(0x224)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x5b5ed1=_0x4774b3[_0x2924cb];if(!_0x5b5ed1)return console['warn'](_0x2e4bdf(0x19b)+_0x15f890+_0x2e4bdf(0x18d)+_0x2924cb+_0x2e4bdf(0x190)),0x0;const _0x57be13=_0x15f890===_0x2e4bdf(0x224)?_0x5b5ed1['owner']||GLOBAL_SCOPE_ID:_0x8516ab,_0xd38398=_0x57be13+'_'+_0x2924cb;return await countVectorsInCollection(_0xd38398);}else{console[_0x2e4bdf(0x232)](_0x2e4bdf(0x1ba));const _0x1a5e58=Object['values'](getLocalKnowledgeBases()),_0x37c711=Object['values'](getGlobalKnowledgeBases()),_0x154ae9=[];_0x1a5e58[_0x2e4bdf(0x1a4)](_0x3eef14=>{const _0x3c9702=_0x2e4bdf,_0x1e13b9=_0x8516ab+'_'+_0x3eef14['id'];_0x154ae9[_0x3c9702(0x22a)](countVectorsInCollection(_0x1e13b9));}),_0x37c711['forEach'](_0x52a073=>{const _0x5edfb8=_0x2e4bdf,_0x7b0c80=_0x52a073[_0x5edfb8(0x281)]||GLOBAL_SCOPE_ID,_0x55ae72=_0x7b0c80+'_'+_0x52a073['id'];_0x154ae9[_0x5edfb8(0x22a)](countVectorsInCollection(_0x55ae72));});const _0x357fd3=await _0x23dff3();_0x154ae9[_0x2e4bdf(0x22a)](countVectorsInCollection(_0x357fd3));const _0x540cf1=await Promise['all'](_0x154ae9),_0x1582a4=_0x540cf1['reduce']((_0x211a7b,_0x2dcdbe)=>_0x211a7b+_0x2dcdbe,0x0);return console[_0x2e4bdf(0x232)]('[翰林院-日志]\x20所有知识库统计完成,总向量数:\x20'+_0x1582a4),_0x1582a4;}}async function countVectorsInCollection(_0x4f6a19){const _0x1a7a8a=_0x58d31a;if(!_0x4f6a19)return 0x0;console[_0x1a7a8a(0x232)](_0x1a7a8a(0x1c9)+_0x4f6a19);const _0x1ba29d={'collectionId':_0x4f6a19,'source':_0x1a7a8a(0x207),'embeddings':{}};try{const _0x32ade5=await fetch(_0x1a7a8a(0x27d),{'method':_0x1a7a8a(0x196),'headers':context['getRequestHeaders'](),'body':JSON[_0x1a7a8a(0x285)](_0x1ba29d)});if(!_0x32ade5['ok']){if(_0x32ade5['status']===0x194)console[_0x1a7a8a(0x232)](_0x1a7a8a(0x1a2)+_0x4f6a19+_0x1a7a8a(0x1c6));else{const _0x1922bd=await _0x32ade5[_0x1a7a8a(0x265)]();console[_0x1a7a8a(0x205)](_0x1a7a8a(0x208)+_0x4f6a19+_0x1a7a8a(0x193)+_0x32ade5[_0x1a7a8a(0x286)]+'):',_0x1922bd);}return 0x0;}const _0x5ad724=await _0x32ade5[_0x1a7a8a(0x1a8)]();let _0x93c1d4=0x0;if(Array[_0x1a7a8a(0x248)](_0x5ad724))_0x93c1d4=_0x5ad724[_0x1a7a8a(0x264)];else _0x5ad724&&_0x5ad724[_0x1a7a8a(0x272)]&&(_0x93c1d4=_0x5ad724[_0x1a7a8a(0x272)][_0x1a7a8a(0x264)]);return _0x93c1d4;}catch(_0x46639a){return console[_0x1a7a8a(0x18e)](_0x1a7a8a(0x195)+_0x4f6a19+_0x1a7a8a(0x262),_0x46639a),0x0;}}async function purgeStorage(_0x2b01f1=null){const _0x5e4e4d=_0x58d31a;console[_0x5e4e4d(0x232)](_0x5e4e4d(0x1d1));const _0x2a268e=_0x2b01f1||await getCollectionId();if(!_0x2a268e)return console['error'](_0x5e4e4d(0x1bb)),toastr[_0x5e4e4d(0x18e)](_0x5e4e4d(0x26d)),![];console[_0x5e4e4d(0x232)](_0x5e4e4d(0x1b5)+_0x2a268e);const _0x379390={'collectionId':_0x2a268e};console[_0x5e4e4d(0x232)](_0x5e4e4d(0x299),JSON[_0x5e4e4d(0x285)](_0x379390,null,0x2));const _0x465409=await fetch('/api/vector/purge',{'method':_0x5e4e4d(0x196),'headers':context['getRequestHeaders'](),'body':JSON[_0x5e4e4d(0x285)](_0x379390)});console[_0x5e4e4d(0x232)](_0x5e4e4d(0x1d7)+_0x465409['status']);if(!_0x465409['ok']){const _0x4e8412=await _0x465409[_0x5e4e4d(0x265)]();console[_0x5e4e4d(0x18e)](_0x5e4e4d(0x23e),_0x4e8412);}else console[_0x5e4e4d(0x232)](_0x5e4e4d(0x18f));return _0x465409['ok'];}function getMessagesForCondensation(_0x12fc04=null){const _0x3038cd=_0x58d31a;if(!settings['condensation'][_0x3038cd(0x228)])return showNotification(_0x3038cd(0x260),_0x3038cd(0x293)),[];const {layerStart:_0x2f6bd2,layerEnd:_0x2b07dd}=settings[_0x3038cd(0x24f)],_0x23f94a=_0x12fc04||settings['condensation']['messageTypes'],_0x434730=context[_0x3038cd(0x1c7)]['length'],_0x1c73f3=Math[_0x3038cd(0x291)](0x0,_0x2f6bd2-0x1),_0xefe8c5=_0x2b07dd===0x0||_0x2b07dd>_0x434730?_0x434730:Math[_0x3038cd(0x1b8)](_0x434730,_0x2b07dd),_0x30167b=context['chat'][_0x3038cd(0x20c)](_0x1c73f3,_0xefe8c5);return _0x30167b['filter'](_0x49c70b=>{const _0x16f684=_0x3038cd,_0x35da83=_0x49c70b[_0x16f684(0x298)]===!![],_0x3a346f=_0x49c70b['is_user']===![];if(!_0x49c70b[_0x16f684(0x1be)]||!_0x49c70b[_0x16f684(0x1be)][_0x16f684(0x28c)]())return![];return _0x23f94a[_0x16f684(0x26e)]&&_0x35da83||_0x23f94a['ai']&&_0x3a346f;});}async function processCondensation(_0x6313ab,_0x58a3cc=()=>{},_0x159a26=null){const _0x2f38f4=_0x58d31a;if(!_0x6313ab||_0x6313ab[_0x2f38f4(0x264)]===0x0)return{'success':![],'error':'No\x20messages\x20to\x20process.'};try{let _0x251b5d,_0x311bf2;const _0x433547=getCharacterName()||_0x2f38f4(0x249);if(_0x159a26){const _0x29c59b=_0x159a26[_0x2f38f4(0x1a7)]??'?',_0x409d9d=_0x159a26['end']===0x0?'末':_0x159a26[_0x2f38f4(0x186)]??'?';_0x251b5d=_0x433547+':\x20'+_0x29c59b+'楼-'+_0x409d9d+'楼';}else{const _0x791d6d=new Date()[_0x2f38f4(0x1ee)](_0x2f38f4(0x241),{'hour12':![]});_0x251b5d=_0x2f38f4(0x1e5)+_0x791d6d;}const _0x1cb289=Object[_0x2f38f4(0x257)](getLocalKnowledgeBases()),_0x59c472=_0x1cb289[_0x2f38f4(0x230)](_0x54c959=>_0x54c959[_0x2f38f4(0x1f4)]===_0x251b5d);if(_0x59c472)_0x311bf2=_0x59c472['id'],_0x58a3cc('[翰林院-核心]\x20检测到同名知识库\x20\x22'+_0x251b5d+_0x2f38f4(0x19e),_0x2f38f4(0x1c4));else{_0x58a3cc(_0x2f38f4(0x25c)+_0x251b5d+_0x2f38f4(0x1c1),'info');const _0x1a1f76=addKnowledgeBase(_0x251b5d,'chat_history');_0x311bf2=_0x1a1f76['id'];}const _0x11a666=getCharacterStableId(),_0x501776=_0x11a666+'_'+_0x311bf2;_0x58a3cc(_0x2f38f4(0x294)+_0x251b5d+_0x2f38f4(0x1bd)+_0x501776+')',_0x2f38f4(0x27c));const _0x55e7ae=[],_0x581bae=context['chat'];for(const _0x5a16c9 of _0x6313ab){const _0x372902=(_0x5a16c9['mes']||'')[_0x2f38f4(0x237)](/<[^>]*>/g,'')[_0x2f38f4(0x28c)]();if(_0x372902['length']===0x0)continue;let _0x38cc9c;if(_0x5a16c9[_0x2f38f4(0x296)]!==undefined&&_0x5a16c9[_0x2f38f4(0x296)]!==null)_0x38cc9c=_0x5a16c9[_0x2f38f4(0x296)];else{const _0x75c47=_0x581bae[_0x2f38f4(0x274)](_0x3cbc5d=>_0x3cbc5d===_0x5a16c9);_0x38cc9c=_0x75c47!==-0x1?_0x75c47+0x1:-0x1;}const _0x388638=new Date(_0x5a16c9['send_date']),_0x2afbc5=isNaN(_0x388638[_0x2f38f4(0x20f)]())?new Date()['toISOString']():_0x388638[_0x2f38f4(0x280)](),_0xe17f52=splitIntoChunks(_0x372902,_0x2f38f4(0x1dd),{'floor':_0x38cc9c,'is_user':_0x5a16c9[_0x2f38f4(0x298)],'timestamp':_0x2afbc5});_0x55e7ae[_0x2f38f4(0x22a)](..._0xe17f52);}if(_0x55e7ae[_0x2f38f4(0x264)]===0x0)return{'success':!![],'count':0x0};_0x58a3cc(_0x2f38f4(0x184)+_0x6313ab[_0x2f38f4(0x264)]+_0x2f38f4(0x1c2)+_0x55e7ae[_0x2f38f4(0x264)]+_0x2f38f4(0x1e8),_0x2f38f4(0x1c4));const _0x5f45d6=settings[_0x2f38f4(0x219)][_0x2f38f4(0x1e9)]||0x5;let _0x33fd55=0x0;for(let _0x2766ea=0x0;_0x2766ea<_0x55e7ae[_0x2f38f4(0x264)];_0x2766ea+=_0x5f45d6){const _0x229b3f=_0x55e7ae[_0x2f38f4(0x20c)](_0x2766ea,_0x2766ea+_0x5f45d6),_0x434277=_0x229b3f[_0x2f38f4(0x18a)](_0x1e97bc=>_0x1e97bc[_0x2f38f4(0x265)]),_0x5ca940=await getEmbeddings(_0x434277);if(_0x229b3f[_0x2f38f4(0x264)]!==_0x5ca940[_0x2f38f4(0x264)])throw new Error('文本块和向量数量不匹配');const _0x438587=_0x229b3f[_0x2f38f4(0x18a)]((_0x3d9f58,_0x3709e6)=>({..._0x3d9f58,'vector':_0x5ca940[_0x3709e6]}));await insertVectors(_0x438587,null,_0x501776),_0x33fd55+=_0x229b3f[_0x2f38f4(0x264)];}if(_0x159a26){const _0x38e75e=_0x159a26['end']===0x0?context[_0x2f38f4(0x1c7)]['length']:_0x159a26[_0x2f38f4(0x186)],_0x1624d6=getCharacterStableId();!settings['condensationHistory'][_0x1624d6]&&(settings[_0x2f38f4(0x20a)][_0x1624d6]={}),settings[_0x2f38f4(0x20a)][_0x1624d6][_0x501776]={'start':_0x159a26[_0x2f38f4(0x1a7)],'end':_0x38e75e,'timestamp':new Date()['toISOString']()},saveSettings(),_0x58a3cc('[翰林院-核心]\x20已为宝库\x20'+_0x501776+_0x2f38f4(0x288)+_0x159a26[_0x2f38f4(0x1a7)]+'-'+_0x38e75e,'info');}_0x58a3cc('[翰林院-核心]\x20聊天记录凝识完成,成功插入\x20'+_0x33fd55+_0x2f38f4(0x214),_0x2f38f4(0x27c));const _0x45ae17=_0x6313ab[_0x2f38f4(0x18a)](_0x299cf0=>{const _0x2ac38b=_0x2f38f4,_0x4b71b5=_0x581bae[_0x2ac38b(0x274)](_0x424a7a=>_0x424a7a===_0x299cf0),_0x35e87a=_0x4b71b5!==-0x1?_0x4b71b5+0x1:-0x1,_0x1993de=_0x299cf0[_0x2ac38b(0x298)]?'用户':getCharacterName()||'AI';return'['+_0x1993de+'\x20-\x20楼层\x20#'+_0x35e87a+']\x20的消息已成功凝识。';});return{'success':!![],'count':_0x33fd55,'messages':_0x45ae17};}catch(_0x137f0a){return console[_0x2f38f4(0x18e)]('[翰林院-核心]\x20processCondensation\x20失败:',_0x137f0a),_0x58a3cc(_0x2f38f4(0x247)+_0x137f0a['message'],_0x2f38f4(0x18e)),{'success':![],'error':_0x137f0a[_0x2f38f4(0x17c)]};}}async function rerankResults(_0x58e66b,_0x30b6fa,_0x3ee856){const _0x436bf6=_0x58d31a;let _0x5de8f4=_0x58e66b,_0x3f6895=![];if(_0x3ee856[_0x436bf6(0x1f7)][_0x436bf6(0x228)]&&_0x58e66b[_0x436bf6(0x264)]>0x0){console['log']('[翰林院-Rerank]\x20开始外部API重排序...');try{const _0x4735b4=_0x58e66b[_0x436bf6(0x18a)](_0x27254b=>_0x27254b[_0x436bf6(0x265)]),_0x18e43e=await executeRerank(_0x30b6fa,_0x4735b4,_0x3ee856[_0x436bf6(0x1f7)]),_0x125b00=_0x58e66b['map']((_0x533aea,_0x2afe5b)=>({..._0x533aea,'original_index':_0x2afe5b}));_0x5de8f4=_0x125b00['map'](_0x45c143=>{const _0x451db7=_0x436bf6,_0x5449f3=_0x18e43e[_0x451db7(0x250)][_0x451db7(0x230)](_0xc9db83=>_0xc9db83[_0x451db7(0x1f9)]===_0x45c143[_0x451db7(0x211)]),_0x27ec4b=_0x5449f3?_0x5449f3[_0x451db7(0x1dc)]:0x0;return{..._0x45c143,'rerank_score':_0x27ec4b};}),_0x3f6895=!![];}catch(_0x39e614){console['error'](_0x436bf6(0x259),_0x39e614);if(_0x3ee856[_0x436bf6(0x1f7)][_0x436bf6(0x263)])showNotification(_0x436bf6(0x1a5)+_0x39e614[_0x436bf6(0x17c)],'error');_0x5de8f4['forEach'](_0x40252f=>_0x40252f[_0x436bf6(0x284)]=0x0);}}else _0x5de8f4['forEach'](_0x14c6fb=>_0x14c6fb[_0x436bf6(0x284)]=0x0);console['log']('[翰林院-Rerank]\x20开始元数据加权最终排序...');const _0x1b8db9=context[_0x436bf6(0x1c7)][_0x436bf6(0x264)],_0x456e8b=_0x3ee856[_0x436bf6(0x1f7)]['hybrid_alpha'],_0x232b10=_0x5de8f4['map'](_0x2d0371=>{const _0x558802=_0x436bf6;let _0x23baec=0x1;const _0x16c444=_0x2d0371[_0x558802(0x223)]||{};switch(_0x16c444[_0x558802(0x1cd)]){case _0x558802(0x231):_0x23baec*=1.2;break;case'manual':_0x23baec*=1.1;break;case _0x558802(0x1dd):if(_0x16c444[_0x558802(0x296)]&&_0x1b8db9>0x0){const _0x1f6ec8=_0x16c444[_0x558802(0x296)]/_0x1b8db9;_0x23baec*=0x1+_0x1f6ec8;}break;}const _0x271b5d=_0x2d0371[_0x558802(0x284)]*_0x456e8b+(_0x2d0371[_0x558802(0x192)]||0x0)*(0x1-_0x456e8b),_0x2b59d4=_0x271b5d*_0x23baec;return{'text':_0x2d0371['text'],'score':_0x2d0371[_0x558802(0x192)],'rerank_score':_0x2d0371[_0x558802(0x284)],'final_score':_0x2b59d4,'metadata':_0x2d0371['metadata']};});_0x232b10['sort']((_0x30f276,_0x341703)=>(_0x341703[_0x436bf6(0x267)]||0x0)-(_0x30f276[_0x436bf6(0x267)]||0x0)),console[_0x436bf6(0x232)](_0x436bf6(0x202));let _0x4327bd=_0x232b10;return _0x3ee856['rerank']['superSortEnabled']&&(_0x4327bd=superSort(_0x232b10)),{'results':_0x4327bd[_0x436bf6(0x20c)](0x0,_0x3ee856[_0x436bf6(0x1f7)]['top_n']),'reranked':_0x3f6895};}async function rearrangeChat(_0x45c500,_0xf9b68d,_0x241a53,_0x164386){const _0x4d59e1=_0x58d31a,_0x248b6a={'novel':_0x4d59e1(0x201),'chat_history':_0x4d59e1(0x1aa),'lorebook':_0x4d59e1(0x181),'manual':_0x4d59e1(0x215)};Object['values'](_0x248b6a)[_0x4d59e1(0x1a4)](_0x5bd74e=>setExtensionPrompt(_0x5bd74e,'',0x0,0x0,![],0x0));if(_0x164386===_0x4d59e1(0x1fa)||!settings[_0x4d59e1(0x219)]['enabled'])return;const _0x581fc3=_0x45c500[_0x4d59e1(0x20c)](-settings[_0x4d59e1(0x22c)][_0x4d59e1(0x282)]);if(_0x581fc3['length']===0x0)return;const _0x4d242c=_0x581fc3[_0x4d59e1(0x18a)](_0x26a0f4=>_0x26a0f4['mes'])['join']('\x20')['replace'](/<[^>]*>/g,'')[_0x4d59e1(0x28c)]();if(!_0x4d242c)return;try{const _0x2fabc2=0x2,_0x5006dd=settings[_0x4d59e1(0x275)]||0x1;let _0x4fd481=![];if(_0x5006dd<_0x2fabc2){console[_0x4d59e1(0x232)](_0x4d59e1(0x1de)+_0x5006dd+'),开始强制重分类所有知识库...'),toastr[_0x4d59e1(0x1c4)](_0x4d59e1(0x18b),_0x4d59e1(0x27a));const _0xd5363c=getKnowledgeBases();for(const _0x2e1271 of Object[_0x4d59e1(0x257)](_0xd5363c)){const _0x5d4d7e=_0x2e1271[_0x4d59e1(0x1f4)],_0x238567=_0x2e1271[_0x4d59e1(0x1cd)];if(_0x5d4d7e[_0x4d59e1(0x1f8)](_0x4d59e1(0x1ac)))_0x2e1271[_0x4d59e1(0x1cd)]=_0x4d59e1(0x242);else{if(_0x5d4d7e[_0x4d59e1(0x1f8)](_0x4d59e1(0x290)))_0x2e1271[_0x4d59e1(0x1cd)]=_0x4d59e1(0x1d9);else _0x5d4d7e[_0x4d59e1(0x28f)]('楼-')&&_0x5d4d7e[_0x4d59e1(0x28f)]('楼')&&_0x5d4d7e[_0x4d59e1(0x28f)](':')?_0x2e1271['source']=_0x4d59e1(0x1dd):_0x2e1271[_0x4d59e1(0x1cd)]=_0x4d59e1(0x231);}_0x238567!==_0x2e1271['source']&&console[_0x4d59e1(0x232)](_0x4d59e1(0x28b)+_0x5d4d7e+_0x4d59e1(0x24c)+(_0x238567||'无')+_0x4d59e1(0x27e)+_0x2e1271['source']+']');}settings['settingsVersion']=_0x2fabc2,_0x4fd481=!![];}_0x4fd481&&(console['log']('[翰林院-户口普查]\x20普查完成,正在保存更新后的户籍...'),saveSettings());let _0x4aa626=[];const _0x4bef35=settings['rerank'][_0x4d59e1(0x25d)];if(_0x4bef35[_0x4d59e1(0x228)]){console[_0x4d59e1(0x232)](_0x4d59e1(0x1df));const _0x25026a=Object[_0x4d59e1(0x257)](getKnowledgeBases())[_0x4d59e1(0x1cf)](_0x854ff7=>_0x854ff7[_0x4d59e1(0x228)]),_0xdfac65=Object[_0x4d59e1(0x1a1)](_0x4bef35['sources'])[_0x4d59e1(0x1cf)](_0x575633=>_0x4bef35[_0x4d59e1(0x1f3)][_0x575633]&&_0x4bef35[_0x4d59e1(0x1f3)][_0x575633]['enabled']),_0x1e1416=[];let _0xc07318=[..._0x25026a];for(const _0x13b55f of _0xdfac65){const _0x45e21b=_0x4bef35['sources'][_0x13b55f],_0x505b8e=_0xc07318[_0x4d59e1(0x1cf)](_0x2bb751=>_0x2bb751[_0x4d59e1(0x1cd)]===_0x13b55f);_0xc07318=_0xc07318[_0x4d59e1(0x1cf)](_0x2b291b=>!_0x505b8e['includes'](_0x2b291b));if(_0x505b8e[_0x4d59e1(0x264)]>0x0){console[_0x4d59e1(0x232)](_0x4d59e1(0x21e)+_0x13b55f+'\x20('+_0x505b8e[_0x4d59e1(0x264)]+_0x4d59e1(0x222));const _0x3b3449=queryVectors(_0x4d242c,{'includeBases':_0x505b8e})[_0x4d59e1(0x1cb)](_0x1dc450=>{const _0x4c5aee=_0x4d59e1;console[_0x4c5aee(0x232)](_0x4c5aee(0x1ec)+_0x13b55f+'\x20返回\x20'+_0x1dc450['length']+_0x4c5aee(0x297));let _0x53d206=_0x1dc450['filter'](_0x39ff3d=>_0x39ff3d[_0x4c5aee(0x223)]?.['source']===_0x13b55f);return _0x53d206=_0x53d206[_0x4c5aee(0x20c)](0x0,_0x45e21b['count']),console[_0x4c5aee(0x232)](_0x4c5aee(0x1b2)+_0x13b55f+_0x4c5aee(0x255)+_0x53d206[_0x4c5aee(0x264)]+_0x4c5aee(0x297)),settings[_0x4c5aee(0x1f7)][_0x4c5aee(0x200)]&&(_0x53d206=superSort(_0x53d206)),_0x53d206;});_0x1e1416['push'](_0x3b3449);}}const _0x2f9ee9=_0xc07318;if(_0x2f9ee9[_0x4d59e1(0x264)]>0x0){console['log'](_0x4d59e1(0x21c)+_0x2f9ee9[_0x4d59e1(0x264)]+'个库)');const _0x113620=queryVectors(_0x4d242c,{'includeBases':_0x2f9ee9})[_0x4d59e1(0x1cb)](async _0x41dcf5=>{const _0xdb6d46=_0x4d59e1;console[_0xdb6d46(0x232)](_0xdb6d46(0x276)+_0x41dcf5[_0xdb6d46(0x264)]+_0xdb6d46(0x297)),console[_0xdb6d46(0x232)]('[翰林院]\x20开始处理常规池...');const _0x215a98=await rerankResults(_0x41dcf5,_0x4d242c,settings),_0x18e181=_0x215a98[_0xdb6d46(0x250)];return console['log'](_0xdb6d46(0x1ca)+(_0x18e181||[])[_0xdb6d46(0x264)]+_0xdb6d46(0x297)),_0x215a98[_0xdb6d46(0x1b7)]&&settings['rerank'][_0xdb6d46(0x263)]&&showNotification(_0xdb6d46(0x243),_0xdb6d46(0x27c)),_0x18e181;});_0x1e1416[_0x4d59e1(0x22a)](_0x113620);}const _0x176c00=await Promise['all'](_0x1e1416);_0x4aa626=_0x176c00[_0x4d59e1(0x235)]();}else{console['log']('[翰林院]\x20进入传统处理流程...');const _0x2e29c9=await queryVectors(_0x4d242c),_0x14465b=await rerankResults(_0x2e29c9,_0x4d242c,settings);_0x4aa626=_0x14465b['results'],_0x14465b['reranked']&&settings[_0x4d59e1(0x1f7)][_0x4d59e1(0x263)]&&showNotification(_0x4d59e1(0x188),'success');}if(!_0x4aa626||_0x4aa626[_0x4d59e1(0x264)]===0x0){console[_0x4d59e1(0x232)](_0x4d59e1(0x1ae));return;}console['log'](_0x4d59e1(0x268)+_0x4aa626[_0x4d59e1(0x264)]+_0x4d59e1(0x297));const _0x208924={'novel':[],'chat_history':[],'lorebook':[],'manual':[]};_0x4aa626[_0x4d59e1(0x1a4)](_0x2a0be3=>{const _0x167af7=_0x4d59e1,_0x360970=_0x2a0be3[_0x167af7(0x223)]?.[_0x167af7(0x1cd)];_0x360970&&_0x208924[_0x167af7(0x1af)](_0x360970)&&_0x208924[_0x360970][_0x167af7(0x22a)](_0x2a0be3);});for(const _0x354748 in _0x208924){const _0x30aea7=_0x208924[_0x354748];if(_0x30aea7[_0x4d59e1(0x264)]===0x0)continue;const _0x58761d=settings[_0x4d59e1(0x19d)+_0x354748[_0x4d59e1(0x237)](_0x4d59e1(0x1ea),'')];if(!_0x58761d){console[_0x4d59e1(0x205)]('[翰林院]\x20未找到来源\x20\x27'+_0x354748+_0x4d59e1(0x1fe));continue;}const _0x82bdb0=_0x30aea7[_0x4d59e1(0x18a)](_0x184620=>_0x184620[_0x4d59e1(0x265)])['join']('\x0a\x0a'),_0x3ad659='{{'+_0x354748[_0x4d59e1(0x237)]('_history','')+_0x4d59e1(0x218);let _0x429dcd=_0x58761d['template'][_0x4d59e1(0x237)](_0x3ad659,_0x82bdb0);_0x429dcd[_0x4d59e1(0x28c)]()&&(_0x429dcd='%%'+_0x248b6a[_0x354748]+'%%'+_0x429dcd),setExtensionPrompt(_0x248b6a[_0x354748],_0x429dcd,_0x58761d[_0x4d59e1(0x1c5)],_0x58761d[_0x4d59e1(0x1e7)],![],_0x58761d[_0x4d59e1(0x1ed)]),console['log']('[翰林院]\x20已为来源\x20\x27'+_0x354748+_0x4d59e1(0x256)+_0x30aea7['length']+'\x20条内容。');}}catch(_0x160d92){console[_0x4d59e1(0x18e)]('[翰林院]\x20检索或注入时发生错误:',_0x160d92);if(settings[_0x4d59e1(0x219)]['notify'])showNotification(_0x4d59e1(0x1fb)+_0x160d92[_0x4d59e1(0x17c)],_0x4d59e1(0x18e));}}async function moveKnowledgeBase(_0x4df7d9,_0x47d52d){const _0x32baae=_0x58d31a,_0x2700ee=_0x47d52d===_0x32baae(0x224)?_0x32baae(0x1d6):_0x32baae(0x224),_0x312456=getCharacterStableId();if(!_0x312456&&_0x2700ee===_0x32baae(0x1d6)){toastr[_0x32baae(0x18e)](_0x32baae(0x21f));return;}const _0x1c73bf=_0x47d52d==='global'?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x73f86a=_0x2700ee===_0x32baae(0x224)?getGlobalKnowledgeBases():getLocalKnowledgeBases(),_0x5a6198=_0x1c73bf[_0x4df7d9];if(!_0x5a6198){const _0x41e453=_0x32baae(0x283)+_0x47d52d+_0x32baae(0x18d)+_0x4df7d9+_0x32baae(0x190);console['error'](_0x32baae(0x1fd)+_0x41e453),toastr[_0x32baae(0x18e)](_0x32baae(0x266));return;}_0x47d52d===_0x32baae(0x1d6)&&_0x2700ee==='global'&&!_0x5a6198['owner']&&(console[_0x32baae(0x232)](_0x32baae(0x24a)+_0x4df7d9+'\x20补充所有者ID:\x20'+_0x312456),_0x5a6198[_0x32baae(0x281)]=_0x312456);delete _0x1c73bf[_0x4df7d9],_0x73f86a[_0x4df7d9]=_0x5a6198,saveSettings();const _0x1fe0d9='知识库【'+_0x5a6198[_0x32baae(0x1f4)]+_0x32baae(0x26a)+(_0x2700ee===_0x32baae(0x224)?'全局':'局部')+'。';console[_0x32baae(0x232)](_0x32baae(0x1fd)+_0x1fe0d9);}async function getAllVectorsFromCollection(_0x5df398){const _0x40b2b8=_0x58d31a,_0x6a88f9='*',_0x54f283={'collectionId':_0x5df398,'searchText':_0x6a88f9,'topK':0x2710,'threshold':0x0,'source':_0x40b2b8(0x207),'embeddings':{}},_0xb12183=(await getEmbeddings([_0x6a88f9]))[0x0];_0x54f283['embeddings']={[_0x6a88f9]:_0xb12183};const _0x5c9147=await fetch('/api/vector/query',{'method':_0x40b2b8(0x196),'headers':context[_0x40b2b8(0x1ab)](),'body':JSON['stringify'](_0x54f283)});if(!_0x5c9147['ok']){if(_0x5c9147[_0x40b2b8(0x286)]===0x194)return console[_0x40b2b8(0x232)](_0x40b2b8(0x25f)+_0x5df398+_0x40b2b8(0x1fc)),[];const _0x435b36=await _0x5c9147[_0x40b2b8(0x265)]();throw new Error(_0x40b2b8(0x1d2)+_0x5df398+_0x40b2b8(0x26c)+_0x435b36);}const _0x5cc50b=await _0x5c9147[_0x40b2b8(0x1a8)]();return _0x5cc50b['metadata']||_0x5cc50b[_0x40b2b8(0x250)]||_0x5cc50b[_0x40b2b8(0x197)]||[];} From 695445b6510643c88fcf9649f6eb8e73fea5dc89 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 12 Oct 2025 15:56:52 +0800 Subject: [PATCH 09/29] Update summarizer.js --- core/summarizer.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/summarizer.js b/core/summarizer.js index f4a2118..6d95980 100644 --- a/core/summarizer.js +++ b/core/summarizer.js @@ -178,6 +178,9 @@ export async function processOptimization(latestMessage, previousMessages) { optimizedContent: finalMessage, }; + if (settings.showOptimizationToast) { + toastr.success("正文优化成功!", "Amily2号"); + } console.timeEnd("优化任务总耗时"); console.groupEnd(); From 11c3b46ebbf82b81fa38f5fe64835d8cc8eed70a Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 12 Oct 2025 15:57:16 +0800 Subject: [PATCH 10/29] Update historiographer.js --- core/historiographer.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/historiographer.js b/core/historiographer.js index 2e3ade4..ecd44a8 100644 --- a/core/historiographer.js +++ b/core/historiographer.js @@ -302,7 +302,8 @@ async function getSummary(formattedHistory, toastTitle) { toastr.info(`正在为您熔铸对话历史...`, toastTitle); const settings = extension_settings[extensionName]; const presetPrompts = await getPresetPrompts('small_summary'); - + + // 获取混合排序 let mixedOrder; try { const savedOrder = localStorage.getItem('amily2_prompt_presets_v2_mixed_order'); @@ -317,16 +318,19 @@ async function getSummary(formattedHistory, toastTitle) { const messages = [ { role: 'system', content: generateRandomSeed() } ]; - - let promptCounter = 0; + + // 根据混合排序添加提示词 + let promptCounter = 0; // 用于跟踪已处理的提示词数量 for (const item of order) { if (item.type === 'prompt') { + // 处理普通提示词 - getPresetPrompts已经按照mixedOrder排序,直接按顺序使用 if (presetPrompts && presetPrompts[promptCounter]) { messages.push(presetPrompts[promptCounter]); - promptCounter++; + promptCounter++; // 递增计数器 } } else if (item.type === 'conditional') { + // 处理条件块 switch (item.id) { case 'jailbreakPrompt': if (settings.historiographySmallJailbreakPrompt) { From 9165985062b57c0f43025f3698ec546d560f82bd Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 12 Oct 2025 15:57:51 +0800 Subject: [PATCH 11/29] Update lore.js From 62c9ec69df27b67aebf3ea20fa3e200eb9ebe952 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 12 Oct 2025 15:59:22 +0800 Subject: [PATCH 12/29] Update events.js --- core/events.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/events.js b/core/events.js index 61f7121..6574127 100644 --- a/core/events.js +++ b/core/events.js @@ -83,7 +83,7 @@ export async function onMessageReceived(data) { const tableSystemEnabled = settings.table_system_enabled !== false; await executeAutoHide(); - const isOptimizationEnabled = settings.enabled && settings.optimizationEnabled && settings.apiUrl; + const isOptimizationEnabled = settings.optimizationEnabled && settings.apiUrl; if (isOptimizationEnabled) { if (chat.length >= 2 && chat[chat.length - 2].is_user) { const contextCount = settings.contextMessages || 2; From ec1f3efb3ba803027fcf1837667ea827cd06c2b9 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 12 Oct 2025 16:00:04 +0800 Subject: [PATCH 13/29] Update cwb_index.js --- CharacterWorldBook/cwb_index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CharacterWorldBook/cwb_index.js b/CharacterWorldBook/cwb_index.js index 69a03e6..ed9847c 100644 --- a/CharacterWorldBook/cwb_index.js +++ b/CharacterWorldBook/cwb_index.js @@ -44,6 +44,15 @@ export async function initializeCharacterWorldBook($cwbSettingsPanel) { updateCardUpdateStatusDisplay($cwbSettingsPanel); }); + eventSource.on(event_types.CHARACTER_CHANGED, async () => { + console.log('[CWB] Detected character change. Resetting state and updating UI.'); + setTimeout(async () => { + const newChatName = await getLatestChatName(); + await resetScriptStateForNewChat($cwbSettingsPanel, newChatName); + updateCardUpdateStatusDisplay($cwbSettingsPanel); + }, 150); + }); + console.log('[CWB] Character World Book feature initialized successfully.'); } catch (error) { From dff88eb8ce22d32956bc4a4f8d8554b0f7732a52 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 12 Oct 2025 16:00:35 +0800 Subject: [PATCH 14/29] Update cwb_core.js --- CharacterWorldBook/src/cwb_core.js | 50 ++++++++++++++++-------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/CharacterWorldBook/src/cwb_core.js b/CharacterWorldBook/src/cwb_core.js index 2cab7de..5380417 100644 --- a/CharacterWorldBook/src/cwb_core.js +++ b/CharacterWorldBook/src/cwb_core.js @@ -7,8 +7,9 @@ import { extractBlocksByTags, applyExclusionRules } from '../../core/utils/rag-t import { getExtensionSettings } from '../../utils/settings.js'; import { getPresetPrompts, getMixedOrder } from '../../PresetSettings/index.js'; import { generateRandomSeed } from '../../core/api.js'; +import { getChatIdentifier } from '../../core/lore.js'; -const { SillyTavern, TavernHelper, jQuery } = window; +const { SillyTavern, TavernHelper, jQuery, characters } = window; let isUpdatingCard = false; let isBatchUpdating = false; @@ -77,31 +78,34 @@ export async function updateCardUpdateStatusDisplay($panel) { } async function loadAllChatMessages($panel) { - logDebug('尝试加载所有聊天消息...'); - if (!TavernHelper || !SillyTavern) { - logError('用于加载消息的API不可用。'); + logDebug('尝试使用 getContext() 加载所有聊天消息...'); + if (!SillyTavern) { + logError('SillyTavern API 不可用。'); state.allChatMessages = []; return; } try { const context = SillyTavern.getContext(); - const chatLength = context?.chat?.length || 0; + const chat = context?.chat || []; - if (chatLength === 0) { + if (chat.length === 0) { logDebug('聊天为空,无需加载消息。'); state.allChatMessages = []; } else { - const lastMessageId = chatLength - 1; - const messagesFromApi = await TavernHelper.getChatMessages(`0-${lastMessageId}`, { include_swipes: false }); - state.allChatMessages = Array.isArray(messagesFromApi) ? messagesFromApi.map((msg, idx) => ({ ...msg, id: idx })) : []; + state.allChatMessages = chat.map((msg, idx) => ({ + ...msg, + message: msg.mes, + id: idx + })); } logDebug(`成功为 ${state.currentChatFileIdentifier} 加载了 ${state.allChatMessages.length} 条消息。`); await updateCardUpdateStatusDisplay($panel); } catch (error) { - logError('获取聊天消息时发生严重错误:', error); + logError('使用 getContext() 获取聊天消息时发生严重错误:', error); + showToastr('error', '获取聊天记录时发生内部错误。'); state.allChatMessages = []; } } @@ -376,21 +380,21 @@ async function triggerAutomaticUpdate($panel) { } export async function getLatestChatName() { - let newChatFileIdentifier = 'unknown_chat_fallback'; - try { - let chatNameFromCommand = await TavernHelper.triggerSlash('/getchatname'); - if (chatNameFromCommand && typeof chatNameFromCommand === 'string' && chatNameFromCommand.trim() && !['null', 'undefined'].includes(chatNameFromCommand.trim())) { - newChatFileIdentifier = cleanChatName(chatNameFromCommand.trim()); - } else { - const contextFallback = SillyTavern.getContext(); - if (contextFallback && contextFallback.chat) { - newChatFileIdentifier = cleanChatName(contextFallback.chat); - } + let attempts = 0; + const maxAttempts = 50; + const interval = 100; + + while (attempts < maxAttempts) { + const context = getContext(); + if (context && context.chatId) { + return context.chatId; } - } catch (error) { - logError('获取最新聊天名称时出错:', error); + await new Promise((resolve) => setTimeout(resolve, interval)); + attempts++; } - return newChatFileIdentifier; + + logError("[CWB] 长时间等待后,仍无法确定聊天ID。"); + return "unknown_chat_timeout"; } export async function handleMessageReceived($panel) { From 850968520bea075dcb34b550039f9c5414080a5c Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 12 Oct 2025 16:01:18 +0800 Subject: [PATCH 15/29] Update cwb_lorebookManager.js --- CharacterWorldBook/src/cwb_lorebookManager.js | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/CharacterWorldBook/src/cwb_lorebookManager.js b/CharacterWorldBook/src/cwb_lorebookManager.js index 4414138..4fb699e 100644 --- a/CharacterWorldBook/src/cwb_lorebookManager.js +++ b/CharacterWorldBook/src/cwb_lorebookManager.js @@ -317,3 +317,84 @@ export async function manageAutoCardUpdateLorebookEntry() { logError('管理世界书条目时出错:', error); } } +/** + * (重构) 通用函数,用于同步小说处理生成的世界书条目。 + * @param {string} bookName - 目标世界书名称。 + * @param {Array<{title: string, content: string}>} entries - 从API回复中解析出的条目数组。 + */ +export async function syncNovelLorebookEntries(bookName, entries) { + if (!bookName || !Array.isArray(entries) || entries.length === 0) { + logError('[CWB-NovelSync] 参数无效或条目为空'); + if (Array.isArray(entries) && entries.length === 0) { + showToastr('warning', '[小说处理] API回复中未找到有效条目。'); + } + return; + } + + try { + const allEntries = (await TavernHelper.getLorebookEntries(bookName)) || []; + const managedEntries = allEntries.filter(e => e.comment?.startsWith(`[Amily2小说处理]`)); + + const entriesToUpdate = []; + const entriesToCreate = []; + + // 查找“章节内容概述”的最新部分编号 + let maxPart = 0; + managedEntries.forEach(entry => { + const match = entry.comment.match(/章节内容概述-第(\d+)部分/); + if (match && parseInt(match[1], 10) > maxPart) { + maxPart = parseInt(match[1], 10); + } + }); + let nextPart = maxPart + 1; + + for (const entry of entries) { + const { title, content } = entry; + + if (title === '章节内容概述') { + // “章节内容概述”条目总是新建 + const loreData = { + keys: [`小说处理`, title, `第${nextPart}部分`], + content: content, + comment: `[Amily2小说处理] ${title}-第${nextPart}部分`, + enabled: true, + order: 100, + position: 'before_char', + }; + entriesToCreate.push(loreData); + nextPart++; // 为同一批次中的下一个概述增加编号 + } else { + // 其他条目(世界观、时间线等)是动态更新的 + const existingEntry = managedEntries.find(e => e.comment === `[Amily2小说处理] ${title}`); + + const loreData = { + keys: [`小说处理`, title], + content: content, + comment: `[Amily2小说处理] ${title}`, + enabled: true, + order: 100, + position: 'before_char', + }; + + if (existingEntry) { + entriesToUpdate.push({ uid: existingEntry.uid, ...loreData }); + } else { + entriesToCreate.push(loreData); + } + } + } + + if (entriesToUpdate.length > 0) { + await TavernHelper.setLorebookEntries(bookName, entriesToUpdate); + showToastr('info', `[小说处理] 更新了 ${entriesToUpdate.length} 个世界书条目。`); + } + if (entriesToCreate.length > 0) { + await TavernHelper.createLorebookEntries(bookName, entriesToCreate); + showToastr('success', `[小说处理] 创建了 ${entriesToCreate.length} 个新世界书条目。`); + } + + } catch (error) { + logError('同步小说世界书条目时出错:', error); + showToastr('error', '同步世界书失败,详情请查看控制台。'); + } +} From b0aaf2e76fc732bcb4c32ad2f1344cc2a58d7664 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 12 Oct 2025 16:01:56 +0800 Subject: [PATCH 16/29] Update bindings.js --- ui/bindings.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ui/bindings.js b/ui/bindings.js index d4689ac..291c519 100644 --- a/ui/bindings.js +++ b/ui/bindings.js @@ -662,7 +662,7 @@ export function bindModalEvents() { container .off("click.amily2.chamber_nav") .on("click.amily2.chamber_nav", - "#amily2_open_plot_optimization, #amily2_open_additional_features, #amily2_open_rag_palace, #amily2_open_memorisation_forms, #amily2_open_character_world_book, #amily2_open_world_editor, #amily2_back_to_main_settings, #amily2_back_to_main_from_hanlinyuan, #amily2_back_to_main_from_forms, #amily2_back_to_main_from_optimization, #amily2_back_to_main_from_cwb, #amily2_back_to_main_from_world_editor", function () { + "#amily2_open_plot_optimization, #amily2_open_additional_features, #amily2_open_rag_palace, #amily2_open_memorisation_forms, #amily2_open_character_world_book, #amily2_open_world_editor, #amily2_open_glossary, #amily2_back_to_main_settings, #amily2_back_to_main_from_hanlinyuan, #amily2_back_to_main_from_forms, #amily2_back_to_main_from_optimization, #amily2_back_to_main_from_cwb, #amily2_back_to_main_from_world_editor, #amily2_back_to_main_from_glossary", function () { if (!pluginAuthStatus.authorized) return; const mainPanel = container.find('.plugin-features'); @@ -672,6 +672,7 @@ container const plotOptimizationPanel = container.find('#amily2_plot_optimization_panel'); const characterWorldBookPanel = container.find('#amily2_character_world_book_panel'); const worldEditorPanel = container.find('#amily2_world_editor_panel'); + const glossaryPanel = container.find('#amily2_glossary_panel'); mainPanel.hide(); additionalPanel.hide(); @@ -680,6 +681,7 @@ container plotOptimizationPanel.hide(); characterWorldBookPanel.hide(); worldEditorPanel.hide(); + glossaryPanel.hide(); switch (this.id) { case 'amily2_open_plot_optimization': @@ -700,12 +702,16 @@ container case 'amily2_open_world_editor': worldEditorPanel.show(); break; + case 'amily2_open_glossary': + glossaryPanel.show(); + break; case 'amily2_back_to_main_settings': case 'amily2_back_to_main_from_hanlinyuan': case 'amily2_back_to_main_from_forms': case 'amily2_back_to_main_from_optimization': case 'amily2_back_to_main_from_cwb': case 'amily2_back_to_main_from_world_editor': + case 'amily2_back_to_main_from_glossary': mainPanel.show(); break; } @@ -715,7 +721,7 @@ container .off("change.amily2.checkbox") .on( "change.amily2.checkbox", - 'input[type="checkbox"][id^="amily2_"]:not([id^="amily2_wb_enabled"])', + 'input[type="checkbox"][id^="amily2_"]:not([id^="amily2_wb_enabled"]):not(#amily2_sybd_enabled)', function (event) { if (!pluginAuthStatus.authorized) return; From e3ca07d6be2a223394fca2c8abdc9c85585b9cc7 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 12 Oct 2025 16:02:52 +0800 Subject: [PATCH 17/29] Update state.js --- ui/state.js | 1 - 1 file changed, 1 deletion(-) diff --git a/ui/state.js b/ui/state.js index 391fb3e..ee244a0 100644 --- a/ui/state.js +++ b/ui/state.js @@ -79,7 +79,6 @@ export function updateUI() { const settings = extension_settings[extensionName]; if (!settings) return; - $("#amily2_enabled").prop("checked", settings.enabled); $("#amily2_api_provider").val(settings.apiProvider || 'openai'); $("#amily2_api_url").val(settings.apiUrl); $("#amily2_api_url").attr('type', 'text'); From d556a35e09d711c03338783bbe883080a0732a5d Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 12 Oct 2025 16:03:15 +0800 Subject: [PATCH 18/29] Update drawer.js --- ui/drawer.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ui/drawer.js b/ui/drawer.js index f9f2b93..0062795 100644 --- a/ui/drawer.js +++ b/ui/drawer.js @@ -97,6 +97,10 @@ async function initializePanel(contentPanel, errorContainer) { const worldEditorPanelHtml = ``; mainContainer.append(worldEditorPanelHtml); + const glossaryContent = await $.get(`${extensionFolderPath}/assets/amily2-glossary.html`); + const glossaryPanelHtml = ``; + mainContainer.append(glossaryPanelHtml); + // 在面板创建后,加载世界书编辑器脚本 const worldEditorScriptId = 'world-editor-script'; if (!document.getElementById(worldEditorScriptId)) { From 33b85940d809557db2c669ad57568b2df43d3e04 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 12 Oct 2025 16:04:08 +0800 Subject: [PATCH 19/29] Update amily2-modal.html --- assets/amily2-modal.html | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/assets/amily2-modal.html b/assets/amily2-modal.html index 2f5fd63..ba5db7e 100644 --- a/assets/amily2-modal.html +++ b/assets/amily2-modal.html @@ -112,31 +112,30 @@ - From 4595cbd8b6128d5e5d7b45f870d67cbef5f2c59b Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 12 Oct 2025 16:05:35 +0800 Subject: [PATCH 20/29] Create amily2-glossary.html --- assets/amily2-glossary.html | 183 ++++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 assets/amily2-glossary.html diff --git a/assets/amily2-glossary.html b/assets/amily2-glossary.html new file mode 100644 index 0000000..8b4f4dc --- /dev/null +++ b/assets/amily2-glossary.html @@ -0,0 +1,183 @@ +
+
+ 术语表 (Sybd 系统) +
+ +
+
+ + +
+ + + + +
+ + +
+ + +
+
+
Sybd API 调用系统
+ + 独立的API调用系统,可与主系统并行使用,支持全兼容和SillyTavern预设两种模式。 + + +
+ + +
+ +
+
+ + +
+ +
+ +
+
+ + +
+
+ + +
+
+ +
+ + +
+
+
+ + + + + +
+ + +
+
+ + +
+ + +
+ + +
+
+
+
+
+ + +
+
+
待开发
+

待开发

+
+
+ + +
+
+
待开发
+

待开发

+
+
+ + +
+
+
小说文件处理流程
+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+ +
+ +
+ 请先上传文件并识别章节... +
+
+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+ 等待操作... +
+
+
+
From d807ac65e367b45303e61a3cdc8ba0bb76ef5098 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 12 Oct 2025 16:06:16 +0800 Subject: [PATCH 21/29] Create amily2-glossary.css --- assets/amily2-glossary.css | 118 +++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 assets/amily2-glossary.css diff --git a/assets/amily2-glossary.css b/assets/amily2-glossary.css new file mode 100644 index 0000000..453a6c8 --- /dev/null +++ b/assets/amily2-glossary.css @@ -0,0 +1,118 @@ +/* --- 术语表 (Glossary) 专属样式 --- */ +/* 所有样式均已限定在 #amily2_glossary_panel 范围内,防止全局污染 */ + +/* 标签页导航容器 */ +#amily2_glossary_panel .glossary-tabs { + display: flex; + border-bottom: 1px solid rgba(255, 255, 255, 0.2); + margin-bottom: 15px; +} + +/* 单个标签页按钮 */ +#amily2_glossary_panel .glossary-tab { + background: none; + border: none; + color: var(--text-color-secondary); + padding: 10px 15px; + cursor: pointer; + font-size: 1em; + transition: color 0.2s, border-bottom 0.2s; + border-bottom: 2px solid transparent; + margin-bottom: -1px; /* 让下边框与容器边框重合 */ +} + +#amily2_glossary_panel .glossary-tab:hover { + color: var(--text-color-light); +} + +/* 激活状态的标签页 */ +#amily2_glossary_panel .glossary-tab.active { + color: var(--text-color-accent); + border-bottom: 2px solid var(--text-color-accent); +} + +#amily2_glossary_panel .glossary-tab i { + margin-right: 8px; +} + +/* 标签页内容面板 */ +#amily2_glossary_panel .glossary-content { + display: none; /* 默认隐藏 */ +} + +/* 激活状态的内容面板 */ +#amily2_glossary_panel .glossary-content.active { + display: block; /* 显示激活的面板 */ +} + +/* 隐藏内容的辅助类 */ +#amily2_glossary_panel .amily2-content-hidden { + display: none !important; +} + +/* 通用设置组样式 */ +#amily2_glossary_panel .settings-group { + background-color: rgba(0, 0, 0, 0.15); + border: 1px solid rgba(255, 255, 255, 0.1); + border-radius: 10px; + padding: 15px; + margin-bottom: 15px; +} + +#amily2_glossary_panel .settings-group .legend { + font-size: 1.1em; + font-weight: bold; + color: var(--text-color-light); + margin-bottom: 10px; + padding-bottom: 5px; + border-bottom: 1px solid rgba(255, 255, 255, 0.15); +} + +#amily2_glossary_panel .settings-group .legend i { + margin-right: 8px; + color: var(--text-color-accent); +} + +/* 设置块 */ +#amily2_glossary_panel .amily2_settings_block { + display: flex; + justify-content: space-between; + align-items: center; + padding: 10px 0; + border-bottom: 1px solid rgba(255, 255, 255, 0.08); +} +#amily2_glossary_panel .amily2_settings_block:last-child { + border-bottom: none; +} + +/* 控制组(标签和输入框) */ +#amily2_glossary_panel .control-group { + display: flex; + align-items: center; + margin-bottom: 12px; +} + +#amily2_glossary_panel .control-group label { + flex-basis: 150px; /* 固定标签宽度 */ + flex-shrink: 0; + margin-right: 10px; +} + +#amily2_glossary_panel .control-group .text_pole, +#amily2_glossary_panel .control-group .select-with-refresh { + flex-grow: 1; +} + +/* 带刷新按钮的选择器 */ +#amily2_glossary_panel .select-with-refresh { + display: flex; + align-items: center; +} + +/* 按钮行 */ +#amily2_glossary_panel .sybd-button-row { + display: flex; + gap: 10px; + justify-content: center; + margin-top: 20px; +} From 14ae17d997a326bb52c17786a900b3469ef56ca9 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 12 Oct 2025 16:07:27 +0800 Subject: [PATCH 22/29] Update WorldEditor.js --- WorldEditor/WorldEditor.js | 601 +++++++++++++++++++++++-------------- 1 file changed, 377 insertions(+), 224 deletions(-) diff --git a/WorldEditor/WorldEditor.js b/WorldEditor/WorldEditor.js index 659b8b1..bd1b878 100644 --- a/WorldEditor/WorldEditor.js +++ b/WorldEditor/WorldEditor.js @@ -1,20 +1,29 @@ -/** - * 世界书编辑器 - 最终稳定版 - */ -import { world_names, loadWorldInfo, saveWorldInfo } from "/scripts/world-info.js"; + +import { world_names, loadWorldInfo, saveWorldInfo, deleteWorldInfo, updateWorldInfoList } from "/scripts/world-info.js"; import { eventSource, event_types } from '/script.js'; import { showHtmlModal } from '/scripts/extensions/third-party/ST-Amily2-Chat-Optimisation/ui/page-window.js'; +import { safeLorebooks, safeLorebookEntries, safeUpdateLorebookEntries } from '../core/tavernhelper-compatibility.js'; +import { writeToLorebookWithTavernHelper } from '../core/lore.js'; const { SillyTavern, TavernHelper } = window; class WorldEditor { constructor() { + // 通用状态 + this.isLoading = false; + + // 世界书视图状态 + this.allWorldBooks = []; + this.filteredWorldBooks = []; + this.selectedWorldBooks = new Set(); + + // 条目视图状态 this.currentWorldBook = null; this.entries = []; this.selectedEntries = new Set(); this.filteredEntries = []; - this.isLoading = false; this.currentEditingEntry = null; this.sortState = { key: 'order', asc: true }; + this.init(); } @@ -26,13 +35,22 @@ class WorldEditor { } this.bindEvents(); this.loadAvailableWorldBooks(); - this.bindExternalEvents(); // 绑定外部事件监听 + this.bindExternalEvents(); } initializeComponents() { const ids = [ - 'world-editor-world-select', 'world-editor-refresh-btn', 'world-editor-create-entry-btn', - 'world-editor-search-box', 'world-editor-search-btn', 'world-editor-entry-count', + // 主视图 + 'world-book-selection-view', 'world-editor-entry-view', + // 顶部按钮 + 'world-editor-refresh-btn', 'world-editor-create-book-btn', 'world-editor-create-entry-btn', + // 世界书视图 + 'world-book-search-box', 'world-book-search-btn', 'world-book-count', + 'world-book-batch-actions', 'world-book-selected-count', 'world-book-clone-btn', 'world-book-delete-btn', + 'world-book-list-container', + // 条目视图 + 'world-editor-current-book-title', 'world-editor-back-to-list-btn', + 'world-editor-search-type', 'world-editor-search-box', 'world-editor-search-btn', 'world-editor-entry-count', 'world-editor-select-all', 'world-editor-selected-count', 'world-editor-batch-actions', 'world-editor-entries-container', 'world-editor-enable-selected-btn', 'world-editor-disable-selected-btn', @@ -44,23 +62,35 @@ class WorldEditor { for (const id of ids) { const camelCaseId = id.replace(/-(\w)/g, (_, c) => c.toUpperCase()); this.elements[camelCaseId] = document.getElementById(id); - if (!this.elements[camelCaseId] && id.endsWith('container')) { // Only container is critical - console.error(`[世界书编辑器] 关键元素缺失: ${id}`); - missing = true; + if (!this.elements[camelCaseId]) { + console.warn(`[世界书编辑器] UI元素缺失: ${id}`); + if (id.endsWith('container') || id.endsWith('view')) { + missing = true; // 关键元素缺失 + } } } return !missing; } bindEvents() { - this.elements.worldEditorWorldSelect.addEventListener('change', (e) => this.loadWorldBookEntries(e.target.value)); + // 视图切换 + this.elements.worldEditorBackToListBtn.addEventListener('click', () => this.switchToBookListView()); + + // 顶部按钮 this.elements.worldEditorRefreshBtn.addEventListener('click', () => this.loadAvailableWorldBooks()); - document.querySelector('#world-editor-container .world-editor-entries-header').addEventListener('click', (e) => { - if (e.target.dataset.sort) { - this.sortEntries(e.target.dataset.sort); - } - }); + this.elements.worldEditorCreateBookBtn.addEventListener('click', () => this.createNewWorldBook()); this.elements.worldEditorCreateEntryBtn.addEventListener('click', () => this.openCreateModal()); + + // 世界书视图事件 + this.elements.worldBookSearchBox.addEventListener('input', () => this.filterWorldBooks()); + this.elements.worldBookSearchBtn.addEventListener('click', () => this.filterWorldBooks()); + this.elements.worldBookCloneBtn.addEventListener('click', () => this.cloneSelectedBooks()); + this.elements.worldBookDeleteBtn.addEventListener('click', () => this.deleteSelectedBooks()); + + // 条目视图事件 + document.querySelector('#world-editor-entry-view .world-editor-entries-header').addEventListener('click', (e) => { + if (e.target.dataset.sort) this.sortEntries(e.target.dataset.sort); + }); this.elements.worldEditorSearchBox.addEventListener('input', () => this.filterEntries()); this.elements.worldEditorSearchBtn.addEventListener('click', () => this.filterEntries()); this.elements.worldEditorSelectAll.addEventListener('change', (e) => this.toggleSelectAll(e.target.checked)); @@ -73,19 +103,29 @@ class WorldEditor { this.elements.worldEditorSetPreventRecursionBtn.addEventListener('click', () => this.toggleBatchRecursion('prevent_recursion', '防止递归')); } + // 视图管理 + switchToBookListView() { + this.elements.worldBookSelectionView.style.display = 'block'; + this.elements.worldEditorEntryView.style.display = 'none'; + this.elements.worldEditorCreateEntryBtn.disabled = true; + this.currentWorldBook = null; + } + + switchToEntryView(bookName) { + this.elements.worldBookSelectionView.style.display = 'none'; + this.elements.worldEditorEntryView.style.display = 'block'; + this.elements.worldEditorCreateEntryBtn.disabled = false; + this.elements.worldEditorCurrentBookTitle.textContent = `当前编辑:${bookName}`; + this.loadWorldBookEntries(bookName); + } + + // 世界书数据处理 async loadAvailableWorldBooks() { this.setLoading(true); try { const books = await this.getAllWorldBooks(); - const select = this.elements.worldEditorWorldSelect; - select.innerHTML = ''; - books.forEach(book => { - const option = document.createElement('option'); - option.value = book.name; - option.textContent = book.name; - select.appendChild(option); - }); - await this.selectCurrentCharacterWorldBook(); + this.allWorldBooks = books.sort((a, b) => a.name.localeCompare(b.name)); + this.filterWorldBooks(); // 这会渲染列表 } catch (error) { this.showError('加载世界书列表失败: ' + error.message); } finally { @@ -94,39 +134,174 @@ class WorldEditor { } async getAllWorldBooks() { - if (TavernHelper?.getLorebooks) { - const books = await TavernHelper.getLorebooks(); - if (Array.isArray(books) && books.length > 0) return books.map(name => ({ name })); - } - return (world_names || []).map(name => ({ name })); + const books = await safeLorebooks(); + return books.map(name => ({ name })); } - async selectCurrentCharacterWorldBook() { - if (TavernHelper?.getCurrentCharPrimaryLorebook) { - const primaryBook = await TavernHelper.getCurrentCharPrimaryLorebook(); - if (primaryBook) { - this.elements.worldEditorWorldSelect.value = primaryBook; - await this.loadWorldBookEntries(primaryBook); + filterWorldBooks() { + const term = this.elements.worldBookSearchBox.value.toLowerCase(); + this.filteredWorldBooks = this.allWorldBooks.filter(book => book.name.toLowerCase().includes(term)); + this.renderWorldBookList(); + this.updateWorldBookCount(); + } + + renderWorldBookList() { + const container = this.elements.worldBookListContainer; + container.innerHTML = ''; // 清空 + if (this.filteredWorldBooks.length === 0) { + container.innerHTML = '

没有找到世界书

'; + return; + } + + const fragment = document.createDocumentFragment(); + this.filteredWorldBooks.forEach(book => { + const isSelected = this.selectedWorldBooks.has(book.name); + const row = document.createElement('div'); + row.className = `world-book-row ${isSelected ? 'selected' : ''}`; + row.dataset.bookName = book.name; + row.innerHTML = ` + + ${book.name} +
+ + +
+ `; + fragment.appendChild(row); + }); + container.appendChild(fragment); + this.bindWorldBookListEvents(); + } + + bindWorldBookListEvents() { + this.elements.worldBookListContainer.querySelectorAll('.world-book-row').forEach(row => { + const bookName = row.dataset.bookName; + // 复选框事件 + row.querySelector('.world-book-checkbox').addEventListener('change', (e) => { + if (e.target.checked) { + this.selectedWorldBooks.add(bookName); + } else { + this.selectedWorldBooks.delete(bookName); + } + row.classList.toggle('selected', e.target.checked); + this.updateWorldBookSelectionUI(); + }); + + // 按钮事件 + row.querySelector('[data-action="edit"]').addEventListener('click', (e) => { + e.stopPropagation(); + this.switchToEntryView(bookName); + }); + row.querySelector('[data-action="rename"]').addEventListener('click', (e) => { + e.stopPropagation(); + this.renameWorldBook(bookName); + }); + }); + } + + async createNewWorldBook() { + const bookName = prompt("请输入新的世界书名称:"); + if (bookName && bookName.trim()) { + const trimmedBookName = bookName.trim(); + try { + await writeToLorebookWithTavernHelper(trimmedBookName, '新条目', () => '这是一个新条目', {}); + if (window.toastr) window.toastr.success(`世界书 "${trimmedBookName}" 创建成功!`); + this.loadAvailableWorldBooks(); + } catch (error) { + this.showError(`创建失败: ${error.message}`); } } } + async renameWorldBook(oldName) { + const newName = prompt(`重命名世界书 "${oldName}":`, oldName); + if (newName && newName.trim() && newName !== oldName) { + const trimmedNewName = newName.trim(); + try { + const bookData = await loadWorldInfo(oldName); + await saveWorldInfo(trimmedNewName, bookData); + await deleteWorldInfo(oldName); + if (window.toastr) window.toastr.success('重命名成功!'); + + await updateWorldInfoList(); + eventSource.emit(event_types.CHARACTER_PAGE_LOADED); + this.loadAvailableWorldBooks(); + } catch (error) { + this.showError(`重命名失败: ${error.message}`); + } + } + } + + async cloneSelectedBooks() { + if (this.selectedWorldBooks.size === 0) return; + if (!confirm(`确定要为 ${this.selectedWorldBooks.size} 个世界书创建备份吗?`)) return; + + this.setLoading(true); + try { + for (const bookName of this.selectedWorldBooks) { + const newName = `${bookName}_备份_${Date.now()}`; + const bookData = await loadWorldInfo(bookName); + await saveWorldInfo(newName, bookData); + } + if (window.toastr) window.toastr.success('备份创建成功!'); + + await updateWorldInfoList(); + eventSource.emit(event_types.CHARACTER_PAGE_LOADED); + this.loadAvailableWorldBooks(); + } catch (error) { + this.showError(`备份失败: ${error.message}`); + } finally { + this.setLoading(false); + } + } + + async deleteSelectedBooks() { + if (this.selectedWorldBooks.size === 0) return; + if (!confirm(`警告:这将永久删除 ${this.selectedWorldBooks.size} 个世界书及其所有内容!确定要继续吗?`)) return; + + this.setLoading(true); + try { + for (const bookName of this.selectedWorldBooks) { + await deleteWorldInfo(bookName); + } + if (window.toastr) window.toastr.success('批量删除成功!'); + + await updateWorldInfoList(); + eventSource.emit(event_types.CHARACTER_PAGE_LOADED); + this.loadAvailableWorldBooks(); + } catch (error) { + this.showError(`删除失败: ${error.message}`); + } finally { + this.setLoading(false); + } + } + + updateWorldBookCount() { + this.elements.worldBookCount.textContent = `世界书:${this.allWorldBooks.length}`; + } + + updateWorldBookSelectionUI() { + const count = this.selectedWorldBooks.size; + this.elements.worldBookSelectedCount.textContent = `已选择 ${count} 项`; + this.elements.worldBookBatchActions.classList.toggle('active', count > 0); + } + + + // 条目数据处理 (大部分逻辑与旧版相似) async loadWorldBookEntries(worldBookName) { - if (!worldBookName) { this.entries = []; this.renderEntries(); return; } + if (!worldBookName) { + this.entries = []; + this.filteredEntries = []; + this.selectedEntries.clear(); + this.renderEntries(); + this.updateEntryCount(); + this.updateSelectionUI(); + return; + } this.setLoading(true); this.currentWorldBook = worldBookName; try { - let rawEntries = await TavernHelper?.getLorebookEntries?.(worldBookName); - if (!rawEntries || rawEntries.length === 0) { - const bookData = await loadWorldInfo(worldBookName); - if (bookData?.entries) { - rawEntries = Object.entries(bookData.entries).map(([uid, entry]) => ({ - uid: parseInt(uid), enabled: !entry.disable, type: entry.constant ? 'constant' : 'selective', - keys: entry.key || [], content: entry.content || '', position: this.convertPositionFromNative(entry.position), - depth: entry.depth, order: entry.order, comment: entry.comment || '' - })); - } - } + const rawEntries = await safeLorebookEntries(worldBookName); this.entries = (rawEntries || []).map(e => ({ uid: e.uid, enabled: e.enabled, type: e.type || (e.constant ? 'constant' : 'selective'), keys: e.keys || [], content: e.content || '', position: e.position || 'before_character_definition', @@ -138,8 +313,11 @@ class WorldEditor { this.updateEntryCount(); } catch (error) { this.showError(`加载条目失败: ${error.message}`); - this.entries = []; this.renderEntries(); + this.entries = []; + this.filteredEntries = []; } finally { + this.selectedEntries.clear(); + this.updateSelectionUI(); this.setLoading(false); } } @@ -153,10 +331,6 @@ class WorldEditor { const container = this.elements.worldEditorEntriesContainer; const header = container.querySelector('.world-editor-entries-header'); - // Clear only the entry rows, not the header - while (container.firstChild && container.firstChild !== header) { - container.removeChild(container.firstChild); - } while (header && header.nextSibling) { container.removeChild(header.nextSibling); } @@ -178,7 +352,6 @@ class WorldEditor { tempDiv.innerHTML = rowHTML; const rowElement = tempDiv.firstChild; - // Safely set the content to prevent HTML rendering const contentCell = rowElement.querySelector('.world-editor-entry-content'); if (contentCell) { contentCell.textContent = e.content || ''; @@ -216,19 +389,13 @@ class WorldEditor { bindEntryEvents() { this.elements.worldEditorEntriesContainer.querySelectorAll('.world-editor-entry-row').forEach(row => { const uid = parseInt(row.dataset.uid); - - // Checkbox const checkbox = row.querySelector('.world-editor-entry-checkbox'); checkbox.addEventListener('change', (e) => { if (e.target.checked) this.selectedEntries.add(uid); else this.selectedEntries.delete(uid); row.classList.toggle('selected', e.target.checked); this.updateSelectionUI(); }); - - // Content click to open modal (for longer edits) row.querySelector('[data-action="open-editor"]').addEventListener('click', () => this.openEditModal(uid)); - - // Inline toggles (enabled, type) row.querySelectorAll('.inline-toggle').forEach(toggle => { toggle.addEventListener('click', (e) => { e.stopPropagation(); @@ -240,54 +407,106 @@ class WorldEditor { this.updateSingleEntry(uid, { [field]: newValue }); }); }); - - // Inline edits (inputs, selects) row.querySelectorAll('.inline-edit').forEach(input => { input.addEventListener('change', (e) => { e.stopPropagation(); const field = input.dataset.field; let value = input.value; if (input.type === 'number') value = parseInt(value, 10); - // The 'keys' field is no longer inline editable, so that specific logic can be removed. - const updates = { [field]: value }; - // If position changes, re-evaluate depth disable state if (field === 'position') { const depthInput = row.querySelector('[data-field="depth"]'); if (depthInput) depthInput.disabled = !value.startsWith('at_depth'); } - this.updateSingleEntry(uid, updates); }); - input.addEventListener('click', e => e.stopPropagation()); // Prevent row selection when clicking input + input.addEventListener('click', e => e.stopPropagation()); }); }); } + /** + * 使用原生 saveWorldInfo 更新条目,避免界面跳转 + * @param {Array} entriesToUpdate - 需要更新的条目对象数组 + */ + async updateEntriesWithNativeMethod(entriesToUpdate) { + try { + const bookData = await loadWorldInfo(this.currentWorldBook); + if (!bookData || !bookData.entries) { + throw new Error("无法加载世界书数据。"); + } + + const uidsToUpdate = new Set(entriesToUpdate.map(e => e.uid)); + const updatedUIDs = new Set(); + + // 更新 bookData.entries + for (const entry of entriesToUpdate) { + if (bookData.entries[entry.uid]) { + const nativeEntry = bookData.entries[entry.uid]; + nativeEntry.comment = entry.comment; + nativeEntry.content = entry.content; + nativeEntry.key = entry.keys; + nativeEntry.disable = !entry.enabled; + nativeEntry.constant = entry.type === 'constant'; + nativeEntry.position = this.convertPositionToNative(entry.position); + nativeEntry.depth = entry.depth; + nativeEntry.order = entry.order; + nativeEntry.exclude_recursion = entry.exclude_recursion; + nativeEntry.prevent_recursion = entry.prevent_recursion; + updatedUIDs.add(entry.uid); + } + } + + if (updatedUIDs.size !== uidsToUpdate.size) { + console.warn("[世界书编辑器] 部分条目更新失败,UID可能不存在。"); + } + + await saveWorldInfo(this.currentWorldBook, bookData, true); // true 表示静默保存 + + // Optimistic UI update in local state + for (const updatedEntry of entriesToUpdate) { + const localEntry = this.entries.find(e => e.uid === updatedEntry.uid); + if (localEntry) { + Object.assign(localEntry, updatedEntry); + } + } + this.renderEntries(); + + } catch (error) { + this.showError(`更新失败: ${error.message}`); + this.loadWorldBookEntries(this.currentWorldBook); // On error, re-sync with truth + } + } + + // Helper function to convert string position to native number format + convertPositionToNative(posStr) { + const map = { + 'before_character_definition': 0, + 'after_character_definition': 1, + 'before_author_note': 2, + 'after_author_note': 3, + 'at_depth': 4, + 'at_depth_as_system': 4 + }; + return map[posStr] !== undefined ? map[posStr] : 4; + } + async updateSingleEntry(uid, updates) { const entry = this.entries.find(e => e.uid === uid); if (!entry) return; - - // Optimistic UI update - Object.assign(entry, updates); - this.renderEntries(); // Re-render to reflect changes immediately - - try { - await TavernHelper.setLorebookEntries(this.currentWorldBook, [{ ...entry, ...updates }]); - } catch (error) { - this.showError(`更新失败: ${error.message}`); - // Revert on failure - this.loadWorldBookEntries(this.currentWorldBook); - } + const updatedEntry = { ...entry, ...updates }; + await this.updateEntriesWithNativeMethod([updatedEntry]); } async batchUpdateEntries(updates, confirmation = null) { if (this.selectedEntries.size === 0) return; if (confirmation && !confirm(confirmation)) return; - const entries = this.entries.filter(e => this.selectedEntries.has(e.uid)).map(e => ({ ...e, ...updates })); - await TavernHelper.setLorebookEntries(this.currentWorldBook, entries); - this.loadWorldBookEntries(this.currentWorldBook); // Refresh + const entriesToUpdate = this.entries + .filter(e => this.selectedEntries.has(e.uid)) + .map(e => ({ ...e, ...updates })); + + await this.updateEntriesWithNativeMethod(entriesToUpdate); if (window.toastr) window.toastr.success('批量更新成功!'); } @@ -303,9 +522,12 @@ class WorldEditor { async batchDeleteEntries() { if (this.selectedEntries.size === 0 || !confirm(`删除 ${this.selectedEntries.size} 个条目?`)) return; - await TavernHelper.deleteLorebookEntries(this.currentWorldBook, Array.from(this.selectedEntries)); - this.selectedEntries.clear(); - this.loadWorldBookEntries(this.currentWorldBook); // Refresh + try { + await TavernHelper.deleteLorebookEntries(this.currentWorldBook, Array.from(this.selectedEntries)); + this.loadWorldBookEntries(this.currentWorldBook); + } catch (error) { + this.showError(`删除失败: ${error.message}`); + } } toggleSelectAll(checked) { @@ -327,16 +549,8 @@ class WorldEditor { filterEntries() { const term = this.elements.worldEditorSearchBox.value.toLowerCase(); - const searchType = document.getElementById('world-editor-search-type').value; - - if (!term) { - this.filteredEntries = [...this.entries]; - } else { - this.filteredEntries = this.entries.filter(e => { - const targetField = e[searchType] || ''; - return targetField.toLowerCase().includes(term); - }); - } + const searchType = this.elements.worldEditorSearchType.value; + this.filteredEntries = !term ? [...this.entries] : this.entries.filter(e => (e[searchType] || '').toLowerCase().includes(term)); this.renderEntries(); } @@ -355,146 +569,84 @@ class WorldEditor { showEditModal(title, entry) { const formHtml = this.getEditFormHtml(entry); - showHtmlModal(title, formHtml, { - onOk: (dialog) => { - this.saveEntry(dialog); - return true; // Close the modal - } - }); + showHtmlModal(title, formHtml, { onOk: (d) => { this.saveEntry(d); return true; } }); } getEditFormHtml(entry) { return `
-
- - -
- - - - - - - - - - - - - - - - - - - - - - -
- - -
-
- - -
- +
+ + + + + + + +
+
`; } async saveEntry(dialog) { const formData = this.getFormDataFromModal(dialog); - if (this.currentEditingEntry) { - await TavernHelper.setLorebookEntries(this.currentWorldBook, [{ ...this.currentEditingEntry, ...formData }]); - } else { - await TavernHelper.createLorebookEntries(this.currentWorldBook, [formData]); + try { + if (this.currentEditingEntry) { + // 使用改造后的原生方法更新 + await this.updateEntriesWithNativeMethod([{ ...this.currentEditingEntry, ...formData }]); + } else { + // 创建条目仍然可以使用TavernHelper,因为它通常不会触发跳转 + await TavernHelper.createLorebookEntries(this.currentWorldBook, [formData]); + } + // 刷新当前视图 + this.loadWorldBookEntries(this.currentWorldBook); + } catch (error) { + this.showError(`保存失败: ${error.message}`); } - this.loadWorldBookEntries(this.currentWorldBook); } getFormDataFromModal(dialog) { - const data = {}; - data.enabled = dialog.find('#world-editor-entry-enabled').is(':checked'); - data.type = dialog.find('#world-editor-entry-type').val(); - data.keys = dialog.find('#world-editor-entry-keys').val().split('\n').map(k => k.trim()).filter(Boolean); - data.content = dialog.find('#world-editor-entry-content').val(); - data.position = dialog.find('#world-editor-entry-position').val(); - data.depth = parseInt(dialog.find('#world-editor-entry-depth').val()); - data.order = parseInt(dialog.find('#world-editor-entry-order').val()); - data.comment = dialog.find('#world-editor-entry-comment').val(); - data.exclude_recursion = dialog.find('#world-editor-entry-disable-recursion').is(':checked'); - data.prevent_recursion = dialog.find('#world-editor-entry-prevent-recursion').is(':checked'); - return data; + return { + enabled: dialog.find('#world-editor-entry-enabled').is(':checked'), + type: dialog.find('#world-editor-entry-type').val(), + keys: dialog.find('#world-editor-entry-keys').val().split('\n').map(k => k.trim()).filter(Boolean), + content: dialog.find('#world-editor-entry-content').val(), + position: dialog.find('#world-editor-entry-position').val(), + depth: parseInt(dialog.find('#world-editor-entry-depth').val()), + order: parseInt(dialog.find('#world-editor-entry-order').val()), + comment: dialog.find('#world-editor-entry-comment').val(), + exclude_recursion: dialog.find('#world-editor-entry-disable-recursion').is(':checked'), + prevent_recursion: dialog.find('#world-editor-entry-prevent-recursion').is(':checked') + }; } - setLoading(loading) { this.elements.worldEditorEntriesContainer.classList.toggle('loading', loading); } + setLoading(loading) { + this.isLoading = loading; + document.getElementById('world-editor-container').classList.toggle('loading', loading); + } showError(msg) { if (window.toastr) window.toastr.error(msg); console.error(msg); } sortEntries(key) { - if (this.sortState.key === key) { - this.sortState.asc = !this.sortState.asc; - } else { - this.sortState.key = key; - this.sortState.asc = true; - } + if (this.sortState.key === key) this.sortState.asc = !this.sortState.asc; + else { this.sortState.key = key; this.sortState.asc = true; } this.renderEntries(); } sortFilteredEntries() { const { key, asc } = this.sortState; this.filteredEntries.sort((a, b) => { - let valA = a[key]; - let valB = b[key]; - + let valA = a[key], valB = b[key]; if (typeof valA === 'string') valA = valA.toLowerCase(); if (typeof valB === 'string') valB = valB.toLowerCase(); - if (valA < valB) return asc ? -1 : 1; if (valA > valB) return asc ? 1 : -1; return 0; @@ -503,32 +655,33 @@ class WorldEditor { bindExternalEvents() { eventSource.on(event_types.CHAT_CHANGED, () => { - console.log('[世界书编辑器] 检测到聊天变更 (CHAT_CHANGED),将自动刷新。'); - this.loadAvailableWorldBooks(); + console.log('[世界书编辑器] 检测到聊天变更,将自动刷新。'); + if (this.currentWorldBook) { + this.loadWorldBookEntries(this.currentWorldBook); + } else { + this.loadAvailableWorldBooks(); + } }); - console.log('[世界书编辑器] 已成功绑定外部事件监听器。'); } } -function initializeWorldEditorWhenVisible() { - const panel = document.getElementById('amily2_world_editor_panel'); - if (!panel) { console.error('[WorldEditor] Panel not found!'); return; } - const observer = new MutationObserver(() => { - if (panel.style.display !== 'none' && !window.worldEditorInstance) { - window.worldEditorInstance = new WorldEditor(); - observer.disconnect(); - } - }); - observer.observe(panel, { attributes: true, attributeFilter: ['style'] }); - if (panel.style.display !== 'none') { // Check initial state - if (!window.worldEditorInstance) window.worldEditorInstance = new WorldEditor(); - observer.disconnect(); +function initializeWorldEditor() { + // 确保面板存在 + if (!document.getElementById('amily2_world_editor_panel')) { + console.error('[WorldEditor] Panel not found, initialization aborted.'); + return; + } + // 防止重复初始化 + if (!window.worldEditorInstance) { + console.log('[WorldEditor] Initializing WorldEditor instance.'); + window.worldEditorInstance = new WorldEditor(); } } +// 确保在DOM加载完毕后执行 if (document.readyState === 'loading') { - document.addEventListener('DOMContentLoaded', initializeWorldEditorWhenVisible); + document.addEventListener('DOMContentLoaded', initializeWorldEditor); } else { - initializeWorldEditorWhenVisible(); + initializeWorldEditor(); } From 7c3d82b925c77d91f9a09f6e5a826e2c7a1528e0 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sun, 12 Oct 2025 16:09:00 +0800 Subject: [PATCH 23/29] Update WorldEditor.html --- WorldEditor.html | 119 ++++++++++++++++++++++++++++------------------- 1 file changed, 70 insertions(+), 49 deletions(-) diff --git a/WorldEditor.html b/WorldEditor.html index a34c633..8da4dca 100644 --- a/WorldEditor.html +++ b/WorldEditor.html @@ -10,73 +10,94 @@
-
- 世界书管理 - -
+
- +
-
-
- - -
- -
-
- - - + +
+
+
+ + +
+
+ 世界书:0 +
-
- 条目:0 +
+ 已选择 0 项 + + +
+
+
-
-
- 已选择 0 项 - - - - - - - + +