diff --git a/core/rag-processor.js b/core/rag-processor.js index 0481088..36533b8 100644 --- a/core/rag-processor.js +++ b/core/rag-processor.js @@ -1 +1 @@ -'use strict';const _0x4a685c=_0x1993;(function(_0x465453,_0x797624){const _0x266fbe=_0x1993,_0xbdd17d=_0x465453();while(!![]){try{const _0xe1473c=parseInt(_0x266fbe(0xf6))/0x1+parseInt(_0x266fbe(0xfb))/0x2+parseInt(_0x266fbe(0xb8))/0x3+-parseInt(_0x266fbe(0x12a))/0x4+-parseInt(_0x266fbe(0x11a))/0x5+parseInt(_0x266fbe(0xe9))/0x6+-parseInt(_0x266fbe(0x9e))/0x7*(parseInt(_0x266fbe(0x12b))/0x8);if(_0xe1473c===_0x797624)break;else _0xbdd17d['push'](_0xbdd17d['shift']());}catch(_0x4577f6){_0xbdd17d['push'](_0xbdd17d['shift']());}}}(_0x55f7,0x316f8));import{extension_prompt_roles,setExtensionPrompt}from'/script.js';function _0x1993(_0x3b269c,_0x4bb7cb){const _0x55f721=_0x55f7();return _0x1993=function(_0x1993e9,_0x1728e2){_0x1993e9=_0x1993e9-0x90;let _0x49c1be=_0x55f721[_0x1993e9];return _0x49c1be;},_0x1993(_0x3b269c,_0x4bb7cb);}import*as _0x2ce1b6 from'./utils/context-utils.js';import{getCollectionIdInfo}from'./utils/context-utils.js';import{defaultSettings as _0x50292a}from'./rag-settings.js';import*as _0x20bfcb from'./ingestion-manager.js';import{getSanitizedBaseUrl,fetchEmbeddingModels,getRerankBaseUrl,fetchRerankModels,executeRerank,getApiEndpointUrl,getApiHeaders,getEmbeddings,testApiConnection as _0x4cc999}from'./rag-api.js';const MODULE_NAME=_0x4a685c(0xdd),OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME=_0x4a685c(0xf0);let context=null,settings=null,lockedCollectionId=null;function _0x55f7(){const _0x3c0060=['batchSize','Rerank失败:\x20','\x20记录凝识范围:\x20','replace','message','success','floor','[翰林院-日志]\x20忆识存入API错误:','[翰林院-核心]\x20ingestTextToHanlinyuan\x20失败:','start','hashes','aborted','\x20个条目。','第1章','extensionSettings','injection','POST','hanlinyuan-rag-core','trim','[翰林院-日志]\x20查询目标集合ID:\x20','error','length','info','[翰林院-日志]\x20宝库查询API错误:','[翰林院-日志]\x20开始向量查询\x20(采用最终API交互模式)...','[翰林院-分块]\x20未知的来源类型\x20\x27','无法确定当前忆识宝库的ID,请确认角色已正确加载。','未知来源',',\x20第1卷,\x20第1章,\x20第','651186qbGpdI','[翰林院-日志]\x20发送到\x20/api/vector/query\x20的请求体:','翰林院忆识核心已启动\x20(V5.1-借壳上市版),已注册全局函数:\x20','clearJob','[翰林院-日志]\x20/api/vector/list\x20响应状态:\x20','saveSettingsDebounced','toString','vectors_rearrangeChat','depth','/api/vector/list','find','[来源:\x20','[翰林院-日志]\x20统计成功,向量总数:\x20','94480ptGPUY','messageTypes','操作已取消。','\x20-\x20楼层\x20#','小说录入','634570UVhvnL','substring','外部Rerank完成','name','聊天记录\x20#','depth_role','saveProgress','getRequestHeaders','\x20条结果。','[来源:\x20世界书,\x20条目:\x20','filter','enabled','slice','webllm','log','function','user','join','世界书','正在智能分块...','[翰林院-日志]\x20开始清空宝库...','notify','oldId','condensation','rerank','[翰林院-日志]\x20/api/vector/purge\x20响应状态:\x20','toLocaleString','(已锁定:\x20','[翰林院-核心]\x20已锁定忆识宝库ID:\x20','输入文本为空','push','21445LqJvNd','final_score','\x0a{},_0x4e9140=null,_0x41f364=()=>{},_0x3905af=()=>{},_0x18d9cc=null,_0x5606cc=0x0,_0xc20e48=null){const _0x276cb5=_0x4a685c;if(!_0x35fd35||!_0x35fd35[_0x276cb5(0xde)]())return{'success':![],'error':_0x276cb5(0x118)};if(!settings)return{'success':![],'error':_0x276cb5(0x137)};try{let _0x5ebc47=await getCollectionId();const _0x4486d2=getCollectionIdInfo();if(_0x4486d2[_0x276cb5(0x111)]&&_0x4486d2[_0x276cb5(0x111)]===_0x5ebc47&&_0x4486d2[_0x276cb5(0x111)]!==_0x4486d2[_0x276cb5(0x11f)]){const _0x43c261=confirm(_0x276cb5(0xba));if(_0x43c261)_0x41f364(_0x276cb5(0x134)+_0x4486d2[_0x276cb5(0x111)],_0x276cb5(0xc6)),await purgeStorage(_0x4486d2[_0x276cb5(0x111)]),_0x5ebc47=_0x4486d2[_0x276cb5(0x11f)],_0x41f364('[翰林院-迁移]\x20旧宝库已清空,将向新宝库写入数据:\x20'+_0x5ebc47,_0x276cb5(0xd1));else return _0x41f364(_0x276cb5(0xac),'info'),toastr[_0x276cb5(0xe2)](_0x276cb5(0xf8)),{'success':![],'error':'用户取消了迁移操作'};}if(!_0x5ebc47)throw new Error(_0x276cb5(0xe6));_0x41f364(_0x276cb5(0x117)+_0x5ebc47,_0x276cb5(0xe2)),_0x1d2fe6({'message':_0x276cb5(0x10e),'processed':0x0,'total':0x1});const _0x2b682f=splitIntoChunks(_0x35fd35,_0x5470e4,{'sourceName':_0x42d390}),_0x3bf271=_0x2b682f[_0x276cb5(0xe1)];if(_0x4e9140?.['aborted'])throw new Error(_0x276cb5(0xa4));_0x41f364(_0x276cb5(0xc7)+(_0x42d390||_0x5470e4)+_0x276cb5(0x13e)+_0x3bf271+'\x20个块。',_0x276cb5(0xe2));if(_0x3bf271===0x0)return{'success':!![],'count':0x0};const _0x1b6344=settings['retrieval']['batchSize']||0x5;let _0x9fa417=_0x5606cc;for(let _0x3fed2e=_0x5606cc;_0x3fed2e<_0x3bf271;_0x3fed2e+=_0x1b6344){if(_0x4e9140?.[_0x276cb5(0xd7)])throw new Error('AbortError');const _0x3c8909=_0x2b682f[_0x276cb5(0x107)](_0x3fed2e,_0x3fed2e+_0x1b6344);_0x1d2fe6({'message':_0x276cb5(0xad)+(_0x3fed2e+0x1)+'-'+(_0x3fed2e+_0x3c8909[_0x276cb5(0xe1)])+'\x20块','processed':_0x3fed2e,'total':_0x3bf271});const _0x5722d5=_0x3c8909['map'](_0x1ae7b1=>_0x1ae7b1[_0x276cb5(0x139)]),_0x440d22=await getEmbeddings(_0x5722d5,_0x4e9140);if(_0x4e9140?.['aborted'])throw new Error(_0x276cb5(0xa4));if(_0x3c8909[_0x276cb5(0xe1)]!==_0x440d22[_0x276cb5(0xe1)])throw new Error(_0x276cb5(0x9a));const _0x14f3a5=_0x3c8909['map']((_0x349e44,_0x105c24)=>({..._0x349e44,'vector':_0x440d22[_0x105c24]}));await insertVectors(_0x14f3a5,_0x4e9140,_0x5ebc47),_0x9fa417+=_0x3c8909[_0x276cb5(0xe1)],_0x18d9cc&&_0x20bfcb[_0x276cb5(0x101)](_0x18d9cc,_0x9fa417,_0x3bf271),_0x3905af();}_0x18d9cc&&_0x20bfcb[_0x276cb5(0xec)](_0x18d9cc);if(_0xc20e48){const _0x4cff28=await getCollectionId(),_0x17764e=_0xc20e48[_0x276cb5(0xb3)]===0x0?context[_0x276cb5(0xb0)]['length']:_0xc20e48[_0x276cb5(0xb3)];settings[_0x276cb5(0x12e)][_0x4cff28]={'start':_0xc20e48['start'],'end':_0x17764e,'timestamp':new Date()['toISOString']()},saveSettings(),_0x41f364('[翰林院-核心]\x20已为宝库\x20'+_0x4cff28+_0x276cb5(0xce)+_0xc20e48[_0x276cb5(0xd5)]+'-'+_0x17764e,_0x276cb5(0xe2));}return _0x41f364(_0x276cb5(0x13d)+_0x9fa417+'\x20个向量条目。',_0x276cb5(0xd1)),{'success':!![],'count':_0x9fa417};}catch(_0x145ef8){if(_0x145ef8[_0x276cb5(0xfe)]===_0x276cb5(0xa4)){_0x41f364(_0x276cb5(0x132),_0x276cb5(0xc6));throw _0x145ef8;}return console[_0x276cb5(0xe0)](_0x276cb5(0xd4),_0x145ef8),_0x41f364('[翰林院-核心]\x20文本录入失败:\x20'+_0x145ef8[_0x276cb5(0xd0)],_0x276cb5(0xe0)),{'success':![],'error':_0x145ef8['message']};}}function getSettings(){const _0x4adc09=_0x4a685c;if(!context||!context[_0x4adc09(0xda)])return structuredClone(_0x50292a);let _0x237086=context[_0x4adc09(0xda)][MODULE_NAME];!_0x237086&&(_0x237086={},context[_0x4adc09(0xda)][MODULE_NAME]=_0x237086);_0x237086[_0x4adc09(0x12e)]===undefined&&(_0x237086[_0x4adc09(0x12e)]={});for(const _0x2cc91d in _0x50292a){if(_0x237086[_0x2cc91d]===undefined)_0x237086[_0x2cc91d]=structuredClone(_0x50292a[_0x2cc91d]);else{if(typeof _0x50292a[_0x2cc91d]==='object'&&!Array[_0x4adc09(0xc2)](_0x50292a[_0x2cc91d])&&_0x50292a[_0x2cc91d]!==null)for(const _0x36be81 in _0x50292a[_0x2cc91d]){_0x237086[_0x2cc91d][_0x36be81]===undefined&&(_0x237086[_0x2cc91d][_0x36be81]=_0x50292a[_0x2cc91d][_0x36be81]);}}}return _0x237086;}function saveSettings(){const _0x581eb1=_0x4a685c;if(context)context[_0x581eb1(0xee)]();}function resetSettings(){const _0x2e456a=_0x4a685c;context&&(context[_0x2e456a(0xda)][MODULE_NAME]=structuredClone(_0x50292a),saveSettings());}function showNotification(_0x16cb5e,_0x14b828=_0x4a685c(0xe2)){toastr[_0x14b828](_0x16cb5e);}function getTagForSource(_0x19c253){const _0x24b56e=_0x4a685c;switch(_0x19c253){case _0x24b56e(0xc4):return _0x24b56e(0xbc);case _0x24b56e(0x120):return _0x24b56e(0x10d);case _0x24b56e(0xb9):return _0x24b56e(0xa3);case _0x24b56e(0x124):return _0x24b56e(0xfa);default:return'资料';}}function splitIntoChunks(_0x264df0,_0x35d097,_0x4331c4={}){const _0x20d2ba=_0x4a685c;switch(_0x35d097){case _0x20d2ba(0x124):return _chunkForNovel(_0x264df0,_0x4331c4);case _0x20d2ba(0xc4):return _chunkForChatHistory(_0x264df0,_0x4331c4);case'lorebook':return _chunkForLorebook(_0x264df0,_0x4331c4);case _0x20d2ba(0xb9):return _chunkForManual(_0x264df0,_0x4331c4);default:console[_0x20d2ba(0xc6)](_0x20d2ba(0xe5)+_0x35d097+_0x20d2ba(0x123));return _chunkForManual(_0x264df0,{..._0x4331c4,'sourceName':_0x4331c4[_0x20d2ba(0x11d)]||_0x20d2ba(0xe7)});}}function _chunkForNovel(_0x1b90f9,_0x290961){const _0x20022c=_0x4a685c,{chunkSize:_0x28dfad,overlap:_0x3540d6}=settings['advanced'],{sourceName:sourceName='小说'}=_0x290961,_0x4db620=[];if(!_0x1b90f9||_0x28dfad<=0x0)return _0x4db620;const _0xbb125f=/(第\s*[一二三四五六七八九十百千万零\d]+\s*卷)/gim,_0x1872e4=/(第\s*[一二三四五六七八九十百千万零\d]+\s*[章回节部])|^(Chapter\s+\d+)/gim;let _0x2157cb=0x0;const _0x21f23f=_0x1b90f9[_0x20022c(0x9b)]('\x0a');let _0x5a669c=_0x20022c(0xa2),_0x2b954b=_0x20022c(0xd9),_0x18e5a4=[];function _0x36e689(){const _0x1df18c=_0x20022c;if(_0x18e5a4[_0x1df18c(0xe1)]===0x0)return;const _0x421b82=_0x18e5a4[_0x1df18c(0x10c)]('\x0a');let _0x298d18=0x0,_0x297faa=0x1;while(_0x298d18<_0x421b82[_0x1df18c(0xe1)]){const _0x243838=Math[_0x1df18c(0xbd)](_0x298d18+_0x28dfad,_0x421b82[_0x1df18c(0xe1)]),_0x4270a4=_0x421b82[_0x1df18c(0xfc)](_0x298d18,_0x243838);if(_0x4270a4[_0x1df18c(0xde)]()[_0x1df18c(0xe1)]>0x0){const _0x36dce0={'source':_0x1df18c(0x124),'sourceName':sourceName,'timestamp':new Date()[_0x1df18c(0x91)](),'globalIndex':_0x2157cb++,'volume':_0x5a669c,'chapter':_0x2b954b,'section':_0x297faa},_0x3663b8=getTagForSource('novel'),_0x38778a=_0x1df18c(0xf4)+sourceName+',\x20'+_0x5a669c+',\x20'+_0x2b954b+_0x1df18c(0x129)+_0x297faa+'节]',_0x53ada9='<'+_0x3663b8+'>\x0a'+_0x38778a+'\x0a'+_0x4270a4+_0x1df18c(0x11c)+_0x3663b8+'>';_0x4db620[_0x1df18c(0x119)]({'text':_0x53ada9,'metadata':_0x36dce0}),_0x297faa++;}_0x298d18+=_0x28dfad-_0x3540d6;if(_0x298d18>=_0x421b82[_0x1df18c(0xe1)])break;}_0x18e5a4=[];}for(const _0xef2769 of _0x21f23f){const _0x410900=_0xef2769[_0x20022c(0xde)]();if(_0xbb125f['test'](_0x410900))_0x36e689(),_0x5a669c=_0x410900,_0x2b954b=_0x20022c(0xd9);else _0x1872e4[_0x20022c(0x98)](_0x410900)?(_0x36e689(),_0x2b954b=_0x410900):_0x18e5a4[_0x20022c(0x119)](_0xef2769);}_0x36e689();if(_0x4db620[_0x20022c(0xe1)]===0x0&&_0x1b90f9['length']>0x0){let _0x250dd3=0x0,_0xa22d9e=0x1;while(_0x250dd3<_0x1b90f9[_0x20022c(0xe1)]){const _0x302642=Math[_0x20022c(0xbd)](_0x250dd3+_0x28dfad,_0x1b90f9[_0x20022c(0xe1)]),_0x14476f=_0x1b90f9['substring'](_0x250dd3,_0x302642),_0x3a7c93={'source':_0x20022c(0x124),'sourceName':sourceName,'timestamp':new Date()[_0x20022c(0x91)](),'globalIndex':_0x4db620[_0x20022c(0xe1)],'volume':_0x20022c(0xa2),'chapter':_0x20022c(0xd9),'section':_0xa22d9e},_0x28ec3c=getTagForSource(_0x20022c(0x124)),_0x2f1303=_0x20022c(0xf4)+sourceName+_0x20022c(0xe8)+_0xa22d9e+'节]',_0x3d71ec='<'+_0x28ec3c+'>\x0a'+_0x2f1303+'\x0a'+_0x14476f+'\x0a';_0x4db620[_0x20022c(0x119)]({'text':_0x3d71ec,'metadata':_0x3a7c93}),_0xa22d9e++,_0x250dd3+=_0x28dfad-_0x3540d6;}}return _0x4db620;}function _chunkForChatHistory(_0x17a8f9,_0xc0184c){const _0x4df133=_0x4a685c,{chunkSize:_0x5589bb,overlap:_0x399ede}=settings[_0x4df133(0xa1)],{floor:_0x54a67f,is_user:_0x40df49,timestamp:_0xc668ed}=_0xc0184c,_0x27560a=[];if(!_0x17a8f9||_0x5589bb<=0x0)return _0x27560a;let _0x4e567b=0x1,_0x142ed7=0x0;while(_0x142ed7<_0x17a8f9[_0x4df133(0xe1)]){const _0x49fc92=Math[_0x4df133(0xbd)](_0x142ed7+_0x5589bb,_0x17a8f9[_0x4df133(0xe1)]),_0x188434=_0x17a8f9['substring'](_0x142ed7,_0x49fc92),_0x47a75e=_0x4df133(0x125)+_0x54a67f+_0x4df133(0x129)+_0x4e567b+_0x4df133(0x97),_0x2a7d39=getTagForSource(_0x4df133(0xc4)),_0x1cb927='<'+_0x2a7d39+'>\x0a'+_0x47a75e+'\x0a'+_0x188434+_0x4df133(0x11c)+_0x2a7d39+'>';_0x27560a['push']({'text':_0x1cb927,'metadata':{'source':'chat_history','sourceName':_0x4df133(0xff)+_0x54a67f,'floor':_0x54a67f,'part':_0x4e567b,'is_user':_0x40df49,'timestamp':_0xc668ed}}),_0x4e567b++,_0x142ed7+=_0x5589bb-_0x399ede;if(_0x142ed7>=_0x17a8f9['length'])break;}return _0x27560a;}function _chunkForLorebook(_0x18ca69,_0x55d1fc){const _0x16f789=_0x4a685c,{chunkSize:_0x1ab46b,overlap:_0x450038}=settings[_0x16f789(0xa1)],{sourceName:sourceName=_0x16f789(0x13f)}=_0x55d1fc,_0x1042c8=[];if(!_0x18ca69||_0x1ab46b<=0x0)return _0x1042c8;let _0x503702=0x1,_0x42970b=0x0;while(_0x42970b<_0x18ca69[_0x16f789(0xe1)]){const _0x36b0be=Math[_0x16f789(0xbd)](_0x42970b+_0x1ab46b,_0x18ca69[_0x16f789(0xe1)]),_0x2344f=_0x18ca69[_0x16f789(0xfc)](_0x42970b,_0x36b0be),_0x16813f=_0x16f789(0x104)+sourceName+_0x16f789(0x129)+_0x503702+_0x16f789(0x97),_0x308dc1=getTagForSource(_0x16f789(0x120)),_0x5c8a5c='<'+_0x308dc1+'>\x0a'+_0x16813f+'\x0a'+_0x2344f+_0x16f789(0x11c)+_0x308dc1+'>';_0x1042c8[_0x16f789(0x119)]({'text':_0x5c8a5c,'metadata':{'source':_0x16f789(0x120),'sourceName':sourceName,'part':_0x503702,'timestamp':new Date()['toISOString']()}}),_0x503702++,_0x42970b+=_0x1ab46b-_0x450038;if(_0x42970b>=_0x18ca69['length'])break;}return _0x1042c8;}function _chunkForManual(_0xf151b6,_0x14fc0a){const _0x1e49ab=_0x4a685c,{chunkSize:_0x456484,overlap:_0x7bc0d0}=settings[_0x1e49ab(0xa1)],{sourceName:sourceName=_0x1e49ab(0xa3)}=_0x14fc0a,_0x49485b=[];if(!_0xf151b6||_0x456484<=0x0)return _0x49485b;const _0x212e84=new Date(),_0x42b285=_0x212e84[_0x1e49ab(0x115)]('zh-CN');let _0x435499=0x1,_0x1febb4=0x0;while(_0x1febb4<_0xf151b6[_0x1e49ab(0xe1)]){const _0x52ebdf=Math['min'](_0x1febb4+_0x456484,_0xf151b6[_0x1e49ab(0xe1)]),_0x506a3b=_0xf151b6[_0x1e49ab(0xfc)](_0x1febb4,_0x52ebdf),_0x539ae0=_0x1e49ab(0xf4)+sourceName+',\x20向量化录入时间:\x20'+_0x42b285+_0x1e49ab(0x129)+_0x435499+_0x1e49ab(0x97),_0x48429f=getTagForSource(_0x1e49ab(0xb9)),_0x4eecf8='<'+_0x48429f+'>\x0a'+_0x539ae0+'\x0a'+_0x506a3b+'\x0a';_0x49485b['push']({'text':_0x4eecf8,'metadata':{'source':_0x1e49ab(0xb9),'sourceName':sourceName,'part':_0x435499,'timestamp':_0x212e84['toISOString']()}}),_0x435499++,_0x1febb4+=_0x456484-_0x7bc0d0;if(_0x1febb4>=_0xf151b6[_0x1e49ab(0xe1)])break;}return _0x49485b;}import{getCollectionId as _0x1c3d83,getCharacterName}from'./utils/context-utils.js';async function getCollectionId(){return lockedCollectionId||await _0x1c3d83();}async function toggleSessionLock(){return lockedCollectionId?(lockedCollectionId=null,![]):(lockedCollectionId=await _0x1c3d83(),!![]);}function isSessionLocked(){return lockedCollectionId!==null;}function getLockedSessionInfo(){const _0x194c9e=_0x4a685c;if(!lockedCollectionId)return null;return{'id':lockedCollectionId,'name':_0x194c9e(0x116)+lockedCollectionId[_0x194c9e(0xfc)](0x0,0x8)+'...)'};}function generateHash(_0xb8933){const _0x40d9a4=_0x4a685c;let _0x1ff27d=0x0;for(let _0x3c2fb3=0x0;_0x3c2fb3<_0xb8933[_0x40d9a4(0xe1)];_0x3c2fb3++){const _0x1b9f4c=_0xb8933['charCodeAt'](_0x3c2fb3);_0x1ff27d=(_0x1ff27d<<0x5)-_0x1ff27d+_0x1b9f4c,_0x1ff27d=_0x1ff27d&_0x1ff27d;}return Math['abs'](_0x1ff27d)[_0x40d9a4(0xef)](0x24);}async function queryVectors(_0x2e20ad){const _0x2b367a=_0x4a685c;console[_0x2b367a(0x109)](_0x2b367a(0xe4));const _0xbd790c=await getCollectionId();console[_0x2b367a(0x109)](_0x2b367a(0xdf)+_0xbd790c);const _0x12f504=(await getEmbeddings([_0x2e20ad]))[0x0],_0x3612fa={'collectionId':_0xbd790c,'searchText':_0x2e20ad,'topK':settings[_0x2b367a(0xa1)][_0x2b367a(0xb5)],'threshold':settings['advanced'][_0x2b367a(0xa7)],'source':_0x2b367a(0x108),'embeddings':{[_0x2e20ad]:_0x12f504}};console[_0x2b367a(0x109)](_0x2b367a(0xea),JSON['stringify'](_0x3612fa,null,0x2));const _0xaab904=await fetch(_0x2b367a(0x136),{'method':_0x2b367a(0xdc),'headers':context[_0x2b367a(0x102)](),'body':JSON[_0x2b367a(0xc5)](_0x3612fa)});console[_0x2b367a(0x109)]('[翰林院-日志]\x20/api/vector/query\x20响应状态:\x20'+_0xaab904[_0x2b367a(0x138)]);if(!_0xaab904['ok']){const _0x4400a4=await _0xaab904[_0x2b367a(0x139)]();console[_0x2b367a(0xe0)](_0x2b367a(0xe3),_0x4400a4);throw new Error(_0x2b367a(0x122)+_0xaab904[_0x2b367a(0x138)]+':\x20'+_0x4400a4);}const _0x282e4d=await _0xaab904[_0x2b367a(0xc8)]();console['log'](_0x2b367a(0x133),_0x282e4d);const _0x4ad4be=_0x282e4d[_0x2b367a(0x142)]||_0x282e4d['results']||_0x282e4d[_0x2b367a(0x9d)]||[];return console[_0x2b367a(0x109)](_0x2b367a(0x140)+_0x4ad4be[_0x2b367a(0xe1)]+_0x2b367a(0x103)),_0x4ad4be;}async function insertVectors(_0x39a150,_0x444d09=null,_0x1b491b){const _0x4d731b=_0x4a685c;if(!_0x1b491b){console['error']('[翰林院-核心]\x20insertVectors被调用时未提供collectionId!'),_0x1b491b=await getCollectionId();if(!_0x1b491b)throw new Error('在insertVectors内部也无法获取collectionId');}if(_0x39a150[_0x4d731b(0xe1)]===0x0)return{'success':!![],'count':0x0};const _0x56b3e5=_0x39a150[_0x4d731b(0xb7)]((_0x5f511b,_0x412fa8)=>({'hash':generateHash(_0x5f511b[_0x4d731b(0x139)]+Date[_0x4d731b(0x128)]()+_0x412fa8),'text':_0x5f511b['text'],'metadata':_0x5f511b[_0x4d731b(0x142)]||{'source':_0x4d731b(0xb1),'timestamp':new Date()['toISOString']()}})),_0x579776=_0x56b3e5[_0x4d731b(0x127)]((_0x93966b,_0x1359bb,_0x5be7f3)=>{const _0x1b3af5=_0x4d731b;return _0x93966b[_0x1359bb['text']]=_0x39a150[_0x5be7f3][_0x1b3af5(0x141)],_0x93966b;},{}),_0xbd41f6={'collectionId':_0x1b491b,'items':_0x56b3e5,'source':_0x4d731b(0x108),'embeddings':_0x579776},_0x3fe85f=await fetch('/api/vector/insert',{'method':'POST','headers':context[_0x4d731b(0x102)](),'body':JSON[_0x4d731b(0xc5)](_0xbd41f6),'signal':_0x444d09});if(!_0x3fe85f['ok']){const _0x14fefe=await _0x3fe85f['text']();console[_0x4d731b(0xe0)](_0x4d731b(0xd3),_0x14fefe);throw new Error('忆识存入API错误\x20'+_0x3fe85f[_0x4d731b(0x138)]+':\x20'+_0x14fefe);}return{'success':!![],'count':_0x56b3e5[_0x4d731b(0xe1)]};}async function getVectorCount(){const _0xfe1199=_0x4a685c;console[_0xfe1199(0x109)](_0xfe1199(0x12c));const _0x5c172b=await getCollectionId();console[_0xfe1199(0x109)]('[翰林院-日志]\x20统计目标集合ID:\x20'+_0x5c172b);const _0x5abe3b={'collectionId':_0x5c172b,'source':_0xfe1199(0x108),'embeddings':{}};console[_0xfe1199(0x109)]('[翰林院-日志]\x20发送到\x20/api/vector/list\x20的请求体:',JSON[_0xfe1199(0xc5)](_0x5abe3b,null,0x2));const _0x372f07=await fetch(_0xfe1199(0xf2),{'method':'POST','headers':context['getRequestHeaders'](),'body':JSON['stringify'](_0x5abe3b)});console[_0xfe1199(0x109)](_0xfe1199(0xed)+_0x372f07[_0xfe1199(0x138)]);if(!_0x372f07['ok']){const _0x3be915=await _0x372f07[_0xfe1199(0x139)]();return console[_0xfe1199(0xe0)]('[翰林院-日志]\x20获取向量列表API错误:',_0x3be915),0x0;}const _0x431d4e=await _0x372f07[_0xfe1199(0xc8)]();let _0x13841e=0x0;if(Array[_0xfe1199(0xc2)](_0x431d4e))_0x13841e=_0x431d4e[_0xfe1199(0xe1)];else _0x431d4e&&_0x431d4e[_0xfe1199(0xd6)]&&(_0x13841e=_0x431d4e[_0xfe1199(0xd6)]['length']);return console['log'](_0xfe1199(0xf5)+_0x13841e),_0x13841e;}async function purgeStorage(_0x315efd=null){const _0x1a8137=_0x4a685c;console[_0x1a8137(0x109)](_0x1a8137(0x10f));const _0x473b8d=_0x315efd||await getCollectionId();if(!_0x473b8d)return console[_0x1a8137(0xe0)]('[翰林院-日志]\x20无法确定要清空的目标集合ID。'),toastr[_0x1a8137(0xe0)](_0x1a8137(0x12d)),![];console['log'](_0x1a8137(0xa8)+_0x473b8d);const _0x345c77={'collectionId':_0x473b8d};console[_0x1a8137(0x109)](_0x1a8137(0xa0),JSON[_0x1a8137(0xc5)](_0x345c77,null,0x2));const _0x397c56=await fetch(_0x1a8137(0x12f),{'method':_0x1a8137(0xdc),'headers':context[_0x1a8137(0x102)](),'body':JSON['stringify'](_0x345c77)});console['log'](_0x1a8137(0x114)+_0x397c56[_0x1a8137(0x138)]);if(!_0x397c56['ok']){const _0x307975=await _0x397c56[_0x1a8137(0x139)]();console['error']('[翰林院-日志]\x20清空宝库API错误:',_0x307975);}else console[_0x1a8137(0x109)](_0x1a8137(0x90));return _0x397c56['ok'];}function getMessagesForCondensation(_0x53bf56=null){const _0x250cb8=_0x4a685c;if(!settings[_0x250cb8(0x112)][_0x250cb8(0x106)])return showNotification(_0x250cb8(0x13b),_0x250cb8(0xb6)),[];const {layerStart:_0x2ba711,layerEnd:_0x4f2cc4}=settings['condensation'],_0x53d29f=_0x53bf56||settings[_0x250cb8(0x112)][_0x250cb8(0xf7)],_0x116b94=context[_0x250cb8(0xb0)][_0x250cb8(0xe1)],_0x4016e3=Math[_0x250cb8(0x131)](0x0,_0x2ba711-0x1),_0xce9e8f=_0x4f2cc4===0x0||_0x4f2cc4>_0x116b94?_0x116b94:Math[_0x250cb8(0xbd)](_0x116b94,_0x4f2cc4),_0x5e91c6=context[_0x250cb8(0xb0)]['slice'](_0x4016e3,_0xce9e8f);return _0x5e91c6[_0x250cb8(0x105)](_0x45faff=>{const _0x24e075=_0x250cb8,_0x2d2597=_0x45faff['is_user']===!![],_0x1578a3=_0x45faff['is_user']===![];if(!_0x45faff[_0x24e075(0xab)]||!_0x45faff[_0x24e075(0xab)][_0x24e075(0xde)]())return![];return _0x53d29f[_0x24e075(0x10b)]&&_0x2d2597||_0x53d29f['ai']&&_0x1578a3;});}async function processCondensation(_0x22f33d,_0x2b8b4c=()=>{},_0x14e488=null){const _0x356b03=_0x4a685c;if(!_0x22f33d||_0x22f33d[_0x356b03(0xe1)]===0x0)return{'success':![],'error':_0x356b03(0x126)};try{let _0xd6ddbd=await getCollectionId();const _0x4a729b=getCollectionIdInfo();if(_0x4a729b[_0x356b03(0x111)]&&_0x4a729b[_0x356b03(0x111)]===_0xd6ddbd&&_0x4a729b['oldId']!==_0x4a729b[_0x356b03(0x11f)]){const _0x1ff9af=confirm(_0x356b03(0xba));if(_0x1ff9af)_0x2b8b4c('[翰林院-迁移]\x20用户确认迁移,正在清空旧宝库:\x20'+_0x4a729b[_0x356b03(0x111)],_0x356b03(0xc6)),await purgeStorage(_0x4a729b['oldId']),_0xd6ddbd=_0x4a729b['newId'],_0x2b8b4c(_0x356b03(0x94)+_0xd6ddbd,_0x356b03(0xd1));else return _0x2b8b4c(_0x356b03(0xac),_0x356b03(0xe2)),toastr[_0x356b03(0xe2)](_0x356b03(0xf8)),{'success':![],'error':_0x356b03(0xbf)};}if(!_0xd6ddbd)throw new Error(_0x356b03(0xe6));_0x2b8b4c(_0x356b03(0xaa)+_0xd6ddbd,_0x356b03(0xe2));const _0x55b35a=[],_0x27aff8=context[_0x356b03(0xb0)];for(const _0x1f3e15 of _0x22f33d){const _0x1dea84=(_0x1f3e15['mes']||'')[_0x356b03(0xcf)](/<[^>]*>/g,'')['trim']();if(_0x1dea84[_0x356b03(0xe1)]===0x0)continue;let _0x5d96cb;if(_0x1f3e15['floor']!==undefined&&_0x1f3e15[_0x356b03(0xd2)]!==null)_0x5d96cb=_0x1f3e15[_0x356b03(0xd2)];else{const _0xb70902=_0x27aff8[_0x356b03(0xbe)](_0x44b7e9=>_0x44b7e9===_0x1f3e15);_0x5d96cb=_0xb70902!==-0x1?_0xb70902+0x1:-0x1;}const _0x834f72=new Date(_0x1f3e15[_0x356b03(0xc1)]),_0x2dc978=isNaN(_0x834f72['getTime']())?new Date()[_0x356b03(0x91)]():_0x834f72['toISOString'](),_0x19b01d=splitIntoChunks(_0x1dea84,_0x356b03(0xc4),{'floor':_0x5d96cb,'is_user':_0x1f3e15[_0x356b03(0x130)],'timestamp':_0x2dc978});_0x55b35a[_0x356b03(0x119)](..._0x19b01d);}if(_0x55b35a[_0x356b03(0xe1)]===0x0)return{'success':!![],'count':0x0};_0x2b8b4c(_0x356b03(0xcb)+_0x22f33d[_0x356b03(0xe1)]+'\x20条消息分解为\x20'+_0x55b35a[_0x356b03(0xe1)]+_0x356b03(0xc0),_0x356b03(0xe2));const _0x54e353=settings['retrieval'][_0x356b03(0xcc)]||0x5;let _0x2a698f=0x0;for(let _0x45cfbd=0x0;_0x45cfbd<_0x55b35a[_0x356b03(0xe1)];_0x45cfbd+=_0x54e353){const _0x37e7d9=_0x55b35a[_0x356b03(0x107)](_0x45cfbd,_0x45cfbd+_0x54e353),_0x5641a8=_0x37e7d9['map'](_0x45b3f7=>_0x45b3f7[_0x356b03(0x139)]),_0xfc6e2e=await getEmbeddings(_0x5641a8);if(_0x37e7d9[_0x356b03(0xe1)]!==_0xfc6e2e[_0x356b03(0xe1)])throw new Error(_0x356b03(0x9a));const _0x579951=_0x37e7d9['map']((_0xa2ff,_0x1dea0d)=>({..._0xa2ff,'vector':_0xfc6e2e[_0x1dea0d]}));await insertVectors(_0x579951,null,_0xd6ddbd),_0x2a698f+=_0x37e7d9[_0x356b03(0xe1)];}if(_0x14e488){const _0x331fe0=_0x14e488[_0x356b03(0xb3)]===0x0?context[_0x356b03(0xb0)][_0x356b03(0xe1)]:_0x14e488[_0x356b03(0xb3)];settings[_0x356b03(0x12e)][_0xd6ddbd]={'start':_0x14e488['start'],'end':_0x331fe0,'timestamp':new Date()[_0x356b03(0x91)]()},saveSettings(),_0x2b8b4c('[翰林院-核心]\x20已为宝库\x20'+_0xd6ddbd+_0x356b03(0xce)+_0x14e488['start']+'-'+_0x331fe0,_0x356b03(0xe2));}_0x2b8b4c('[翰林院-核心]\x20聊天记录凝识完成,成功插入\x20'+_0x2a698f+_0x356b03(0xd8),_0x356b03(0xd1));const _0x1a2bc3=_0x22f33d[_0x356b03(0xb7)](_0x20951d=>{const _0x48825d=_0x356b03,_0x183861=_0x27aff8['findIndex'](_0x15e3f6=>_0x15e3f6===_0x20951d),_0x1bc9d5=_0x183861!==-0x1?_0x183861+0x1:-0x1,_0x536c78=_0x20951d[_0x48825d(0x130)]?'用户':getCharacterName()||'AI';return'['+_0x536c78+_0x48825d(0xf9)+_0x1bc9d5+']\x20的消息已成功凝识。';});return{'success':!![],'count':_0x2a698f,'messages':_0x1a2bc3};}catch(_0x455aa4){return console[_0x356b03(0xe0)]('[翰林院-核心]\x20processCondensation\x20失败:',_0x455aa4),_0x2b8b4c(_0x356b03(0xb2)+_0x455aa4['message'],'error'),{'success':![],'error':_0x455aa4[_0x356b03(0xd0)]};}}async function rerankResults(_0x5e074d,_0x1b25ba,_0x42f666){const _0x5b3dee=_0x4a685c;let _0x5c181e=_0x5e074d;if(_0x42f666[_0x5b3dee(0x113)][_0x5b3dee(0x106)]&&_0x5e074d[_0x5b3dee(0xe1)]>0x0){console[_0x5b3dee(0x109)]('[翰林院-Rerank]\x20开始外部API重排序...');try{const _0x431fb8=_0x5e074d[_0x5b3dee(0xb7)](_0xfb4d56=>_0xfb4d56[_0x5b3dee(0x139)]),_0x23b130=await executeRerank(_0x1b25ba,_0x431fb8,_0x42f666['rerank']),_0x388154=_0x5e074d[_0x5b3dee(0xb7)]((_0x1097ea,_0x3e05a0)=>({..._0x1097ea,'original_index':_0x3e05a0}));_0x5c181e=_0x388154[_0x5b3dee(0xb7)](_0x6a3183=>{const _0x32a263=_0x5b3dee,_0x227e2e=_0x23b130[_0x32a263(0x95)][_0x32a263(0xf3)](_0x2f0a91=>_0x2f0a91[_0x32a263(0xb4)]===_0x6a3183['original_index']),_0x52d2ab=_0x227e2e?_0x227e2e[_0x32a263(0xaf)]:0x0;return{..._0x6a3183,'rerank_score':_0x52d2ab};});if(_0x42f666[_0x5b3dee(0x113)][_0x5b3dee(0x110)])showNotification(_0x5b3dee(0xfd),_0x5b3dee(0xd1));}catch(_0x13906d){console[_0x5b3dee(0xe0)](_0x5b3dee(0x9c),_0x13906d);if(_0x42f666[_0x5b3dee(0x113)]['notify'])showNotification(_0x5b3dee(0xcd)+_0x13906d['message'],_0x5b3dee(0xe0));_0x5c181e[_0x5b3dee(0xc3)](_0x496d72=>_0x496d72[_0x5b3dee(0xae)]=0x0);}}else _0x5c181e[_0x5b3dee(0xc3)](_0xc97ea=>_0xc97ea['rerank_score']=0x0);console[_0x5b3dee(0x109)](_0x5b3dee(0x13c));const _0xb7160d=context[_0x5b3dee(0xb0)]['length'],_0x3cddaa=_0x42f666[_0x5b3dee(0x113)]['hybrid_alpha'],_0x39956b=_0x5c181e[_0x5b3dee(0xb7)](_0x2efa71=>{const _0x473219=_0x5b3dee;let _0x3c1ede=0x1;const _0x4c36ba=_0x2efa71[_0x473219(0x142)]||{};switch(_0x4c36ba[_0x473219(0x135)]){case _0x473219(0x120):_0x3c1ede*=1.2;break;case _0x473219(0xb9):_0x3c1ede*=1.1;break;case _0x473219(0xc4):if(_0x4c36ba[_0x473219(0xd2)]&&_0xb7160d>0x0){const _0x14ba91=_0x4c36ba[_0x473219(0xd2)]/_0xb7160d;_0x3c1ede*=0x1+_0x14ba91;}break;}const _0x834b14=_0x2efa71[_0x473219(0xae)]*_0x3cddaa+(_0x2efa71[_0x473219(0x93)]||0x0)*(0x1-_0x3cddaa),_0x51735d=_0x834b14*_0x3c1ede;return{..._0x2efa71,'final_score':_0x51735d};});return _0x39956b[_0x5b3dee(0x121)]((_0x3c0b60,_0x57fa75)=>(_0x57fa75[_0x5b3dee(0x11b)]||0x0)-(_0x3c0b60[_0x5b3dee(0x11b)]||0x0)),console[_0x5b3dee(0x109)](_0x5b3dee(0xa9)),_0x39956b[_0x5b3dee(0x107)](0x0,_0x42f666[_0x5b3dee(0x113)][_0x5b3dee(0x96)]);}async function rearrangeChat(_0xf724a6,_0x492ad2,_0x3a3b16,_0x1faf8b){const _0x18428b=_0x4a685c;setExtensionPrompt('HANLINYUAN_RAG','',settings[_0x18428b(0xdb)][_0x18428b(0x92)],settings[_0x18428b(0xdb)][_0x18428b(0xf1)],![],settings[_0x18428b(0xdb)]['depth_role']);if(_0x1faf8b===_0x18428b(0xca)||!settings[_0x18428b(0x11e)][_0x18428b(0x106)])return;const _0x17cd1f=_0xf724a6['slice'](-settings[_0x18428b(0xa1)]['queryMessageCount']);if(_0x17cd1f['length']===0x0)return;const _0x21f846=_0x17cd1f['map'](_0x2c4f91=>_0x2c4f91['mes'])['join']('\x20')['replace'](/<[^>]*>/g,'')[_0x18428b(0xde)]();if(!_0x21f846)return;try{const _0x261782=await queryVectors(_0x21f846);if(_0x261782['length']===0x0)return;const _0xb0ec62=await rerankResults(_0x261782,_0x21f846,settings);if(_0xb0ec62[_0x18428b(0xe1)]===0x0)return;const _0x7ecfdb=_0xb0ec62[_0x18428b(0xb7)](_0x58d706=>_0x58d706[_0x18428b(0x139)])[_0x18428b(0x10c)]('\x0a\x0a'),_0xca4d52=settings[_0x18428b(0xdb)][_0x18428b(0x99)][_0x18428b(0xcf)](_0x18428b(0xbb),_0x7ecfdb);setExtensionPrompt(_0x18428b(0x13a),_0xca4d52,settings[_0x18428b(0xdb)][_0x18428b(0x92)],settings[_0x18428b(0xdb)]['depth'],![],settings['injection'][_0x18428b(0x100)]);}catch(_0x2c9546){console['error'](_0x18428b(0xa6),_0x2c9546);if(settings[_0x18428b(0x11e)][_0x18428b(0x110)])showNotification(_0x18428b(0xa5)+_0x2c9546[_0x18428b(0xd0)],_0x18428b(0xe0));}} +'use strict';const _0x21dada=_0x3643;(function(_0x2f29c9,_0x59f8d4){const _0x5aed3a=_0x3643,_0x14823d=_0x2f29c9();while(!![]){try{const _0x56ae6f=-parseInt(_0x5aed3a(0xf3))/0x1+-parseInt(_0x5aed3a(0xb3))/0x2+parseInt(_0x5aed3a(0xc1))/0x3*(parseInt(_0x5aed3a(0xf9))/0x4)+parseInt(_0x5aed3a(0x115))/0x5+-parseInt(_0x5aed3a(0xc8))/0x6*(parseInt(_0x5aed3a(0xf6))/0x7)+-parseInt(_0x5aed3a(0x10b))/0x8*(-parseInt(_0x5aed3a(0xce))/0x9)+-parseInt(_0x5aed3a(0xf1))/0xa*(-parseInt(_0x5aed3a(0x124))/0xb);if(_0x56ae6f===_0x59f8d4)break;else _0x14823d['push'](_0x14823d['shift']());}catch(_0x22b763){_0x14823d['push'](_0x14823d['shift']());}}}(_0x516b,0xa8737));import{extension_prompt_roles,setExtensionPrompt}from'/script.js';import*as _0x621bda from'./utils/context-utils.js';import{getCollectionIdInfo}from'./utils/context-utils.js';function _0x3643(_0x2d055b,_0x16410b){const _0x516b6c=_0x516b();return _0x3643=function(_0x3643c2,_0x257201){_0x3643c2=_0x3643c2-0x98;let _0x3cce1f=_0x516b6c[_0x3643c2];return _0x3cce1f;},_0x3643(_0x2d055b,_0x16410b);}import{defaultSettings as _0x5d7c5d}from'./rag-settings.js';import*as _0x4feb85 from'./ingestion-manager.js';import{getEmbeddings,fetchEmbeddingModels as _0x2bfd94,fetchRerankModels as _0x5afeac,executeRerank,testApiConnection as _0x5f3e1c}from'./rag-api.js';const MODULE_NAME=_0x21dada(0xa8),OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME='vectors_rearrangeChat';let context=null,settings=null,lockedCollectionId=null;export{initialize,getSettings,saveSettings,resetSettings,_0x5f3e1c as testApiConnection,_0x2bfd94 as fetchEmbeddingModels,_0x5afeac as fetchRerankModels,getVectorCount,purgeStorage,getMessagesForCondensation,processCondensation,ingestTextToHanlinyuan,getCollectionId,toggleSessionLock,isSessionLocked,getLockedSessionInfo};function _0x516b(){const _0x197f26=['[翰林院-日志]\x20无法确定要清空的目标集合ID。','info','\x20个知识块,准备入库。','[翰林院-核心]\x20凝识任务已锁定忆识宝库ID:\x20','results','oldId','第1卷','forEach','聊天记录\x20#','[翰林院-核心]\x20文本录入失败:\x20','abs','正在处理\x20','忆识检索失败:\x20','retrieval','[翰林院-核心]\x20已为宝库\x20','未知来源','...)','toLocaleString','rerank','POST','toISOString','push','mes','manual','[翰林院-日志]\x20清空宝库API调用成功。','saveSettingsDebounced','newId','\x20个条目。','/api/vector/list','message','log','\x20记录凝识范围:\x20','webllm','substring','now','\x27,使用通用分块逻辑。','hanlinyuan-rag-core','depth','matchThreshold',']\x20的消息已成功凝识。','stringify','condensation','[翰林院-日志]\x20查询目标集合ID:\x20','hybrid_alpha','notify','template','charCodeAt','1637868JHinVF','queryMessageCount',',\x20向量化录入时间:\x20','翰林院忆识核心已启动\x20(V5.1-借壳上市版),已注册全局函数:\x20','end','test','start','sourceName','trim','\x0a{},_0x49bee9=null,_0x5c95cd=()=>{},_0x158276=()=>{},_0xbfe4e=null,_0x1733a2=0x0,_0x38e636=null){const _0x36a565=_0x21dada;if(!_0x1698fd||!_0x1698fd[_0x36a565(0xbb)]())return{'success':![],'error':_0x36a565(0xd3)};if(!settings)return{'success':![],'error':'核心未初始化'};try{let _0x5ec5eb=await getCollectionId();const _0x3d3fcf=getCollectionIdInfo();if(_0x3d3fcf[_0x36a565(0x13c)]&&_0x3d3fcf['oldId']===_0x5ec5eb&&_0x3d3fcf[_0x36a565(0x13c)]!==_0x3d3fcf[_0x36a565(0x9e)]){const _0x3d3cc7=confirm(_0x36a565(0xd1));if(_0x3d3cc7)_0x5c95cd(_0x36a565(0xe1)+_0x3d3fcf['oldId'],_0x36a565(0x132)),await purgeStorage(_0x3d3fcf[_0x36a565(0x13c)]),_0x5ec5eb=_0x3d3fcf[_0x36a565(0x9e)],_0x5c95cd(_0x36a565(0xc6)+_0x5ec5eb,_0x36a565(0x116));else return _0x5c95cd(_0x36a565(0x11c),_0x36a565(0x138)),toastr['info'](_0x36a565(0xe3)),{'success':![],'error':_0x36a565(0x111)};}if(!_0x5ec5eb)throw new Error(_0x36a565(0xe6));_0x5c95cd(_0x36a565(0xf4)+_0x5ec5eb,_0x36a565(0x138)),_0x339f66({'message':_0x36a565(0xe9),'processed':0x0,'total':0x1});const _0x122207=splitIntoChunks(_0x1698fd,_0x448f5b,{'sourceName':_0x1821f0}),_0x4f4238=_0x122207['length'];if(_0x49bee9?.['aborted'])throw new Error(_0x36a565(0x11d));_0x5c95cd(_0x36a565(0xdc)+(_0x1821f0||_0x448f5b)+'\x27的文本分割成\x20'+_0x4f4238+_0x36a565(0x136),_0x36a565(0x138));if(_0x4f4238===0x0)return{'success':!![],'count':0x0};const _0x2dd97a=settings['retrieval']['batchSize']||0x5;let _0x510b25=_0x1733a2;for(let _0x4ae6aa=_0x1733a2;_0x4ae6aa<_0x4f4238;_0x4ae6aa+=_0x2dd97a){if(_0x49bee9?.['aborted'])throw new Error(_0x36a565(0x11d));const _0x4fe647=_0x122207[_0x36a565(0xc7)](_0x4ae6aa,_0x4ae6aa+_0x2dd97a);_0x339f66({'message':_0x36a565(0x142)+(_0x4ae6aa+0x1)+'-'+(_0x4ae6aa+_0x4fe647[_0x36a565(0xfb)])+'\x20块','processed':_0x4ae6aa,'total':_0x4f4238});const _0x411355=_0x4fe647[_0x36a565(0xcc)](_0x3ec25e=>_0x3ec25e[_0x36a565(0xfa)]),_0xee4fcb=await getEmbeddings(_0x411355,_0x49bee9);if(_0x49bee9?.[_0x36a565(0xd9)])throw new Error('AbortError');if(_0x4fe647['length']!==_0xee4fcb[_0x36a565(0xfb)])throw new Error('文本块和向量数量不匹配');const _0x53d065=_0x4fe647[_0x36a565(0xcc)]((_0xe2747f,_0xd13347)=>({..._0xe2747f,'vector':_0xee4fcb[_0xd13347]}));await insertVectors(_0x53d065,_0x49bee9,_0x5ec5eb),_0x510b25+=_0x4fe647[_0x36a565(0xfb)],_0xbfe4e&&_0x4feb85['saveProgress'](_0xbfe4e,_0x510b25,_0x4f4238),_0x158276();}_0xbfe4e&&_0x4feb85[_0x36a565(0xe0)](_0xbfe4e);if(_0x38e636){const _0x1ff8fb=await getCollectionId(),_0x14fc88=_0x38e636[_0x36a565(0xb7)]===0x0?context['chat'][_0x36a565(0xfb)]:_0x38e636['end'];settings[_0x36a565(0x126)][_0x1ff8fb]={'start':_0x38e636['start'],'end':_0x14fc88,'timestamp':new Date()[_0x36a565(0x98)]()},saveSettings(),_0x5c95cd(_0x36a565(0x145)+_0x1ff8fb+'\x20记录凝识范围:\x20'+_0x38e636['start']+'-'+_0x14fc88,_0x36a565(0x138));}return _0x5c95cd(_0x36a565(0x128)+_0x510b25+_0x36a565(0x10a),'success'),{'success':!![],'count':_0x510b25};}catch(_0x1fca5e){if(_0x1fca5e['name']==='AbortError'){_0x5c95cd(_0x36a565(0xcd),'warn');throw _0x1fca5e;}return console['error'](_0x36a565(0x11f),_0x1fca5e),_0x5c95cd(_0x36a565(0x140)+_0x1fca5e['message'],_0x36a565(0x131)),{'success':![],'error':_0x1fca5e[_0x36a565(0xa1)]};}}function getSettings(){const _0xe78045=_0x21dada;if(!context||!context['extensionSettings'])return structuredClone(_0x5d7c5d);let _0x4cd1c9=context[_0xe78045(0xc9)][MODULE_NAME];!_0x4cd1c9&&(_0x4cd1c9={},context['extensionSettings'][MODULE_NAME]=_0x4cd1c9);_0x4cd1c9[_0xe78045(0x126)]===undefined&&(_0x4cd1c9['condensationHistory']={});for(const _0x3dbd6e in _0x5d7c5d){if(_0x4cd1c9[_0x3dbd6e]===undefined)_0x4cd1c9[_0x3dbd6e]=structuredClone(_0x5d7c5d[_0x3dbd6e]);else{if(typeof _0x5d7c5d[_0x3dbd6e]==='object'&&!Array[_0xe78045(0xcb)](_0x5d7c5d[_0x3dbd6e])&&_0x5d7c5d[_0x3dbd6e]!==null)for(const _0x3326a4 in _0x5d7c5d[_0x3dbd6e]){_0x4cd1c9[_0x3dbd6e][_0x3326a4]===undefined&&(_0x4cd1c9[_0x3dbd6e][_0x3326a4]=_0x5d7c5d[_0x3dbd6e][_0x3326a4]);}}}return _0x4cd1c9;}function saveSettings(){const _0x59f11f=_0x21dada;if(context)context[_0x59f11f(0x9d)]();}function resetSettings(){context&&(context['extensionSettings'][MODULE_NAME]=structuredClone(_0x5d7c5d),saveSettings());}function showNotification(_0x2aa069,_0x20f8bf='info'){toastr[_0x20f8bf](_0x2aa069);}function getTagForSource(_0x4e7fa6){const _0x3bb999=_0x21dada;switch(_0x4e7fa6){case'chat_history':return _0x3bb999(0x118);case _0x3bb999(0x127):return _0x3bb999(0x119);case'manual':return'手动录入';case _0x3bb999(0xc3):return _0x3bb999(0xfe);default:return'资料';}}function splitIntoChunks(_0x5c4386,_0x530244,_0x53bc86={}){const _0xd969ed=_0x21dada;switch(_0x530244){case _0xd969ed(0xc3):return _chunkForNovel(_0x5c4386,_0x53bc86);case'chat_history':return _chunkForChatHistory(_0x5c4386,_0x53bc86);case _0xd969ed(0x127):return _chunkForLorebook(_0x5c4386,_0x53bc86);case _0xd969ed(0x9b):return _chunkForManual(_0x5c4386,_0x53bc86);default:console[_0xd969ed(0x132)](_0xd969ed(0x12a)+_0x530244+_0xd969ed(0xa7));return _chunkForManual(_0x5c4386,{..._0x53bc86,'sourceName':_0x53bc86[_0xd969ed(0xba)]||_0xd969ed(0x146)});}}function _chunkForNovel(_0x2780c4,_0x2dc737){const _0xeaf80e=_0x21dada,{chunkSize:_0x524dd2,overlap:_0x342ecb}=settings[_0xeaf80e(0x122)],{sourceName:sourceName='小说'}=_0x2dc737,_0x4a809c=[];if(!_0x2780c4||_0x524dd2<=0x0)return _0x4a809c;const _0x1e6d54=/(第\s*[一二三四五六七八九十百千万零\d]+\s*卷)/gim,_0x3db885=/(第\s*[一二三四五六七八九十百千万零\d]+\s*[章回节部])|^(Chapter\s+\d+)/gim;let _0x2f6b70=0x0;const _0x436a32=_0x2780c4['split']('\x0a');let _0x5013b6=_0xeaf80e(0x13d),_0x290365='第1章',_0x1fe1f1=[];function _0x3fdb04(){const _0x29b135=_0xeaf80e;if(_0x1fe1f1['length']===0x0)return;const _0x4216b5=_0x1fe1f1['join']('\x0a');let _0x23652e=0x0,_0x1f8219=0x1;while(_0x23652e<_0x4216b5[_0x29b135(0xfb)]){const _0x773fdd=Math['min'](_0x23652e+_0x524dd2,_0x4216b5['length']),_0x2d5d87=_0x4216b5['substring'](_0x23652e,_0x773fdd);if(_0x2d5d87[_0x29b135(0xbb)]()[_0x29b135(0xfb)]>0x0){const _0x425a60={'source':_0x29b135(0xc3),'sourceName':sourceName,'timestamp':new Date()[_0x29b135(0x98)](),'globalIndex':_0x2f6b70++,'volume':_0x5013b6,'chapter':_0x290365,'section':_0x1f8219},_0x30a274=getTagForSource(_0x29b135(0xc3)),_0x4e78fe='[来源:\x20'+sourceName+',\x20'+_0x5013b6+',\x20'+_0x290365+',\x20第'+_0x1f8219+'节]',_0x2cfa86='<'+_0x30a274+'>\x0a'+_0x4e78fe+'\x0a'+_0x2d5d87+_0x29b135(0xbc)+_0x30a274+'>';_0x4a809c[_0x29b135(0x99)]({'text':_0x2cfa86,'metadata':_0x425a60}),_0x1f8219++;}_0x23652e+=_0x524dd2-_0x342ecb;if(_0x23652e>=_0x4216b5[_0x29b135(0xfb)])break;}_0x1fe1f1=[];}for(const _0x3231cf of _0x436a32){const _0x54be34=_0x3231cf['trim']();if(_0x1e6d54[_0xeaf80e(0xb8)](_0x54be34))_0x3fdb04(),_0x5013b6=_0x54be34,_0x290365=_0xeaf80e(0xd0);else _0x3db885[_0xeaf80e(0xb8)](_0x54be34)?(_0x3fdb04(),_0x290365=_0x54be34):_0x1fe1f1['push'](_0x3231cf);}_0x3fdb04();if(_0x4a809c['length']===0x0&&_0x2780c4[_0xeaf80e(0xfb)]>0x0){let _0x698940=0x0,_0x2ada7b=0x1;while(_0x698940<_0x2780c4[_0xeaf80e(0xfb)]){const _0x2fa729=Math[_0xeaf80e(0xd8)](_0x698940+_0x524dd2,_0x2780c4[_0xeaf80e(0xfb)]),_0x299c8f=_0x2780c4[_0xeaf80e(0xa5)](_0x698940,_0x2fa729),_0x4bcc41={'source':_0xeaf80e(0xc3),'sourceName':sourceName,'timestamp':new Date()[_0xeaf80e(0x98)](),'globalIndex':_0x4a809c[_0xeaf80e(0xfb)],'volume':_0xeaf80e(0x13d),'chapter':'第1章','section':_0x2ada7b},_0xe5831a=getTagForSource(_0xeaf80e(0xc3)),_0x3cb90e='[来源:\x20'+sourceName+_0xeaf80e(0x12c)+_0x2ada7b+'节]',_0x481e74='<'+_0xe5831a+'>\x0a'+_0x3cb90e+'\x0a'+_0x299c8f+_0xeaf80e(0xbc)+_0xe5831a+'>';_0x4a809c[_0xeaf80e(0x99)]({'text':_0x481e74,'metadata':_0x4bcc41}),_0x2ada7b++,_0x698940+=_0x524dd2-_0x342ecb;}}return _0x4a809c;}function _chunkForChatHistory(_0x364dfe,_0x3ca137){const _0x1a906d=_0x21dada,{chunkSize:_0x1a5332,overlap:_0x2ec466}=settings[_0x1a906d(0x122)],{floor:_0x1d95c1,is_user:_0x5a2488,timestamp:_0x42e373}=_0x3ca137,_0x1052ff=[];if(!_0x364dfe||_0x1a5332<=0x0)return _0x1052ff;let _0x4b43a8=0x1,_0xa3eacf=0x0;while(_0xa3eacf<_0x364dfe[_0x1a906d(0xfb)]){const _0x2d9ab5=Math[_0x1a906d(0xd8)](_0xa3eacf+_0x1a5332,_0x364dfe['length']),_0x4a7e2c=_0x364dfe[_0x1a906d(0xa5)](_0xa3eacf,_0x2d9ab5),_0x2e851c=_0x1a906d(0xd5)+_0x1d95c1+_0x1a906d(0x108)+_0x4b43a8+_0x1a906d(0xda),_0x415bfa=getTagForSource('chat_history'),_0x3476ae='<'+_0x415bfa+'>\x0a'+_0x2e851c+'\x0a'+_0x4a7e2c+_0x1a906d(0xbc)+_0x415bfa+'>';_0x1052ff[_0x1a906d(0x99)]({'text':_0x3476ae,'metadata':{'source':'chat_history','sourceName':_0x1a906d(0x13f)+_0x1d95c1,'floor':_0x1d95c1,'part':_0x4b43a8,'is_user':_0x5a2488,'timestamp':_0x42e373}}),_0x4b43a8++,_0xa3eacf+=_0x1a5332-_0x2ec466;if(_0xa3eacf>=_0x364dfe[_0x1a906d(0xfb)])break;}return _0x1052ff;}function _chunkForLorebook(_0x28f7a4,_0x376162){const _0x1a7697=_0x21dada,{chunkSize:_0x5c4d02,overlap:_0x1211c7}=settings[_0x1a7697(0x122)],{sourceName:sourceName='世界书条目'}=_0x376162,_0x2f3133=[];if(!_0x28f7a4||_0x5c4d02<=0x0)return _0x2f3133;let _0x8629a6=0x1,_0x115d9d=0x0;while(_0x115d9d<_0x28f7a4['length']){const _0x9b70e1=Math[_0x1a7697(0xd8)](_0x115d9d+_0x5c4d02,_0x28f7a4[_0x1a7697(0xfb)]),_0x53f922=_0x28f7a4[_0x1a7697(0xa5)](_0x115d9d,_0x9b70e1),_0x1b1a5e=_0x1a7697(0x117)+sourceName+_0x1a7697(0x108)+_0x8629a6+_0x1a7697(0xda),_0x4af889=getTagForSource('lorebook'),_0x566cd1='<'+_0x4af889+'>\x0a'+_0x1b1a5e+'\x0a'+_0x53f922+_0x1a7697(0xbc)+_0x4af889+'>';_0x2f3133[_0x1a7697(0x99)]({'text':_0x566cd1,'metadata':{'source':_0x1a7697(0x127),'sourceName':sourceName,'part':_0x8629a6,'timestamp':new Date()[_0x1a7697(0x98)]()}}),_0x8629a6++,_0x115d9d+=_0x5c4d02-_0x1211c7;if(_0x115d9d>=_0x28f7a4[_0x1a7697(0xfb)])break;}return _0x2f3133;}function _chunkForManual(_0x223d9e,_0x5c5004){const _0x496d40=_0x21dada,{chunkSize:_0x20e1c0,overlap:_0x2a7f87}=settings[_0x496d40(0x122)],{sourceName:sourceName='手动录入'}=_0x5c5004,_0x7da435=[];if(!_0x223d9e||_0x20e1c0<=0x0)return _0x7da435;const _0x247d1f=new Date(),_0x5bcde9=_0x247d1f[_0x496d40(0x148)](_0x496d40(0xd7));let _0xdbbc94=0x1,_0x449f5c=0x0;while(_0x449f5c<_0x223d9e['length']){const _0x2355fd=Math[_0x496d40(0xd8)](_0x449f5c+_0x20e1c0,_0x223d9e[_0x496d40(0xfb)]),_0x34cf44=_0x223d9e['substring'](_0x449f5c,_0x2355fd),_0x149e54='[来源:\x20'+sourceName+_0x496d40(0xb5)+_0x5bcde9+',\x20第'+_0xdbbc94+'部分]',_0x291265=getTagForSource('manual'),_0x2cdb76='<'+_0x291265+'>\x0a'+_0x149e54+'\x0a'+_0x34cf44+_0x496d40(0xbc)+_0x291265+'>';_0x7da435['push']({'text':_0x2cdb76,'metadata':{'source':'manual','sourceName':sourceName,'part':_0xdbbc94,'timestamp':_0x247d1f[_0x496d40(0x98)]()}}),_0xdbbc94++,_0x449f5c+=_0x20e1c0-_0x2a7f87;if(_0x449f5c>=_0x223d9e[_0x496d40(0xfb)])break;}return _0x7da435;}import{getCollectionId as _0x11301,getCharacterName}from'./utils/context-utils.js';async function getCollectionId(){return lockedCollectionId||await _0x11301();}async function toggleSessionLock(){return lockedCollectionId?(lockedCollectionId=null,![]):(lockedCollectionId=await _0x11301(),!![]);}function isSessionLocked(){return lockedCollectionId!==null;}function getLockedSessionInfo(){const _0x1b3ece=_0x21dada;if(!lockedCollectionId)return null;return{'id':lockedCollectionId,'name':_0x1b3ece(0x125)+lockedCollectionId['substring'](0x0,0x8)+_0x1b3ece(0x147)};}function generateHash(_0x24dd9c){const _0x4af1c3=_0x21dada;let _0x40f5e9=0x0;for(let _0x58a729=0x0;_0x58a729<_0x24dd9c[_0x4af1c3(0xfb)];_0x58a729++){const _0x3065b2=_0x24dd9c[_0x4af1c3(0xb2)](_0x58a729);_0x40f5e9=(_0x40f5e9<<0x5)-_0x40f5e9+_0x3065b2,_0x40f5e9=_0x40f5e9&_0x40f5e9;}return Math[_0x4af1c3(0x141)](_0x40f5e9)['toString'](0x24);}async function queryVectors(_0x360365){const _0x7f5419=_0x21dada;console[_0x7f5419(0xa2)](_0x7f5419(0xeb));const _0x44fb18=await getCollectionId();console[_0x7f5419(0xa2)](_0x7f5419(0xae)+_0x44fb18);const _0x3c6919=(await getEmbeddings([_0x360365]))[0x0],_0x4124fc={'collectionId':_0x44fb18,'searchText':_0x360365,'topK':settings[_0x7f5419(0x122)]['maxResults'],'threshold':settings[_0x7f5419(0x122)][_0x7f5419(0xaa)],'source':_0x7f5419(0xa4),'embeddings':{[_0x360365]:_0x3c6919}};console[_0x7f5419(0xa2)](_0x7f5419(0x123),JSON[_0x7f5419(0xac)](_0x4124fc,null,0x2));const _0x3d8a23=await fetch('/api/vector/query',{'method':'POST','headers':context['getRequestHeaders'](),'body':JSON[_0x7f5419(0xac)](_0x4124fc)});console[_0x7f5419(0xa2)](_0x7f5419(0xdd)+_0x3d8a23[_0x7f5419(0x105)]);if(!_0x3d8a23['ok']){const _0x79d6dc=await _0x3d8a23['text']();console[_0x7f5419(0x131)](_0x7f5419(0xe8),_0x79d6dc);throw new Error(_0x7f5419(0x12d)+_0x3d8a23[_0x7f5419(0x105)]+':\x20'+_0x79d6dc);}const _0x2243ec=await _0x3d8a23['json']();console[_0x7f5419(0xa2)](_0x7f5419(0x10d),_0x2243ec);const _0xc190ac=_0x2243ec[_0x7f5419(0xe5)]||_0x2243ec['results']||_0x2243ec[_0x7f5419(0x107)]||[];return console[_0x7f5419(0xa2)](_0x7f5419(0xfc)+_0xc190ac[_0x7f5419(0xfb)]+_0x7f5419(0x129)),_0xc190ac;}async function insertVectors(_0x39340,_0x59e526=null,_0x66e773){const _0x212fe6=_0x21dada;if(!_0x66e773){console[_0x212fe6(0x131)](_0x212fe6(0xd2)),_0x66e773=await getCollectionId();if(!_0x66e773)throw new Error(_0x212fe6(0xee));}if(_0x39340[_0x212fe6(0xfb)]===0x0)return{'success':!![],'count':0x0};const _0x50d145=_0x39340['map']((_0x28643b,_0x32ea03)=>({'hash':generateHash(_0x28643b[_0x212fe6(0xfa)]+Date[_0x212fe6(0xa6)]()+_0x32ea03),'text':_0x28643b[_0x212fe6(0xfa)],'metadata':_0x28643b['metadata']||{'source':_0x212fe6(0x104),'timestamp':new Date()['toISOString']()}})),_0x57adfa=_0x50d145[_0x212fe6(0xfd)]((_0x4288b7,_0x7b7f57,_0x3455d3)=>{const _0x177d7c=_0x212fe6;return _0x4288b7[_0x7b7f57[_0x177d7c(0xfa)]]=_0x39340[_0x3455d3][_0x177d7c(0xf8)],_0x4288b7;},{}),_0x3019a2={'collectionId':_0x66e773,'items':_0x50d145,'source':_0x212fe6(0xa4),'embeddings':_0x57adfa},_0x4f73df=await fetch(_0x212fe6(0x10c),{'method':_0x212fe6(0x14a),'headers':context[_0x212fe6(0x11b)](),'body':JSON[_0x212fe6(0xac)](_0x3019a2),'signal':_0x59e526});if(!_0x4f73df['ok']){const _0x5e6bd7=await _0x4f73df[_0x212fe6(0xfa)]();console['error'](_0x212fe6(0x109),_0x5e6bd7);throw new Error(_0x212fe6(0x10f)+_0x4f73df[_0x212fe6(0x105)]+':\x20'+_0x5e6bd7);}return{'success':!![],'count':_0x50d145[_0x212fe6(0xfb)]};}async function getVectorCount(){const _0x4bd0c1=_0x21dada;console['log'](_0x4bd0c1(0x133));const _0x3b9e6e=await getCollectionId();console[_0x4bd0c1(0xa2)](_0x4bd0c1(0x134)+_0x3b9e6e);const _0x2c0ac2={'collectionId':_0x3b9e6e,'source':'webllm','embeddings':{}};console[_0x4bd0c1(0xa2)](_0x4bd0c1(0x11a),JSON[_0x4bd0c1(0xac)](_0x2c0ac2,null,0x2));const _0x588b2c=await fetch(_0x4bd0c1(0xa0),{'method':_0x4bd0c1(0x14a),'headers':context[_0x4bd0c1(0x11b)](),'body':JSON['stringify'](_0x2c0ac2)});console[_0x4bd0c1(0xa2)](_0x4bd0c1(0x120)+_0x588b2c[_0x4bd0c1(0x105)]);if(!_0x588b2c['ok']){const _0x1f8200=await _0x588b2c[_0x4bd0c1(0xfa)]();return console['error']('[翰林院-日志]\x20获取向量列表API错误:',_0x1f8200),0x0;}const _0x5b12af=await _0x588b2c['json']();let _0x2b674a=0x0;if(Array[_0x4bd0c1(0xcb)](_0x5b12af))_0x2b674a=_0x5b12af[_0x4bd0c1(0xfb)];else _0x5b12af&&_0x5b12af[_0x4bd0c1(0xe4)]&&(_0x2b674a=_0x5b12af[_0x4bd0c1(0xe4)][_0x4bd0c1(0xfb)]);return console[_0x4bd0c1(0xa2)]('[翰林院-日志]\x20统计成功,向量总数:\x20'+_0x2b674a),_0x2b674a;}async function purgeStorage(_0x4a4f59=null){const _0x26ede4=_0x21dada;console[_0x26ede4(0xa2)]('[翰林院-日志]\x20开始清空宝库...');const _0x132471=_0x4a4f59||await getCollectionId();if(!_0x132471)return console[_0x26ede4(0x131)](_0x26ede4(0x137)),toastr[_0x26ede4(0x131)](_0x26ede4(0xff)),![];console[_0x26ede4(0xa2)](_0x26ede4(0xed)+_0x132471);const _0x4f7154={'collectionId':_0x132471};console['log']('[翰林院-日志]\x20发送到\x20/api/vector/purge\x20的请求体:',JSON[_0x26ede4(0xac)](_0x4f7154,null,0x2));const _0x191c08=await fetch('/api/vector/purge',{'method':'POST','headers':context['getRequestHeaders'](),'body':JSON[_0x26ede4(0xac)](_0x4f7154)});console[_0x26ede4(0xa2)]('[翰林院-日志]\x20/api/vector/purge\x20响应状态:\x20'+_0x191c08[_0x26ede4(0x105)]);if(!_0x191c08['ok']){const _0x29d664=await _0x191c08['text']();console[_0x26ede4(0x131)](_0x26ede4(0xc5),_0x29d664);}else console[_0x26ede4(0xa2)](_0x26ede4(0x9c));return _0x191c08['ok'];}function getMessagesForCondensation(_0x38424a=null){const _0x374d17=_0x21dada;if(!settings[_0x374d17(0xad)][_0x374d17(0x12e)])return showNotification('凝识之权未开启',_0x374d17(0x102)),[];const {layerStart:_0x59c44b,layerEnd:_0x4f7c78}=settings[_0x374d17(0xad)],_0x23de81=_0x38424a||settings[_0x374d17(0xad)]['messageTypes'],_0x2f3916=context[_0x374d17(0x11e)][_0x374d17(0xfb)],_0x27dff5=Math[_0x374d17(0x114)](0x0,_0x59c44b-0x1),_0x19670a=_0x4f7c78===0x0||_0x4f7c78>_0x2f3916?_0x2f3916:Math[_0x374d17(0xd8)](_0x2f3916,_0x4f7c78),_0x9061de=context['chat'][_0x374d17(0xc7)](_0x27dff5,_0x19670a);return _0x9061de[_0x374d17(0x135)](_0x46ab19=>{const _0x5d6565=_0x374d17,_0x1992de=_0x46ab19[_0x5d6565(0xbd)]===!![],_0xd28255=_0x46ab19[_0x5d6565(0xbd)]===![];if(!_0x46ab19[_0x5d6565(0x9a)]||!_0x46ab19[_0x5d6565(0x9a)][_0x5d6565(0xbb)]())return![];return _0x23de81['user']&&_0x1992de||_0x23de81['ai']&&_0xd28255;});}async function processCondensation(_0x481cc2,_0x17ca6b=()=>{},_0x5a5ec2=null){const _0x320e11=_0x21dada;if(!_0x481cc2||_0x481cc2[_0x320e11(0xfb)]===0x0)return{'success':![],'error':_0x320e11(0xd4)};try{let _0x12df15=await getCollectionId();const _0x5eb071=getCollectionIdInfo();if(_0x5eb071[_0x320e11(0x13c)]&&_0x5eb071[_0x320e11(0x13c)]===_0x12df15&&_0x5eb071[_0x320e11(0x13c)]!==_0x5eb071[_0x320e11(0x9e)]){const _0x2e5d48=confirm('此操作将清空旧版数据,并开始使用新版数据库。此过程不可逆,是否继续?');if(_0x2e5d48)_0x17ca6b(_0x320e11(0xe1)+_0x5eb071['oldId'],'warn'),await purgeStorage(_0x5eb071['oldId']),_0x12df15=_0x5eb071[_0x320e11(0x9e)],_0x17ca6b(_0x320e11(0xc6)+_0x12df15,'success');else return _0x17ca6b(_0x320e11(0x11c),'info'),toastr['info'](_0x320e11(0xe3)),{'success':![],'error':_0x320e11(0x111)};}if(!_0x12df15)throw new Error('无法确定当前忆识宝库的ID,请确认角色已正确加载。');_0x17ca6b(_0x320e11(0x13a)+_0x12df15,_0x320e11(0x138));const _0x1bf473=[],_0x3ccb19=context[_0x320e11(0x11e)];for(const _0x56db1e of _0x481cc2){const _0x27d1e6=(_0x56db1e[_0x320e11(0x9a)]||'')[_0x320e11(0xca)](/<[^>]*>/g,'')[_0x320e11(0xbb)]();if(_0x27d1e6[_0x320e11(0xfb)]===0x0)continue;let _0x357c63;if(_0x56db1e[_0x320e11(0xe7)]!==undefined&&_0x56db1e[_0x320e11(0xe7)]!==null)_0x357c63=_0x56db1e[_0x320e11(0xe7)];else{const _0x60044d=_0x3ccb19['findIndex'](_0x13ecd5=>_0x13ecd5===_0x56db1e);_0x357c63=_0x60044d!==-0x1?_0x60044d+0x1:-0x1;}const _0xa0c60=new Date(_0x56db1e[_0x320e11(0xde)]),_0x4544c0=isNaN(_0xa0c60[_0x320e11(0x12b)]())?new Date()['toISOString']():_0xa0c60[_0x320e11(0x98)](),_0x3c8f5c=splitIntoChunks(_0x27d1e6,_0x320e11(0x101),{'floor':_0x357c63,'is_user':_0x56db1e[_0x320e11(0xbd)],'timestamp':_0x4544c0});_0x1bf473[_0x320e11(0x99)](..._0x3c8f5c);}if(_0x1bf473[_0x320e11(0xfb)]===0x0)return{'success':!![],'count':0x0};_0x17ca6b(_0x320e11(0xdf)+_0x481cc2[_0x320e11(0xfb)]+_0x320e11(0x113)+_0x1bf473['length']+_0x320e11(0x139),_0x320e11(0x138));const _0x266482=settings[_0x320e11(0x144)][_0x320e11(0x130)]||0x5;let _0x4edb8c=0x0;for(let _0x4e566c=0x0;_0x4e566c<_0x1bf473[_0x320e11(0xfb)];_0x4e566c+=_0x266482){const _0x5cc05a=_0x1bf473[_0x320e11(0xc7)](_0x4e566c,_0x4e566c+_0x266482),_0x557ed1=_0x5cc05a[_0x320e11(0xcc)](_0x501ca1=>_0x501ca1['text']),_0x5aee12=await getEmbeddings(_0x557ed1);if(_0x5cc05a[_0x320e11(0xfb)]!==_0x5aee12[_0x320e11(0xfb)])throw new Error('文本块和向量数量不匹配');const _0x584c8c=_0x5cc05a[_0x320e11(0xcc)]((_0x3bee8e,_0x4f0979)=>({..._0x3bee8e,'vector':_0x5aee12[_0x4f0979]}));await insertVectors(_0x584c8c,null,_0x12df15),_0x4edb8c+=_0x5cc05a['length'];}if(_0x5a5ec2){const _0x587711=_0x5a5ec2[_0x320e11(0xb7)]===0x0?context['chat'][_0x320e11(0xfb)]:_0x5a5ec2[_0x320e11(0xb7)];settings[_0x320e11(0x126)][_0x12df15]={'start':_0x5a5ec2['start'],'end':_0x587711,'timestamp':new Date()[_0x320e11(0x98)]()},saveSettings(),_0x17ca6b('[翰林院-核心]\x20已为宝库\x20'+_0x12df15+_0x320e11(0xa3)+_0x5a5ec2[_0x320e11(0xb9)]+'-'+_0x587711,'info');}_0x17ca6b(_0x320e11(0xef)+_0x4edb8c+_0x320e11(0x9f),_0x320e11(0x116));const _0x40958d=_0x481cc2['map'](_0x3c407a=>{const _0x32def8=_0x320e11,_0x293f07=_0x3ccb19[_0x32def8(0x106)](_0x5a062e=>_0x5a062e===_0x3c407a),_0x5a8daa=_0x293f07!==-0x1?_0x293f07+0x1:-0x1,_0x5906f0=_0x3c407a['is_user']?'用户':getCharacterName()||'AI';return'['+_0x5906f0+'\x20-\x20楼层\x20#'+_0x5a8daa+_0x32def8(0xab);});return{'success':!![],'count':_0x4edb8c,'messages':_0x40958d};}catch(_0x5444be){return console[_0x320e11(0x131)](_0x320e11(0xf7),_0x5444be),_0x17ca6b('[翰林院-核心]\x20聊天记录凝识失败:\x20'+_0x5444be[_0x320e11(0xa1)],'error'),{'success':![],'error':_0x5444be[_0x320e11(0xa1)]};}}async function rerankResults(_0x4798c4,_0x28732b,_0x2b0839){const _0x4a2de4=_0x21dada;let _0x16c8a9=_0x4798c4;if(_0x2b0839['rerank'][_0x4a2de4(0x12e)]&&_0x4798c4[_0x4a2de4(0xfb)]>0x0){console[_0x4a2de4(0xa2)](_0x4a2de4(0xc0));try{const _0xbbb70b=_0x4798c4['map'](_0x2ca7e8=>_0x2ca7e8['text']),_0x4e2637=await executeRerank(_0x28732b,_0xbbb70b,_0x2b0839[_0x4a2de4(0x149)]),_0x12e5b4=_0x4798c4[_0x4a2de4(0xcc)]((_0x1450a8,_0x27ff75)=>({..._0x1450a8,'original_index':_0x27ff75}));_0x16c8a9=_0x12e5b4['map'](_0x461f22=>{const _0x523335=_0x4a2de4,_0x235369=_0x4e2637[_0x523335(0x13b)]['find'](_0x51967c=>_0x51967c[_0x523335(0xc4)]===_0x461f22[_0x523335(0xc2)]),_0x220437=_0x235369?_0x235369[_0x523335(0x12f)]:0x0;return{..._0x461f22,'rerank_score':_0x220437};});if(_0x2b0839['rerank'][_0x4a2de4(0xb0)])showNotification(_0x4a2de4(0xe2),'success');}catch(_0x2f32c9){console[_0x4a2de4(0x131)](_0x4a2de4(0x103),_0x2f32c9);if(_0x2b0839[_0x4a2de4(0x149)][_0x4a2de4(0xb0)])showNotification('Rerank失败:\x20'+_0x2f32c9[_0x4a2de4(0xa1)],_0x4a2de4(0x131));_0x16c8a9['forEach'](_0xfdf10d=>_0xfdf10d['rerank_score']=0x0);}}else _0x16c8a9[_0x4a2de4(0x13e)](_0x27a8df=>_0x27a8df[_0x4a2de4(0xcf)]=0x0);console[_0x4a2de4(0xa2)](_0x4a2de4(0x121));const _0x5842cf=context['chat']['length'],_0x1dbcbc=_0x2b0839[_0x4a2de4(0x149)][_0x4a2de4(0xaf)],_0x7e0ab3=_0x16c8a9[_0x4a2de4(0xcc)](_0x133954=>{const _0x1cabc6=_0x4a2de4;let _0x387046=0x1;const _0x3b1454=_0x133954['metadata']||{};switch(_0x3b1454['source']){case _0x1cabc6(0x127):_0x387046*=1.2;break;case _0x1cabc6(0x9b):_0x387046*=1.1;break;case _0x1cabc6(0x101):if(_0x3b1454['floor']&&_0x5842cf>0x0){const _0x3afbe2=_0x3b1454[_0x1cabc6(0xe7)]/_0x5842cf;_0x387046*=0x1+_0x3afbe2;}break;}const _0xfb8fad=_0x133954['rerank_score']*_0x1dbcbc+(_0x133954[_0x1cabc6(0xbe)]||0x0)*(0x1-_0x1dbcbc),_0x44a2a8=_0xfb8fad*_0x387046;return{..._0x133954,'final_score':_0x44a2a8};});return _0x7e0ab3[_0x4a2de4(0xec)]((_0x3b849d,_0x52f6d8)=>(_0x52f6d8[_0x4a2de4(0x110)]||0x0)-(_0x3b849d[_0x4a2de4(0x110)]||0x0)),console[_0x4a2de4(0xa2)]('[翰林院-Rerank]\x20元数据加权排序完成。'),_0x7e0ab3['slice'](0x0,_0x2b0839[_0x4a2de4(0x149)][_0x4a2de4(0x100)]);}async function rearrangeChat(_0xda9122,_0x2b3e89,_0x35ef8d,_0x41ea5a){const _0x22fc60=_0x21dada;setExtensionPrompt(_0x22fc60(0xf0),'',settings[_0x22fc60(0xf2)][_0x22fc60(0xf5)],settings[_0x22fc60(0xf2)][_0x22fc60(0xa9)],![],settings[_0x22fc60(0xf2)][_0x22fc60(0x10e)]);if(_0x41ea5a==='quiet'||!settings[_0x22fc60(0x144)][_0x22fc60(0x12e)])return;const _0x5c5aaf=_0xda9122[_0x22fc60(0xc7)](-settings['advanced'][_0x22fc60(0xb4)]);if(_0x5c5aaf['length']===0x0)return;const _0x1a2a9d=_0x5c5aaf[_0x22fc60(0xcc)](_0x1ca5a8=>_0x1ca5a8['mes'])['join']('\x20')[_0x22fc60(0xca)](/<[^>]*>/g,'')['trim']();if(!_0x1a2a9d)return;try{const _0xe7a617=await queryVectors(_0x1a2a9d);if(_0xe7a617[_0x22fc60(0xfb)]===0x0)return;const _0xaba661=await rerankResults(_0xe7a617,_0x1a2a9d,settings);if(_0xaba661[_0x22fc60(0xfb)]===0x0)return;const _0x49e9f5=_0xaba661['map'](_0x19f4ca=>_0x19f4ca[_0x22fc60(0xfa)])['join']('\x0a\x0a'),_0x2157be=settings[_0x22fc60(0xf2)][_0x22fc60(0xb1)][_0x22fc60(0xca)](_0x22fc60(0xdb),_0x49e9f5);setExtensionPrompt(_0x22fc60(0xf0),_0x2157be,settings[_0x22fc60(0xf2)][_0x22fc60(0xf5)],settings['injection'][_0x22fc60(0xa9)],![],settings[_0x22fc60(0xf2)]['depth_role']);}catch(_0x225ca1){console[_0x22fc60(0x131)](_0x22fc60(0xea),_0x225ca1);if(settings['retrieval']['notify'])showNotification(_0x22fc60(0x143)+_0x225ca1[_0x22fc60(0xa1)],'error');}}