function _0x56e8(_0x2bb8db,_0x46d926){const _0x592c72=_0x592c();return _0x56e8=function(_0x56e8d4,_0x524866){_0x56e8d4=_0x56e8d4-0x1c6;let _0x5e3bc8=_0x592c72[_0x56e8d4];return _0x5e3bc8;},_0x56e8(_0x2bb8db,_0x46d926);}const _0x404143=_0x56e8;(function(_0x4b926b,_0x4d7fea){const _0x170980=_0x56e8,_0x58100e=_0x4b926b();while(!![]){try{const _0x3bf088=-parseInt(_0x170980(0x24a))/0x1+parseInt(_0x170980(0x20e))/0x2+parseInt(_0x170980(0x23a))/0x3+parseInt(_0x170980(0x247))/0x4*(-parseInt(_0x170980(0x222))/0x5)+-parseInt(_0x170980(0x249))/0x6+parseInt(_0x170980(0x22d))/0x7*(-parseInt(_0x170980(0x1c7))/0x8)+-parseInt(_0x170980(0x1e9))/0x9*(-parseInt(_0x170980(0x230))/0xa);if(_0x3bf088===_0x4d7fea)break;else _0x58100e['push'](_0x58100e['shift']());}catch(_0x4170fb){_0x58100e['push'](_0x58100e['shift']());}}}(_0x592c,0x41c89));import{getContext}from'/scripts/extensions.js';import{characters,eventSource,event_types}from'/script.js';import{loadWorldInfo,createNewWorldInfo,createWorldInfoEntry,saveWorldInfo,world_names}from'/scripts/world-info.js';export const LOREBOOK_PREFIX=_0x404143(0x23e);export const DEDICATED_LOREBOOK_NAME='Amily2号-国史馆';export const INTRODUCTORY_TEXT=_0x404143(0x1f6);function _0x592c(){const _0x1ed64d=['[Amily2号-工部-v1.3]\x20执行“圣谕广播”式UI更新...','values','constant','[国史馆-调试]\x20准备创建的新条目数据:','uid','[剧情优化大师]\x20TavernHelper\x20API\x20或\x20context\x20未提供,无法获取世界书内容。','join','dedicated','#amily2_opt_selected_worldbooks','worldbookSource','[条目:\x20','\x0a\x0a---\x0a\x0a','深度:','always','\x20个条目的状态以匹配当前聊天:\x20','groupEnd','setLorebookEntries','length','depth','2284686KvHaHV','from','key','worldbookCharLimit','type','assign','entries','chat_filename','exclude_recursion','#amily2_opt_worldbook_entry_list_container\x20input[type=\x22checkbox\x22]','disable','bookName','enabledWorldbookEntries','【Amily2号自动档案】\x0a此卷宗由Amily2号优化助手自动生成并维护,记录核心事件脉络。\x0a---\x0a','send_date','[Amily2-国史馆]\x20管理世界书条目状态时发生错误:','[Amily2-国史馆]\x20户籍管理处在长时间等待后,仍无法确定户籍。','[剧情优化大师]\x20未找到设置面板,世界书功能将回退到使用已保存的设置。','1.\x20','[Amily2号-工部]\x20“character_page_loaded”事件已广播,UI应已响应刷新。','总结写入总耗时','all','TavernHelper','filter','\x27\x20检索时发生错误:','#amily2_opt_worldbook_char_limit','[史官司]\x20总结已遵旨写入《','chat','map','isArray','[Amily2-国史馆]\x20钦差大臣在整合\x20\x27',':checked','prevent_recursion','avatar','toLowerCase','additional','primary','861182GYBVrb','add','substring','data','收到未知的写入指令:\x20\x22','》更新了\x20','后台写入总结时发生错误。','character_main','trim','push','CHARACTER_PAGE_LOADED','book','character','char-','[Amily2号]\x20致命错误:\x20eventSource\x20或\x20event_types.CHARACTER_PAGE_LOADED\x20未找到。无法广播刷新事件。','time','groupCollapsed','message','target','通过\x20TavernHelper\x20写入世界书失败:\x20','5235zyMCCC','toLocaleTimeString','[Amily2-国史馆]\x20使用\x20TavernHelper\x20写入时发生错误:','[Amily2-国史馆]\x20未选择任何角色,跳过世界书管理。','sourceAiMessageTimestamp','读取世界书\x20\x27','Amily2号-国史馆','角色未绑定主世界书,总结写入任务已中止。','\x27\x20时发生错误:','worldbookEnabled','》文件。','41657JZCkeW','replace','无标题','30fAqvAL','includes','[Amily2号-工部]\x20已将《','settings','characterId','world','[Amily2号-工部]\x20“圣谕广播”式刷新失败:','无法加载世界书《','timeEnd','已创建并写入新档案《','259212NrXDJO','[剧情优化大师]\x20处理世界书逻辑时出错:','extensions','[Amily2号-工部]\x20《','Amily2档案-','\x20chars),将被截断。','[剧情优化大师]\x20世界书内容\x20(','档案整合错误','warning','getCharLorebooks','TavernHelper\x20API\x20未找到,无法执行写入操作。','[Amily2-国史馆]\x20接到一份残缺的待办文书,写入任务已中止。','\x27\x20失败!','1464pfeeQa','pop','1776582sCMDKK','109622vIzNAt','keys','createLorebookEntries','\x20chars)\x20超出限制\x20(','error','sort','[Amily2-国史馆]\x20无法获取有效的聊天标识符,中止条目状态管理。','content','summary','keywords','#amily2_opt_worldbook_enabled','getLorebookEntries','split','[国史馆-调试]\x20writeToLorebookWithTavernHelper\x20接收到的选项:','input[name=\x22amily2_opt_worldbook_source\x22]:checked','296EHyRAa','is_user','[Amily2号-存档任务-v21.0\x20最终圣旨版]\x20','log','startsWith','enabled','Amily2号-核心缺失','warn','find','上下文错误','comment','forEach','emit','selectedWorldbooks','Amily2号'];_0x592c=function(){return _0x1ed64d;};return _0x592c();}export async function getChatIdentifier(){const _0x54dd5d=_0x404143;let _0x24ed7c=0x0;const _0x3cff65=0x32,_0x44101e=0x64;while(_0x24ed7c<_0x3cff65){try{const _0x20ce1a=getContext();if(_0x20ce1a&&_0x20ce1a[_0x54dd5d(0x234)]){const _0x1177c8=characters[_0x20ce1a['characterId']];if(_0x1177c8&&_0x1177c8['avatar'])return _0x54dd5d(0x21b)+_0x1177c8[_0x54dd5d(0x20a)][_0x54dd5d(0x22e)](/\.(png|webp|jpg|jpeg|gif)$/,'');return _0x54dd5d(0x21b)+_0x20ce1a['characterId'];}if(_0x20ce1a&&_0x20ce1a[_0x54dd5d(0x1f0)]){const _0xb9dd8b=_0x20ce1a[_0x54dd5d(0x1f0)][_0x54dd5d(0x256)](/[\\/]/)[_0x54dd5d(0x248)]();return _0xb9dd8b['replace'](/\.jsonl?$/,'');}}catch(_0x42516e){console[_0x54dd5d(0x1ce)]('[Amily2-户籍管理处]\x20等待上下文时发生轻微错误\x20(尝试次数\x20'+(_0x24ed7c+0x1)+'):',_0x42516e[_0x54dd5d(0x21f)]);}await new Promise(_0x4c2c20=>setTimeout(_0x4c2c20,_0x44101e)),_0x24ed7c++;}return console[_0x54dd5d(0x24e)](_0x54dd5d(0x1f9)),toastr[_0x54dd5d(0x242)]('Amily2号无法确定当前聊天身份,世界书功能将受影响。',_0x54dd5d(0x1d0)),'unknown_chat_timeout';}export async function findLatestSummaryLore(_0x26c269,_0x3fb3b2){const _0x5d3e8e=_0x404143;try{const _0x2dbdcf=await loadWorldInfo(_0x26c269);if(!_0x2dbdcf||!_0x2dbdcf['entries'])return null;const _0x3e08d7=Object[_0x5d3e8e(0x1d7)](_0x2dbdcf[_0x5d3e8e(0x1ef)]),_0x2f21a4=''+LOREBOOK_PREFIX+_0x3fb3b2;return _0x3e08d7[_0x5d3e8e(0x1cf)](_0x545af5=>_0x545af5[_0x5d3e8e(0x1d1)]===_0x2f21a4&&!_0x545af5['disable'])||null;}catch(_0x3bcfa6){return console[_0x5d3e8e(0x24e)]('[Amily2-国史馆]\x20钦差大臣在\x20\x27'+_0x26c269+_0x5d3e8e(0x201),_0x3bcfa6),null;}}export async function getCombinedWorldbookContent(_0x2f7060){const _0x431234=_0x404143;if(!_0x2f7060)return'';try{const _0x1369d4=await loadWorldInfo(_0x2f7060);if(!_0x1369d4||!_0x1369d4['entries'])return'';const _0x3a61d4=Object[_0x431234(0x1d7)](_0x1369d4[_0x431234(0x1ef)])[_0x431234(0x200)](_0x3484cd=>!_0x3484cd[_0x431234(0x1f3)])[_0x431234(0x205)](_0xd04349=>_0x431234(0x1e0)+(_0xd04349[_0x431234(0x1d1)]||_0x431234(0x22f))+']\x0a'+_0xd04349[_0x431234(0x251)]);return _0x3a61d4[_0x431234(0x1dc)](_0x431234(0x1e1));}catch(_0xa1b693){return console[_0x431234(0x24e)](_0x431234(0x207)+_0x2f7060+_0x431234(0x22a),_0xa1b693),toastr[_0x431234(0x24e)](_0x431234(0x227)+_0x2f7060+_0x431234(0x246),_0x431234(0x241)),'';}}async function refreshWorldbookListOnly(_0x2008c1=null){const _0x2dd295=_0x404143;console['log'](_0x2dd295(0x1d6));try{_0x2008c1&&(Array['isArray'](world_names)&&!world_names['includes'](_0x2008c1)?(world_names[_0x2dd295(0x217)](_0x2008c1),world_names[_0x2dd295(0x24f)](),console[_0x2dd295(0x1ca)](_0x2dd295(0x232)+_0x2008c1+'》注入前端数据模型。')):console[_0x2dd295(0x1ca)](_0x2dd295(0x23d)+_0x2008c1+'》已存在于数据模型中,跳过注入。')),eventSource&&typeof eventSource['emit']==='function'&&event_types['CHARACTER_PAGE_LOADED']?(console[_0x2dd295(0x1ca)]('[Amily2号-工部]\x20正在广播事件:\x20'+event_types[_0x2dd295(0x218)]),eventSource[_0x2dd295(0x1d3)](event_types[_0x2dd295(0x218)]),console['log'](_0x2dd295(0x1fc))):(console[_0x2dd295(0x24e)](_0x2dd295(0x21c)),toastr['error']('Amily2号无法触发UI刷新。','核心事件系统缺失'));}catch(_0x46fc8c){console[_0x2dd295(0x24e)](_0x2dd295(0x236),_0x46fc8c);}}export async function writeSummaryToLorebook(_0x1bd149){const _0x1d47b9=_0x404143;if(!_0x1bd149||!_0x1bd149[_0x1d47b9(0x252)]||!_0x1bd149[_0x1d47b9(0x226)]||!_0x1bd149[_0x1d47b9(0x233)]){console['warn'](_0x1d47b9(0x245),_0x1bd149);return;}const _0x83062f=getContext(),_0x3a99ce=_0x83062f[_0x1d47b9(0x204)];let _0x5679f6=![],_0x51acff=null;for(let _0x4b0bd4=_0x3a99ce[_0x1d47b9(0x1e7)]-0x2;_0x4b0bd4>=0x0;_0x4b0bd4--){if(!_0x3a99ce[_0x4b0bd4][_0x1d47b9(0x1c8)]){_0x51acff=_0x3a99ce[_0x4b0bd4];break;}}_0x51acff&&_0x51acff[_0x1d47b9(0x1f7)]===_0x1bd149[_0x1d47b9(0x226)]&&(_0x5679f6=!![]);if(!_0x5679f6){console[_0x1d47b9(0x1ca)]('[Amily2号-逆时寻踪]\x20裁决:\x20源消息已被修改或删除,遵旨废黜过时总结。');return;}const {summary:_0x34322f,settings:_0x23036d}=_0x1bd149;console[_0x1d47b9(0x21e)](_0x1d47b9(0x1c9)+new Date()[_0x1d47b9(0x223)]()),console[_0x1d47b9(0x21d)]('总结写入总耗时');try{const _0x37aee4=await getChatIdentifier(),_0x3a1a9e=characters[_0x83062f[_0x1d47b9(0x234)]];let _0x5a65f4=null,_0x4c233e=![];switch(_0x23036d['target']){case _0x1d47b9(0x215):_0x5a65f4=_0x3a1a9e?.['data']?.[_0x1d47b9(0x23c)]?.[_0x1d47b9(0x235)];if(!_0x5a65f4){toastr[_0x1d47b9(0x242)](_0x1d47b9(0x229),_0x1d47b9(0x1d5)),console[_0x1d47b9(0x1e5)]();return;}break;case _0x1d47b9(0x1dd):_0x5a65f4=DEDICATED_LOREBOOK_NAME+'-'+_0x37aee4;break;default:toastr['error'](_0x1d47b9(0x212)+_0x23036d[_0x1d47b9(0x220)]+'\x22','Amily2号'),console[_0x1d47b9(0x1e5)]();return;}!world_names[_0x1d47b9(0x231)](_0x5a65f4)&&(await createNewWorldInfo(_0x5a65f4),_0x4c233e=!![]);const _0x271fcb=''+LOREBOOK_PREFIX+_0x37aee4,_0x4f68b5=await loadWorldInfo(_0x5a65f4);if(!_0x4f68b5){toastr[_0x1d47b9(0x24e)](_0x1d47b9(0x237)+_0x5a65f4+'》','Amily2号'),console[_0x1d47b9(0x1e5)]();return;}const _0x3c7e43=Object[_0x1d47b9(0x1d7)](_0x4f68b5[_0x1d47b9(0x1ef)])['find'](_0x24c52b=>_0x24c52b[_0x1d47b9(0x1d1)]===_0x271fcb&&!_0x24c52b[_0x1d47b9(0x1f3)]);if(_0x3c7e43){const _0x5e1f29=_0x3c7e43[_0x1d47b9(0x251)][_0x1d47b9(0x22e)](INTRODUCTORY_TEXT,'')[_0x1d47b9(0x216)](),_0xce0d9f=_0x5e1f29?_0x5e1f29['split']('\x0a'):[],_0x4c9285=_0xce0d9f[_0x1d47b9(0x1e7)]+0x1;_0x3c7e43['content']+='\x0a'+_0x4c9285+'.\x20'+_0x34322f;}else{const _0x59ae2d={'before_char':0x0,'after_char':0x1,'before_an':0x2,'after_an':0x3,'at_depth':0x4},_0x5648b7=_0x23036d[_0x1d47b9(0x253)][_0x1d47b9(0x256)](',')[_0x1d47b9(0x205)](_0x2f2f27=>_0x2f2f27[_0x1d47b9(0x216)]())[_0x1d47b9(0x200)](Boolean),_0x10249f=_0x23036d['activationMode']===_0x1d47b9(0x1e3),_0x4df72d=createWorldInfoEntry(_0x5a65f4,_0x4f68b5);Object[_0x1d47b9(0x1ee)](_0x4df72d,{'comment':_0x271fcb,'content':INTRODUCTORY_TEXT+_0x1d47b9(0x1fb)+_0x34322f,'key':_0x5648b7,'constant':_0x10249f,'position':_0x59ae2d[_0x23036d['insertionPosition']]??0x4,'depth':_0x23036d[_0x1d47b9(0x1e8)],'disable':![]});}await saveWorldInfo(_0x5a65f4,_0x4f68b5,!![]),console['log'](_0x1d47b9(0x203)+_0x5a65f4+_0x1d47b9(0x22c)),_0x4c233e&&(await refreshWorldbookListOnly(_0x5a65f4),toastr['success'](_0x1d47b9(0x239)+_0x5a65f4+'》!',_0x1d47b9(0x1d5)));}catch(_0xa2c10c){console[_0x1d47b9(0x24e)]('[Amily2号-写入失败]\x20写入流程发生意外错误:',_0xa2c10c),toastr[_0x1d47b9(0x24e)](_0x1d47b9(0x214),_0x1d47b9(0x1d5));}finally{console[_0x1d47b9(0x238)](_0x1d47b9(0x1fd)),console[_0x1d47b9(0x1e5)]();}}export async function getPlotOptimizedWorldbookContent(_0x1dc236,_0x4134a0){const _0x1492ef=_0x404143,_0x394950=$('#amily2_plot_optimization_panel');let _0x4db50b={};if(_0x394950['length']>0x0){_0x4db50b[_0x1492ef(0x22b)]=_0x394950[_0x1492ef(0x1cf)](_0x1492ef(0x254))['is'](_0x1492ef(0x208)),_0x4db50b[_0x1492ef(0x1df)]=_0x394950[_0x1492ef(0x1cf)](_0x1492ef(0x1c6))['val']()||_0x1492ef(0x21a),_0x4db50b[_0x1492ef(0x1d4)]=_0x394950[_0x1492ef(0x1cf)](_0x1492ef(0x1de))['val']()||[],_0x4db50b[_0x1492ef(0x1ec)]=parseInt(_0x394950[_0x1492ef(0x1cf)](_0x1492ef(0x202))['val'](),0xa)||0xea60;let _0x159717={};_0x394950['find'](_0x1492ef(0x1f2))['each'](function(){const _0x27234b=_0x1492ef;if($(this)['is'](':checked')){const _0x5d1f21=$(this)[_0x27234b(0x211)](_0x27234b(0x219)),_0x3b87fe=parseInt($(this)[_0x27234b(0x211)](_0x27234b(0x1da)));!_0x159717[_0x5d1f21]&&(_0x159717[_0x5d1f21]=[]),_0x159717[_0x5d1f21][_0x27234b(0x217)](_0x3b87fe);}}),_0x4db50b[_0x1492ef(0x1f5)]=_0x159717;}else console['warn'](_0x1492ef(0x1fa)),_0x4db50b={'worldbookEnabled':_0x4134a0['worldbookEnabled'],'worldbookSource':_0x4134a0[_0x1492ef(0x1df)],'selectedWorldbooks':_0x4134a0[_0x1492ef(0x1d4)],'worldbookCharLimit':_0x4134a0[_0x1492ef(0x1ec)],'enabledWorldbookEntries':_0x4134a0[_0x1492ef(0x1f5)]};if(!_0x4db50b[_0x1492ef(0x22b)])return'';if(!window['TavernHelper']?.[_0x1492ef(0x255)]||!_0x1dc236)return console[_0x1492ef(0x1ce)](_0x1492ef(0x1db)),'';try{let _0x48da71=[];if(_0x4db50b[_0x1492ef(0x1df)]==='manual'){_0x48da71=_0x4db50b[_0x1492ef(0x1d4)];if(_0x48da71['length']===0x0)return'';}else{const _0x29267c=await window['TavernHelper']['getCharLorebooks']({'type':_0x1492ef(0x1fe)});if(_0x29267c[_0x1492ef(0x20d)])_0x48da71[_0x1492ef(0x217)](_0x29267c[_0x1492ef(0x20d)]);if(_0x29267c['additional']?.[_0x1492ef(0x1e7)])_0x48da71['push'](..._0x29267c[_0x1492ef(0x20c)]);if(_0x48da71[_0x1492ef(0x1e7)]===0x0)return'';}let _0x327fe6=[];for(const _0x290bc3 of _0x48da71){if(_0x290bc3){const _0x5be336=await window[_0x1492ef(0x1ff)][_0x1492ef(0x255)](_0x290bc3);_0x5be336?.[_0x1492ef(0x1e7)]&&_0x5be336[_0x1492ef(0x1d2)](_0x307db1=>_0x327fe6[_0x1492ef(0x217)]({..._0x307db1,'bookName':_0x290bc3}));}}if(_0x327fe6[_0x1492ef(0x1e7)]===0x0)return'';const _0x44d55a=_0x4db50b['enabledWorldbookEntries']||{},_0x2d1408=_0x327fe6[_0x1492ef(0x200)](_0x41a6ba=>{const _0x1dc332=_0x1492ef;if(!_0x41a6ba[_0x1dc332(0x1cc)])return![];const _0x174bb3=_0x44d55a[_0x41a6ba[_0x1dc332(0x1f4)]];return _0x174bb3?_0x174bb3[_0x1dc332(0x231)](_0x41a6ba[_0x1dc332(0x1da)]):![];});if(_0x2d1408['length']===0x0)return'';const _0x1b2cf9=_0x1dc236[_0x1492ef(0x204)][_0x1492ef(0x205)](_0x2b8729=>_0x2b8729['mes'])[_0x1492ef(0x1dc)]('\x0a')[_0x1492ef(0x20b)](),_0x427ae7=_0x5807c7=>[...new Set([..._0x5807c7[_0x1492ef(0x1eb)]||[],..._0x5807c7[_0x1492ef(0x24b)]||[]])][_0x1492ef(0x205)](_0xe88201=>_0xe88201[_0x1492ef(0x20b)]()),_0x260e24=_0x2d1408[_0x1492ef(0x200)](_0x47287c=>_0x47287c[_0x1492ef(0x1ed)]===_0x1492ef(0x1d8));let _0x3ef032=_0x2d1408[_0x1492ef(0x200)](_0x4c887d=>_0x4c887d['type']!=='constant');const _0x295091=new Set([..._0x260e24]);while(!![]){let _0x512d2d=![];const _0x1360d8=Array[_0x1492ef(0x1ea)](_0x295091)['filter'](_0x411994=>!_0x411994[_0x1492ef(0x209)])[_0x1492ef(0x205)](_0x1f691f=>_0x1f691f[_0x1492ef(0x251)])[_0x1492ef(0x1dc)]('\x0a')[_0x1492ef(0x20b)](),_0x2e8951=_0x1b2cf9+'\x0a'+_0x1360d8,_0x2680ec=[];for(const _0x189051 of _0x3ef032){const _0x886966=_0x427ae7(_0x189051);let _0x542ef8=_0x886966[_0x1492ef(0x1e7)]>0x0&&_0x886966['some'](_0x2d0541=>_0x189051[_0x1492ef(0x1f1)]?_0x1b2cf9[_0x1492ef(0x231)](_0x2d0541):_0x2e8951['includes'](_0x2d0541));_0x542ef8?(_0x295091[_0x1492ef(0x20f)](_0x189051),_0x512d2d=!![]):_0x2680ec[_0x1492ef(0x217)](_0x189051);}if(!_0x512d2d)break;_0x3ef032=_0x2680ec;}const _0x41fb62=Array[_0x1492ef(0x1ea)](_0x295091)['map'](_0x27f112=>_0x27f112[_0x1492ef(0x251)])[_0x1492ef(0x200)](Boolean);if(_0x41fb62[_0x1492ef(0x1e7)]===0x0)return'';const _0x36c97c=_0x41fb62[_0x1492ef(0x1dc)](_0x1492ef(0x1e1)),_0x50a792=_0x4db50b[_0x1492ef(0x1ec)];if(_0x36c97c[_0x1492ef(0x1e7)]>_0x50a792)return console[_0x1492ef(0x1ca)](_0x1492ef(0x240)+_0x36c97c[_0x1492ef(0x1e7)]+_0x1492ef(0x24d)+_0x50a792+_0x1492ef(0x23f)),_0x36c97c[_0x1492ef(0x210)](0x0,_0x50a792);return _0x36c97c;}catch(_0x3f9016){return console[_0x1492ef(0x24e)](_0x1492ef(0x23b),_0x3f9016),'';}}const TavernHelper=window[_0x404143(0x1ff)];export async function writeToLorebookWithTavernHelper(_0x441646,_0x163edb,_0x16a106,_0x25be4a={}){const _0x1ffd7f=_0x404143;console[_0x1ffd7f(0x1ca)](_0x1ffd7f(0x257),_0x25be4a);if(!TavernHelper)return toastr['error'](_0x1ffd7f(0x244),_0x1ffd7f(0x1cd)),![];try{const _0xd44ef9=_0x441646;!world_names['includes'](_0xd44ef9)&&(await createNewWorldInfo(_0xd44ef9),Array[_0x1ffd7f(0x206)](world_names)&&!world_names[_0x1ffd7f(0x231)](_0xd44ef9)&&(world_names['push'](_0xd44ef9),world_names[_0x1ffd7f(0x24f)]()),eventSource&&typeof eventSource[_0x1ffd7f(0x1d3)]==='function'&&event_types['CHARACTER_PAGE_LOADED']&&eventSource[_0x1ffd7f(0x1d3)](event_types[_0x1ffd7f(0x218)]));const _0x2ba5cc=await TavernHelper[_0x1ffd7f(0x255)](_0xd44ef9)||[],_0x61f30a=_0x2ba5cc[_0x1ffd7f(0x1cf)](_0x447bf8=>_0x447bf8[_0x1ffd7f(0x1d1)]===_0x163edb&&!_0x447bf8[_0x1ffd7f(0x1f3)]);if(_0x61f30a){const _0x2bb9c8=_0x16a106(_0x61f30a[_0x1ffd7f(0x251)]);await TavernHelper['setLorebookEntries'](_0xd44ef9,[{'uid':_0x61f30a[_0x1ffd7f(0x1da)],'content':_0x2bb9c8}]);}else{const _0x47299b=_0x16a106(null),{keys:keys=[],isConstant:isConstant=![],insertion_position:_0x792bf7,insertion_depth:_0x3a1021}=_0x25be4a,_0x85ada9={'before_char':0x0,'after_char':0x1,'before_an':0x2,'after_an':0x3,'at_depth':0x4},_0x39ccec={'comment':_0x163edb,'content':_0x47299b,'key':keys,'constant':isConstant,'position':_0x85ada9[_0x792bf7]??0x4,'depth':parseInt(_0x3a1021)||0x3e6,'insertion_order':parseInt(_0x3a1021)||0x3e6,'enabled':!![],'disable':![],'case_sensitive':![],'priority':0xa,'type':isConstant?_0x1ffd7f(0x1d8):'selective'};console[_0x1ffd7f(0x1ca)](_0x1ffd7f(0x1d9),_0x39ccec),await TavernHelper[_0x1ffd7f(0x24c)](_0xd44ef9,[_0x39ccec]),console[_0x1ffd7f(0x1ca)]('[国史馆-调试]\x20TavernHelper创建完成,尝试传统API设置位置参数...');try{const _0x3bb6a1=await loadWorldInfo(_0xd44ef9),_0x5bba4f=Object['values'](_0x3bb6a1[_0x1ffd7f(0x1ef)])[_0x1ffd7f(0x1cf)](_0x1b2876=>_0x1b2876['comment']===_0x163edb);_0x5bba4f&&(_0x5bba4f['position']=_0x85ada9[_0x792bf7]??0x4,_0x5bba4f['depth']=parseInt(_0x3a1021)||0x3e6,console['log']('[国史馆-调试]\x20使用传统API设置位置:',_0x5bba4f['position'],_0x1ffd7f(0x1e2),_0x5bba4f['depth']),await saveWorldInfo(_0xd44ef9,_0x3bb6a1,!![]),console[_0x1ffd7f(0x1ca)]('[国史馆-调试]\x20传统API设置完成'));}catch(_0x479e50){console[_0x1ffd7f(0x24e)]('[国史馆-调试]\x20传统API设置失败:',_0x479e50);}}return console[_0x1ffd7f(0x1ca)]('[Amily2-国史馆]\x20已通过\x20TavernHelper\x20将内容成功写入《'+_0xd44ef9+'》的条目\x20\x22'+_0x163edb+'\x22。'),!![];}catch(_0x64d7e1){return console[_0x1ffd7f(0x24e)](_0x1ffd7f(0x224),_0x64d7e1),toastr['error'](_0x1ffd7f(0x221)+_0x64d7e1[_0x1ffd7f(0x21f)],_0x1ffd7f(0x228)),![];}}export async function manageLorebookEntriesForChat(){const _0x313898=_0x404143;if(!TavernHelper){console[_0x313898(0x1ce)]('[Amily2-国史馆]\x20TavernHelper\x20API\x20未找到,无法管理条目状态。');return;}try{const _0x56fc30=await getChatIdentifier();if(!_0x56fc30||_0x56fc30[_0x313898(0x1cb)]('unknown_chat')){console['error'](_0x313898(0x250));return;}const _0x1553b7=getContext();if(!_0x1553b7||!_0x1553b7[_0x313898(0x234)]){console[_0x313898(0x1ca)](_0x313898(0x225));return;}const _0x5ac4b9=await TavernHelper[_0x313898(0x243)]({'type':_0x313898(0x1fe)}),_0x59a73a=[];if(_0x5ac4b9['primary'])_0x59a73a[_0x313898(0x217)](_0x5ac4b9[_0x313898(0x20d)]);if(_0x5ac4b9[_0x313898(0x20c)]?.[_0x313898(0x1e7)])_0x59a73a[_0x313898(0x217)](..._0x5ac4b9[_0x313898(0x20c)]);const _0x5c5e5e=DEDICATED_LOREBOOK_NAME+'-'+_0x56fc30;!_0x59a73a[_0x313898(0x231)](_0x5c5e5e)&&_0x59a73a['push'](_0x5c5e5e);for(const _0x58edd7 of _0x59a73a){if(!world_names[_0x313898(0x231)](_0x58edd7))continue;const _0x59af48=await TavernHelper[_0x313898(0x255)](_0x58edd7)||[],_0x59257f=[];for(const _0x6fb871 of _0x59af48){if(_0x6fb871[_0x313898(0x1d1)]&&_0x6fb871[_0x313898(0x1d1)]['startsWith'](LOREBOOK_PREFIX)){const _0x445b86=_0x6fb871[_0x313898(0x1d1)][_0x313898(0x231)](_0x56fc30);if(_0x445b86&&_0x6fb871[_0x313898(0x1f3)])_0x59257f[_0x313898(0x217)]({'uid':_0x6fb871[_0x313898(0x1da)],'disable':![]});else!_0x445b86&&!_0x6fb871[_0x313898(0x1f3)]&&_0x59257f[_0x313898(0x217)]({'uid':_0x6fb871['uid'],'disable':!![]});}}if(_0x59257f['length']>0x0){const _0x1125af=_0x59257f[_0x313898(0x205)](_0x5bc100=>({'uid':_0x5bc100[_0x313898(0x1da)],'enabled':!_0x5bc100[_0x313898(0x1f3)]}));await TavernHelper[_0x313898(0x1e6)](_0x58edd7,_0x1125af),console['log']('[Amily2-国史馆]\x20已为《'+_0x58edd7+_0x313898(0x213)+_0x1125af[_0x313898(0x1e7)]+_0x313898(0x1e4)+_0x56fc30);}}}catch(_0x3b08ea){console[_0x313898(0x24e)](_0x313898(0x1f8),_0x3b08ea);}}