diff --git a/core/summarizer.js b/core/summarizer.js
index 26ea796..129b96e 100644
--- a/core/summarizer.js
+++ b/core/summarizer.js
@@ -1,518 +1 @@
-import { extension_settings, getContext } from "/scripts/extensions.js";
-import { characters } from "/script.js";
-import { world_info } from "/scripts/world-info.js";
-import { extensionName } from "../utils/settings.js";
-import { extractContentByTag, replaceContentByTag, extractFullTagBlock } from '../utils/tagProcessor.js';
-import { isGoogleEndpoint, convertToGoogleRequest, parseGoogleResponse, buildGoogleApiUrl, buildPlotOptimizationGoogleRequest, parsePlotOptimizationGoogleResponse } from './utils/googleAdapter.js';
-import { applyExclusionRules, extractBlocksByTags } from './utils/rag-tag-extractor.js';
-import {
- getCombinedWorldbookContent, getPlotOptimizedWorldbookContent, getOptimizationWorldbookContent,
-} from "./lore.js";
-import { getBatchFillerFlowTemplate, convertTablesToCsvString, updateTableFromText, saveStateToMessage, getMemoryState } from './table-system/manager.js';
-import { saveChat } from "/script.js";
-import { renderTables } from '../ui/table-bindings.js';
-
-import { getPresetPrompts, getMixedOrder } from '../PresetSettings/index.js';
-import { callAI, generateRandomSeed } from './api.js';
-import { callJqyhAI } from './api/JqyhApi.js';
-
-export async function processOptimization(latestMessage, previousMessages) {
- if (window.AMILY2_SYSTEM_PARALYZED === true) {
- console.error("[Amily2-制裁] 系统完整性已受损,所有外交活动被无限期中止。");
- return null;
- }
-
- const settings = extension_settings[extensionName];
- const isOptimizationEnabled = settings.optimizationEnabled;
-
- if (!isOptimizationEnabled) {
- return null;
- }
-
- console.groupCollapsed(`[Amily2号-正文优化任务] ${new Date().toLocaleTimeString()}`);
- console.time("优化任务总耗时");
-
- try {
- window.Amily2PreOptimizationSnapshot = {
- original: null,
- optimized: null,
- raw: latestMessage.mes,
- };
-
- const originalFullMessage = latestMessage.mes;
- let textToProcess = originalFullMessage;
-
- if (settings.optimizationExclusionEnabled && settings.optimizationExclusionRules?.length > 0) {
- const originalLength = textToProcess.length;
- textToProcess = applyExclusionRules(textToProcess, settings.optimizationExclusionRules);
- const newLength = textToProcess.length;
- if (originalLength !== newLength) {
- console.log(`[Amily2-内容排除] 正文优化内容排除规则已生效,文本长度从 ${originalLength} 变为 ${newLength}。`);
- }
- }
-
- const targetTag = settings.optimizationTargetTag || 'content';
- const extractedBlock = extractFullTagBlock(textToProcess, targetTag);
-
- if (!extractedBlock || extractContentByTag(extractedBlock, targetTag)?.trim() === '') {
- console.log(`[Amily2-外交部] 目标标签 <${targetTag}> 未找到或为空,或内容已被完全排除,优化任务已跳过。`);
- window.Amily2PreOptimizationSnapshot = null;
- document.dispatchEvent(new CustomEvent('preOptimizationStateUpdated'));
- console.timeEnd("优化任务总耗时");
- console.groupEnd();
- return null;
- }
-
- window.Amily2PreOptimizationSnapshot.original = extractContentByTag(extractedBlock, targetTag);
- document.dispatchEvent(new CustomEvent('preOptimizationStateUpdated'));
-
- textToProcess = extractedBlock;
-
- const context = getContext();
- const userName = context.name1 || '用户';
- const characterName = context.name2 || '角色';
-
- const lastUserMessage = previousMessages.length > 0 && previousMessages[previousMessages.length - 1].is_user ? previousMessages[previousMessages.length - 1] : null;
- const historyMessages = lastUserMessage ? previousMessages.slice(0, -1) : previousMessages;
- const history = historyMessages.map(m => (m.mes && m.mes.trim() ? `${m.is_user ? userName : characterName}: ${m.mes.trim()}` : null)).filter(Boolean).join("\n");
-
- const worldbookContent = await getOptimizationWorldbookContent();
- const presetPrompts = await getPresetPrompts('optimization');
- const messages = [
- { role: 'system', content: generateRandomSeed() }
- ];
-
- let currentInteractionContent = lastUserMessage ? `${userName}(用户)最新消息:${lastUserMessage.mes}\n${characterName}(AI)最新消息,[核心处理内容]:${textToProcess}` : `${characterName}(AI)最新消息,[核心处理内容]:${textToProcess}`;
- const fillingMode = settings.filling_mode || 'main-api';
-
-
- const order = getMixedOrder('optimization') || [];
- let promptCounter = 0;
-
- for (const item of order) {
- if (item.type === 'prompt') {
- if (presetPrompts && presetPrompts[promptCounter]) {
- messages.push(presetPrompts[promptCounter]);
- promptCounter++;
- }
- } else if (item.type === 'conditional') {
- switch (item.id) {
- case 'mainPrompt':
- if (settings.mainPrompt?.trim()) {
- messages.push({ role: "system", content: settings.mainPrompt.trim() });
- }
- break;
- case 'systemPrompt':
- if (settings.systemPrompt?.trim()) {
- messages.push({ role: "system", content: settings.systemPrompt.trim() });
- }
- break;
- case 'worldbook':
- if (worldbookContent) {
- messages.push({ role: "user", content: `[世界书档案]:\n${worldbookContent}` });
- }
- break;
- case 'history':
- if (history) {
- messages.push({ role: "user", content: `[上下文参考]:\n${history}` });
- }
- break;
- case 'fillingMode':
- if (isOptimizationEnabled && fillingMode === 'optimized') {
- const flowTemplate = getBatchFillerFlowTemplate();
- const tableData = convertTablesToCsvString();
- const filledFlowTemplate = flowTemplate.replace('{{{Amily2TableData}}}', tableData);
-
- messages.push({ role: "user", content: currentInteractionContent });
- messages.push({ role: "system", content: `请你在优化完成后,在正文标签外结合最新消息中的剧情、当前的表格内容进行填表任务:\n\n${filledFlowTemplate}\n\n\n\nOptimisation and form filling have been completed.` });
- } else {
- messages.push({ role: "user", content: `[目标内容]:\n${currentInteractionContent}Start and end labels correctly.` });
- }
- break;
- }
- }
- }
-
- console.groupCollapsed("[Amily2号-最终国书内容 (发往AI)]");
- console.dir(messages);
- console.groupEnd();
- const rawContent = await callAI(messages);
-
- if (!rawContent) {
- console.error('[Amily2-外交部] 未能获取AI响应内容');
- return null;
- }
-
- console.groupCollapsed("[Amily2号-原始回复]");
- console.log(rawContent);
- console.groupEnd();
-
- let finalMessage = originalFullMessage;
- const purifiedTextFromAI = extractContentByTag(rawContent, targetTag);
-
- if (purifiedTextFromAI?.trim()) {
- finalMessage = replaceContentByTag(originalFullMessage, targetTag, purifiedTextFromAI);
- window.Amily2PreOptimizationSnapshot.optimized = purifiedTextFromAI;
- } else {
- console.warn(`[Amily2-外交部] AI的回复中未找到有效的目标标签 <${targetTag}>,将保留原始消息。`);
- window.Amily2PreOptimizationSnapshot.optimized = window.Amily2PreOptimizationSnapshot.original;
- }
- document.dispatchEvent(new CustomEvent('preOptimizationStateUpdated'));
-
- if (isOptimizationEnabled && fillingMode === 'optimized') {
- await updateTableFromText(rawContent);
-
- const finalContext = getContext();
- if (finalContext.chat && finalContext.chat.length > 0) {
- const lastMessage = finalContext.chat[finalContext.chat.length - 1];
- if (saveStateToMessage(getMemoryState(), lastMessage)) {
- await saveChat();
- renderTables();
- console.log('[Amily2-优化中填表] 流程已全部完成,并已强制保存和刷新UI。');
- }
- }
- }
-
- const result = {
- originalContent: originalFullMessage,
- optimizedContent: finalMessage,
- };
-
- if (settings.showOptimizationToast) {
- toastr.success("正文优化成功!", "Amily2号");
- }
-
- console.timeEnd("优化任务总耗时");
- console.groupEnd();
- return result;
-
- } catch (error) {
- console.error(`[Amily2-外交部] 发生严重错误:`, error);
- toastr.error(`Amily2号任务失败: ${error.message}`, "严重错误");
- console.timeEnd("优化任务总耗时");
- console.groupEnd();
- return null;
- }
-}
-
-
-export async function processPlotOptimization(currentUserMessage, contextMessages, cancellationState = { isCancelled: false }) {
- const settings = extension_settings[extensionName];
-
- if (settings.plotOpt_enabled === false) {
- return null;
- }
-
- console.groupCollapsed(`[${extensionName}] 剧情优化任务启动... ${new Date().toLocaleTimeString()}`);
- console.time('剧情优化任务总耗时');
-
- try {
- const userMessageContent = currentUserMessage.mes;
- if (!userMessageContent || userMessageContent.trim() === '') {
- console.log(`[${extensionName}] 用户输入为空,跳过优化。`);
- return null;
- }
-
- const context = getContext();
- const userName = context.name1 || '用户';
- const charName = context.name2 || '角色';
-
- const presetPrompts = await getPresetPrompts('plot_optimization');
- const messages = [
- { role: 'system', content: generateRandomSeed() }
- ];
-
- const replacements = {
- 'sulv1': settings.plotOpt_rateMain ?? 1.0,
- 'sulv2': settings.plotOpt_ratePersonal ?? 1.0,
- 'sulv3': settings.plotOpt_rateErotic ?? 1.0,
- 'sulv4': settings.plotOpt_rateCuckold ?? 1.0,
- };
-
- let mainPrompt = settings.plotOpt_mainPrompt || '';
- let systemPrompt = settings.plotOpt_systemPrompt || '';
-
- for (const key in replacements) {
- const value = replacements[key];
- const regex = new RegExp(key.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g');
- mainPrompt = mainPrompt.replace(regex, value);
- systemPrompt = systemPrompt.replace(regex, value);
- }
-
- let worldbookContent = await getPlotOptimizedWorldbookContent(context, settings);
-
- // --- EJS 預處理(劇情優化專用)---
- try {
- if (settings.plotOpt_ejsEnabled !== false && globalThis.EjsTemplate?.evalTemplate && globalThis.EjsTemplate?.prepareContext) {
- const safeUser = (userMessageContent ?? '').toString();
- const safeWorld = (worldbookContent ?? '').toString();
- const hasEjsUser = /<%[=_\-]?/.test(safeUser);
- const hasEjsWorld = /<%[=_\-]?/.test(safeWorld);
- const openTagRegex = /<%[=_\-]?/g;
- const closeTagRegex = /[-_]?%>/g;
- const openUser = (safeUser.match(openTagRegex) || []).length;
- const closeUser = (safeUser.match(closeTagRegex) || []).length;
- const openWorld = (safeWorld.match(openTagRegex) || []).length;
- const closeWorld = (safeWorld.match(closeTagRegex) || []).length;
- const balancedUser = hasEjsUser && openUser === closeUser && openUser > 0;
- const balancedWorld = hasEjsWorld && openWorld === closeWorld && openWorld > 0;
-
- if (hasEjsUser || hasEjsWorld) {
- const env = await globalThis.EjsTemplate.prepareContext({ runType: 'plot_optimization', isDryRun: false });
-
- try {
- if (balancedUser) {
- const compiledUser = await globalThis.EjsTemplate.evalTemplate(safeUser, env, { _with: true });
- if (typeof compiledUser === 'string' && compiledUser.length > 0) {
- currentUserMessage.mes = compiledUser;
- }
- } else if (hasEjsUser) {
- console.warn('[ST-Amily2-Chat-Optimisation][PlotOpt] 检测到未闭合的 EJS 标签(用户输入),已跳过预处理。');
- }
- } catch (errUser) {
- console.error('[ST-Amily2-Chat-Optimisation][PlotOpt] EJS 預處理-用户输入失败:', errUser);
- toastr.error('EJS 预处理用户输入失败,已中止。', 'Amily2号');
- return null;
- }
-
- try {
- if (balancedWorld) {
- const compiledWorld = await globalThis.EjsTemplate.evalTemplate(safeWorld, env, { _with: true });
- if (typeof compiledWorld === 'string' && compiledWorld.length > 0) {
- worldbookContent = compiledWorld;
- }
- } else if (hasEjsWorld) {
- console.warn('[ST-Amily2-Chat-Optimisation][PlotOpt] 检测到未闭合的 EJS 标签(世界书),已跳过预处理。');
- }
- } catch (errWorld) {
- try {
- if (globalThis.EjsTemplate?.getSyntaxErrorInfo && typeof errWorld?.message === 'string') {
- const extra = globalThis.EjsTemplate.getSyntaxErrorInfo(safeWorld);
- console.error('[ST-Amily2-Chat-Optimisation][PlotOpt] EJS 預處理-世界书失败(含定位):', errWorld?.message + (extra || ''));
- } else {
- console.error('[ST-Amily2-Chat-Optimisation][PlotOpt] EJS 預處理-世界书失败:', errWorld);
- }
- // 打印世界书片段(限長)
- try {
- const maxLen = 2000;
- const snippet = typeof safeWorld === 'string' ? safeWorld.slice(0, maxLen) : String(safeWorld).slice(0, maxLen);
- const isTruncated = (safeWorld?.length || 0) > maxLen;
- // 存入全局以便用户在控制台直接读取
- try {
- // @ts-ignore
- window.Amily2PlotOptDebug = window.Amily2PlotOptDebug || {};
- // @ts-ignore
- window.Amily2PlotOptDebug.worldErrorMessage = (errWorld?.message || String(errWorld)) + '';
- // @ts-ignore
- window.Amily2PlotOptDebug.worldSnippet = snippet;
- // @ts-ignore
- window.Amily2PlotOptDebug.worldSnippetTruncated = isTruncated;
- // @ts-ignore
- window.Amily2PlotOptDebug.worldOpenClose = { open: openWorld, close: closeWorld };
- } catch (_) {}
-
- // 多级别日志,避免特定环境过滤
- console.groupCollapsed('[ST-Amily2-Chat-Optimisation][PlotOpt] 失败世界书片段 (截断=' + isTruncated + ')');
- console.log(snippet);
- console.groupEnd();
- console.warn('[ST-Amily2-Chat-Optimisation][PlotOpt] worldOpenClose:', { open: openWorld, close: closeWorld });
- console.error('[ST-Amily2-Chat-Optimisation][PlotOpt] 以上即失败世界书片段。');
- } catch (logErr) {
- console.error('[ST-Amily2-Chat-Optimisation][PlotOpt] 打印失败世界书片段时出错:', logErr);
- }
- } catch (sub) {
- console.error('[ST-Amily2-Chat-Optimisation][PlotOpt] 记录语法位置信息失败:', sub);
- }
- toastr.error('EJS 预处理世界书失败,已中止。', 'Amily2号');
- return null;
- }
- }
- }
- } catch (e) {
- console.error('[ST-Amily2-Chat-Optimisation][PlotOpt] EJS 預處理初始化失败(可能是上下文环境):', e);
- toastr.error('EJS 预处理初始化失败,已中止。', 'Amily2号');
- return null; // 直接中止,不送出訊息
- }
-
- let tableContent = '';
- if (settings.plotOpt_tableEnabled) {
- try {
- const { convertTablesToCsvStringForContentOnly } = await import('./table-system/manager.js');
- const contentOnlyTemplate = "##以下内容是故事发生的剧情中提取出的内容,已经转化为表格形式呈现给你,请将以下内容作为后续剧情的一部分参考:<表格内容>\n{{{Amily2TableDataContent}}}表格内容>";
- const tableData = convertTablesToCsvStringForContentOnly();
-
- if (tableData.trim()) {
- tableContent = contentOnlyTemplate.replace('{{{Amily2TableDataContent}}}', tableData);
- }
- } catch (error) {
- console.error('[Amily2-表格系统] 注入表格内容时出错:', error);
- }
- }
-
- let history = '';
- const contextLimit = settings.plotOpt_contextLimit || 0;
- if (contextLimit > 0 && contextMessages.length > 0) {
- const historyMessages = contextMessages.slice(-contextLimit);
-
- // 复刻 Historiographer 的标签提取与内容排除逻辑
- const useTagExtraction = settings.historiographyTagExtractionEnabled ?? false;
- const tagsToExtract = useTagExtraction ? (settings.historiographyTags || '').split(',').map(t => t.trim()).filter(Boolean) : [];
- const exclusionRules = settings.historiographyExclusionRules || [];
-
- history = historyMessages
- .map(msg => {
- if (msg.mes && msg.mes.trim()) {
- let content = msg.mes.trim();
-
- // 1. 标签提取
- if (useTagExtraction && tagsToExtract.length > 0) {
- const blocks = extractBlocksByTags(content, tagsToExtract);
- if (blocks.length > 0) {
- content = blocks.join('\n\n');
- }
- }
-
- // 2. 内容排除
- content = applyExclusionRules(content, exclusionRules);
-
- return content ? `${msg.is_user ? userName : charName}: ${content}` : null;
- }
- return null;
- })
- .filter(Boolean)
- .join('\n');
- }
-
- const order = getMixedOrder('plot_optimization') || [];
- let promptCounter = 0;
-
- for (const item of order) {
- if (item.type === 'prompt') {
- if (presetPrompts && presetPrompts[promptCounter]) {
- messages.push(presetPrompts[promptCounter]);
- promptCounter++;
- }
- } else if (item.type === 'conditional') {
- switch (item.id) {
- case 'mainPrompt':
- if (mainPrompt.trim()) {
- messages.push({ role: "system", content: mainPrompt.trim() });
- }
- break;
- case 'systemPrompt':
- if (systemPrompt.trim()) {
- messages.push({ role: "system", content: systemPrompt.trim() });
- }
- break;
- case 'worldbook':
- if (worldbookContent.trim()) {
- messages.push({ role: "user", content: `<世界书内容>\n${worldbookContent.trim()}世界书内容>` });
- }
- break;
- case 'tableEnabled':
- if (tableContent) {
- messages.push({ role: "user", content: tableContent });
- }
- break;
- case 'contextLimit':
- if (history) {
- messages.push({ role: "user", content: `<前文内容>\n${history}\n前文内容>` });
- }
- break;
- case 'coreContent':
- messages.push({ role: 'user', content: `[核心处理内容]:\n${currentUserMessage.mes}` });
- break;
- }
- }
- }
-
- console.groupCollapsed(`[${extensionName}] 发送给AI的最终请求内容`);
- console.dir(messages);
- console.groupEnd();
-
- let apiResponse = '';
- let attempt = 0;
- const maxAttempts = 3;
- let success = false;
-
- while (attempt < maxAttempts && !success) {
- if (cancellationState.isCancelled) {
- console.log(`[${extensionName}] 优化任务在尝试前被中止。`);
- return null;
- }
- attempt++;
- console.log(`[${extensionName}] 剧情优化第 ${attempt} 次尝试...`);
-
- const rawResponse = settings.jqyhEnabled ? await callJqyhAI(messages) : await callAI(messages, 'plot_optimization');
-
- if (cancellationState.isCancelled) {
- console.log(`[${extensionName}] 优化任务在API调用后被中止。`);
- return null;
- }
-
- if (!rawResponse) {
- console.warn(`[${extensionName}] 第 ${attempt} 次尝试获取响应失败,AI返回为空。`);
- continue;
- }
-
- const plotContent = extractContentByTag(rawResponse, 'plot');
- const optimizedContent = (plotContent?.trim()) ? plotContent.trim() : rawResponse.trim();
-
- if (optimizedContent.length >= 100) {
- apiResponse = rawResponse;
- success = true;
- console.log(`[${extensionName}] 第 ${attempt} 次尝试成功,内容长度 (${optimizedContent.length}) 符合要求。`);
- } else {
- console.warn(`[${extensionName}] 第 ${attempt} 次尝试失败,回复内容长度为 ${optimizedContent.length},小于100字符。`);
- }
- }
-
- if (!success) {
- console.error(`[${extensionName}] 已达到最大重试次数 (${maxAttempts}) 且未获得符合要求的回复,优化任务中止。`);
- toastr.error(`剧情优化在 ${maxAttempts} 次尝试后失败。`, "优化失败");
- return null;
- }
-
- console.groupCollapsed(`[${extensionName}] 从AI收到的原始回复`);
- console.log(apiResponse);
- console.groupEnd();
-
- const plotContent = extractContentByTag(apiResponse, 'plot');
- const optimizedContent = (plotContent?.trim()) ? plotContent.trim() : apiResponse.trim();
-
- if (optimizedContent) {
- let finalContentToAppend = '';
- let finalDirectiveTemplate = settings.plotOpt_finalSystemDirective?.trim() || '';
-
- const replacements = {
- 'sulv1': settings.plotOpt_rateMain ?? 1.0,
- 'sulv2': settings.plotOpt_ratePersonal ?? 1.0,
- 'sulv3': settings.plotOpt_rateErotic ?? 1.0,
- 'sulv4': settings.plotOpt_rateCuckold ?? 1.0,
- };
- for (const key in replacements) {
- const value = replacements[key];
- const regex = new RegExp(key.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g');
- finalDirectiveTemplate = finalDirectiveTemplate.replace(regex, value);
- }
-
- if (finalDirectiveTemplate) {
- finalContentToAppend = finalDirectiveTemplate.replace('', optimizedContent);
- } else {
- finalContentToAppend = optimizedContent;
- }
-
- return { contentToAppend: finalContentToAppend };
- } else {
- return null;
- }
-
- } catch (error) {
- console.error(`[${extensionName}] 剧情优化任务发生严重错误:`, error);
- toastr.error(`剧情优化任务失败: ${error.message}`, '严重错误');
- return null;
- } finally {
- console.timeEnd('剧情优化任务总耗时');
- console.groupEnd();
- }
-}
+(function(_0x28a1f1,_0x5d134c){const _0x297105=_0x1ceb,_0x381844=_0x28a1f1();while(!![]){try{const _0xf6c17e=parseInt(_0x297105(0xcb))/0x1*(-parseInt(_0x297105(0x76))/0x2)+-parseInt(_0x297105(0xc9))/0x3*(parseInt(_0x297105(0x74))/0x4)+parseInt(_0x297105(0xcd))/0x5*(parseInt(_0x297105(0xb6))/0x6)+parseInt(_0x297105(0xaf))/0x7*(-parseInt(_0x297105(0x84))/0x8)+-parseInt(_0x297105(0x7f))/0x9+parseInt(_0x297105(0xbe))/0xa+parseInt(_0x297105(0xbb))/0xb;if(_0xf6c17e===_0x5d134c)break;else _0x381844['push'](_0x381844['shift']());}catch(_0x1bbc5e){_0x381844['push'](_0x381844['shift']());}}}(_0x4ff1,0x1db26));import{extension_settings,getContext}from'/scripts/extensions.js';import{characters}from'/script.js';import{world_info}from'/scripts/world-info.js';import{extensionName}from'../utils/settings.js';import{extractContentByTag,replaceContentByTag,extractFullTagBlock}from'../utils/tagProcessor.js';function _0x1ceb(_0x3df836,_0x34991f){const _0x4ff1bd=_0x4ff1();return _0x1ceb=function(_0x1ceb03,_0x5eedaf){_0x1ceb03=_0x1ceb03-0x6e;let _0x5b5bab=_0x4ff1bd[_0x1ceb03];return _0x5b5bab;},_0x1ceb(_0x3df836,_0x34991f);}import{isGoogleEndpoint,convertToGoogleRequest,parseGoogleResponse,buildGoogleApiUrl,buildPlotOptimizationGoogleRequest,parsePlotOptimizationGoogleResponse}from'./utils/googleAdapter.js';import{applyExclusionRules,extractBlocksByTags}from'./utils/rag-tag-extractor.js';function _0x4ff1(){const _0x4d237b=['{{{Amily2TableData}}}','[Amily2-内容排除]\x20正文优化内容排除规则已生效,文本长度从\x20','worldSnippet','[Amily2-外交部]\x20AI的回复中未找到有效的目标标签\x20<','replace','plot','plotOpt_mainPrompt','[Amily2-外交部]\x20发生严重错误:','[目标内容]:\x0a','EjsTemplate','optimizationExclusionEnabled','[Amily2号-正文优化任务]\x20','plot_optimization','plotOpt_rateMain','mainPrompt','optimizationEnabled','plotOpt_tableEnabled','剧情优化在\x20','优化任务总耗时','join','plotOpt_ratePersonal','EJS\x20预处理用户输入失败,已中止。','history','\x20次尝试失败,回复内容长度为\x20','##以下内容是故事发生的剧情中提取出的内容,已经转化为表格形式呈现给你,请将以下内容作为后续剧情的一部分参考:<表格内容>\x0a{{{Amily2TableDataContent}}}表格内容>','message','[Amily2-优化中填表]\x20流程已全部完成,并已强制保存和刷新UI。',']\x20优化任务在尝试前被中止。','name2','优化失败','getSyntaxErrorInfo','\x20次尝试后失败。','original','\x20次尝试...','[Amily2号-最终国书内容\x20(发往AI)]','map','contextLimit','plotOpt_systemPrompt','is_user','worldErrorMessage','(AI)最新消息,[核心处理内容]:','[ST-Amily2-Chat-Optimisation][PlotOpt]\x20记录语法位置信息失败:',']\x20从AI收到的原始回复','Start\x20and\x20end\x20labels\x20correctly.','push','plotOpt_enabled','groupEnd',']\x20优化任务在API调用后被中止。','plotOpt_contextLimit','4hKAkHD','time','30FOsJQQ','systemPrompt','plotOpt_ejsEnabled','optimization','chat','{{{Amily2TableDataContent}}}','filling_mode','prepareContext','[Amily2-表格系统]\x20注入表格内容时出错:','1629027huBLCY','<前文内容>\x0a','error','[Amily2号-原始回复]','AMILY2_SYSTEM_PARALYZED','16MAIwcR','historiographyTags','[Amily2-外交部]\x20目标标签\x20<','严重错误','[ST-Amily2-Chat-Optimisation][PlotOpt]\x20失败世界书片段\x20(截断=','[ST-Amily2-Chat-Optimisation][PlotOpt]\x20打印失败世界书片段时出错:','toLocaleTimeString','plotOpt_rateCuckold','[核心处理内容]:\x0a','worldSnippetTruncated','[ST-Amily2-Chat-Optimisation][PlotOpt]\x20EJS\x20預處理-用户输入失败:','剧情优化任务总耗时','showOptimizationToast','[ST-Amily2-Chat-Optimisation][PlotOpt]\x20EJS\x20預處理-世界书失败:','slice','[ST-Amily2-Chat-Optimisation][PlotOpt]\x20EJS\x20預處理初始化失败(可能是上下文环境):','user','name1','warn',')\x20且未获得符合要求的回复,优化任务中止。','coreContent','conditional',']\x20第\x20','[ST-Amily2-Chat-Optimisation][PlotOpt]\x20以上即失败世界书片段。','(用户)最新消息:','Amily2PlotOptDebug','filter','historiographyExclusionRules','worldbook','>\x20未找到或为空,或内容已被完全排除,优化任务已跳过。','historiographyTagExtractionEnabled','split','optimized','optimizationExclusionRules','system','test','toString','jqyhEnabled','请你在优化完成后,在正文标签外结合最新消息中的剧情、当前的表格内容进行填表任务:\x0a\x0a','[ST-Amily2-Chat-Optimisation][PlotOpt]\x20EJS\x20預處理-世界书失败(含定位):','trim','>,将保留原始消息。','dir','449512LwwvXZ','match','[ST-Amily2-Chat-Optimisation][PlotOpt]\x20worldOpenClose:','[Amily2-外交部]\x20未能获取AI响应内容','\x20次尝试成功,内容长度\x20(',']\x20剧情优化第\x20','mes','59628miyqAz','EJS\x20预处理初始化失败,已中止。','log','Amily2号任务失败:\x20','timeEnd','5159759GEAMDa','剧情优化任务失败:\x20','length','360760bCbnwV','prompt','','Amily2号','string','Amily2PreOptimizationSnapshot',']\x20已达到最大重试次数\x20(','groupCollapsed','[ST-Amily2-Chat-Optimisation][PlotOpt]\x20检测到未闭合的\x20EJS\x20标签(世界书),已跳过预处理。','evalTemplate','./table-system/manager.js','285921RzsBMU','<世界书内容>\x0a','1897BhceTR','preOptimizationStateUpdated','25qsozQw','type','dispatchEvent'];_0x4ff1=function(){return _0x4d237b;};return _0x4ff1();}import{getCombinedWorldbookContent,getPlotOptimizedWorldbookContent,getOptimizationWorldbookContent}from'./lore.js';import{getBatchFillerFlowTemplate,convertTablesToCsvString,updateTableFromText,saveStateToMessage,getMemoryState}from'./table-system/manager.js';import{saveChat}from'/script.js';import{renderTables}from'../ui/table-bindings.js';import{getPresetPrompts,getMixedOrder}from'../PresetSettings/index.js';import{callAI,generateRandomSeed}from'./api.js';import{callJqyhAI}from'./api/JqyhApi.js';export async function processOptimization(_0x1d7912,_0x2fc44b){const _0x5c5032=_0x1ceb;if(window[_0x5c5032(0x83)]===!![])return console['error']('[Amily2-制裁]\x20系统完整性已受损,所有外交活动被无限期中止。'),null;const _0x5e5198=extension_settings[extensionName],_0x337470=_0x5e5198[_0x5c5032(0xdf)];if(!_0x337470)return null;console[_0x5c5032(0xc5)](_0x5c5032(0xdb)+new Date()[_0x5c5032(0x8a)]()),console[_0x5c5032(0x75)](_0x5c5032(0xe2));try{window[_0x5c5032(0xc3)]={'original':null,'optimized':null,'raw':_0x1d7912[_0x5c5032(0xb5)]};const _0x58ce07=_0x1d7912[_0x5c5032(0xb5)];let _0x1c7267=_0x58ce07;if(_0x5e5198[_0x5c5032(0xda)]&&_0x5e5198[_0x5c5032(0xa5)]?.[_0x5c5032(0xbd)]>0x0){const _0x45b537=_0x1c7267[_0x5c5032(0xbd)];_0x1c7267=applyExclusionRules(_0x1c7267,_0x5e5198[_0x5c5032(0xa5)]);const _0x30b121=_0x1c7267[_0x5c5032(0xbd)];_0x45b537!==_0x30b121&&console[_0x5c5032(0xb8)](_0x5c5032(0xd1)+_0x45b537+'\x20变为\x20'+_0x30b121+'。');}const _0xcdeb8b=_0x5e5198['optimizationTargetTag']||'content',_0x5e012a=extractFullTagBlock(_0x1c7267,_0xcdeb8b);if(!_0x5e012a||extractContentByTag(_0x5e012a,_0xcdeb8b)?.[_0x5c5032(0xac)]()==='')return console['log'](_0x5c5032(0x86)+_0xcdeb8b+_0x5c5032(0xa1)),window[_0x5c5032(0xc3)]=null,document[_0x5c5032(0xcf)](new CustomEvent(_0x5c5032(0xcc))),console[_0x5c5032(0xba)](_0x5c5032(0xe2)),console[_0x5c5032(0x71)](),null;window[_0x5c5032(0xc3)][_0x5c5032(0xf0)]=extractContentByTag(_0x5e012a,_0xcdeb8b),document[_0x5c5032(0xcf)](new CustomEvent(_0x5c5032(0xcc))),_0x1c7267=_0x5e012a;const _0x2fe0cc=getContext(),_0x3a6c70=_0x2fe0cc[_0x5c5032(0x95)]||'用户',_0x2f0bfb=_0x2fe0cc[_0x5c5032(0xec)]||'角色',_0xbdae81=_0x2fc44b[_0x5c5032(0xbd)]>0x0&&_0x2fc44b[_0x2fc44b[_0x5c5032(0xbd)]-0x1][_0x5c5032(0xf6)]?_0x2fc44b[_0x2fc44b[_0x5c5032(0xbd)]-0x1]:null,_0x428e08=_0xbdae81?_0x2fc44b[_0x5c5032(0x92)](0x0,-0x1):_0x2fc44b,_0x1a1038=_0x428e08[_0x5c5032(0xf3)](_0x107419=>_0x107419[_0x5c5032(0xb5)]&&_0x107419[_0x5c5032(0xb5)]['trim']()?(_0x107419['is_user']?_0x3a6c70:_0x2f0bfb)+':\x20'+_0x107419['mes']['trim']():null)['filter'](Boolean)[_0x5c5032(0xe3)]('\x0a'),_0x174111=await getOptimizationWorldbookContent(),_0x48bc12=await getPresetPrompts('optimization'),_0x5cdc23=[{'role':_0x5c5032(0xa6),'content':generateRandomSeed()}];let _0x48076d=_0xbdae81?_0x3a6c70+_0x5c5032(0x9c)+_0xbdae81[_0x5c5032(0xb5)]+'\x0a'+_0x2f0bfb+'(AI)最新消息,[核心处理内容]:'+_0x1c7267:_0x2f0bfb+_0x5c5032(0xf8)+_0x1c7267;const _0x474f6d=_0x5e5198[_0x5c5032(0x7c)]||'main-api',_0x3816c1=getMixedOrder(_0x5c5032(0x79))||[];let _0x1c6cf6=0x0;for(const _0x503243 of _0x3816c1){if(_0x503243[_0x5c5032(0xce)]===_0x5c5032(0xbf))_0x48bc12&&_0x48bc12[_0x1c6cf6]&&(_0x5cdc23['push'](_0x48bc12[_0x1c6cf6]),_0x1c6cf6++);else{if(_0x503243['type']===_0x5c5032(0x99))switch(_0x503243['id']){case _0x5c5032(0xde):_0x5e5198[_0x5c5032(0xde)]?.[_0x5c5032(0xac)]()&&_0x5cdc23[_0x5c5032(0x6f)]({'role':_0x5c5032(0xa6),'content':_0x5e5198[_0x5c5032(0xde)]['trim']()});break;case _0x5c5032(0x77):_0x5e5198[_0x5c5032(0x77)]?.[_0x5c5032(0xac)]()&&_0x5cdc23[_0x5c5032(0x6f)]({'role':_0x5c5032(0xa6),'content':_0x5e5198[_0x5c5032(0x77)]['trim']()});break;case _0x5c5032(0xa0):_0x174111&&_0x5cdc23[_0x5c5032(0x6f)]({'role':_0x5c5032(0x94),'content':'[世界书档案]:\x0a'+_0x174111});break;case _0x5c5032(0xe6):_0x1a1038&&_0x5cdc23[_0x5c5032(0x6f)]({'role':'user','content':'[上下文参考]:\x0a'+_0x1a1038});break;case'fillingMode':if(_0x337470&&_0x474f6d===_0x5c5032(0xa4)){const _0x3e9077=getBatchFillerFlowTemplate(),_0x3569a8=convertTablesToCsvString(),_0x1368e1=_0x3e9077['replace'](_0x5c5032(0xd0),_0x3569a8);_0x5cdc23[_0x5c5032(0x6f)]({'role':_0x5c5032(0x94),'content':_0x48076d}),_0x5cdc23[_0x5c5032(0x6f)]({'role':_0x5c5032(0xa6),'content':_0x5c5032(0xaa)+_0x1368e1+'\x0a\x0a\x0a\x0aOptimisation\x20and\x20form\x20filling\x20have\x20been\x20completed.'});}else _0x5cdc23[_0x5c5032(0x6f)]({'role':'user','content':_0x5c5032(0xd8)+_0x48076d+_0x5c5032(0x6e)});break;}}}console[_0x5c5032(0xc5)](_0x5c5032(0xf2)),console[_0x5c5032(0xae)](_0x5cdc23),console[_0x5c5032(0x71)]();const _0x475a90=await callAI(_0x5cdc23);if(!_0x475a90)return console[_0x5c5032(0x81)](_0x5c5032(0xb2)),null;console['groupCollapsed'](_0x5c5032(0x82)),console[_0x5c5032(0xb8)](_0x475a90),console['groupEnd']();let _0x6f39e8=_0x58ce07;const _0x50f7ac=extractContentByTag(_0x475a90,_0xcdeb8b);_0x50f7ac?.['trim']()?(_0x6f39e8=replaceContentByTag(_0x58ce07,_0xcdeb8b,_0x50f7ac),window[_0x5c5032(0xc3)][_0x5c5032(0xa4)]=_0x50f7ac):(console[_0x5c5032(0x96)](_0x5c5032(0xd3)+_0xcdeb8b+_0x5c5032(0xad)),window['Amily2PreOptimizationSnapshot'][_0x5c5032(0xa4)]=window[_0x5c5032(0xc3)][_0x5c5032(0xf0)]);document[_0x5c5032(0xcf)](new CustomEvent(_0x5c5032(0xcc)));if(_0x337470&&_0x474f6d===_0x5c5032(0xa4)){await updateTableFromText(_0x475a90);const _0x2a7e54=getContext();if(_0x2a7e54[_0x5c5032(0x7a)]&&_0x2a7e54[_0x5c5032(0x7a)][_0x5c5032(0xbd)]>0x0){const _0x324178=_0x2a7e54['chat'][_0x2a7e54[_0x5c5032(0x7a)]['length']-0x1];saveStateToMessage(getMemoryState(),_0x324178)&&(await saveChat(),renderTables(),console[_0x5c5032(0xb8)](_0x5c5032(0xea)));}}const _0x1358d0={'originalContent':_0x58ce07,'optimizedContent':_0x6f39e8};return _0x5e5198[_0x5c5032(0x90)]&&toastr['success']('正文优化成功!',_0x5c5032(0xc1)),console[_0x5c5032(0xba)]('优化任务总耗时'),console[_0x5c5032(0x71)](),_0x1358d0;}catch(_0xd06180){return console[_0x5c5032(0x81)](_0x5c5032(0xd7),_0xd06180),toastr[_0x5c5032(0x81)](_0x5c5032(0xb9)+_0xd06180['message'],_0x5c5032(0x87)),console[_0x5c5032(0xba)](_0x5c5032(0xe2)),console['groupEnd'](),null;}}export async function processPlotOptimization(_0xfe6926,_0x5c6909,_0x538852={'isCancelled':![]}){const _0x3d1e3e=_0x1ceb,_0x339ebe=extension_settings[extensionName];if(_0x339ebe[_0x3d1e3e(0x70)]===![])return null;console[_0x3d1e3e(0xc5)]('['+extensionName+']\x20剧情优化任务启动...\x20'+new Date()[_0x3d1e3e(0x8a)]()),console[_0x3d1e3e(0x75)](_0x3d1e3e(0x8f));try{const _0x3d7e5d=_0xfe6926[_0x3d1e3e(0xb5)];if(!_0x3d7e5d||_0x3d7e5d[_0x3d1e3e(0xac)]()==='')return console['log']('['+extensionName+']\x20用户输入为空,跳过优化。'),null;const _0xd3261f=getContext(),_0x5a236b=_0xd3261f['name1']||'用户',_0x3e5336=_0xd3261f[_0x3d1e3e(0xec)]||'角色',_0x4eb58f=await getPresetPrompts(_0x3d1e3e(0xdc)),_0x2d8b9c=[{'role':_0x3d1e3e(0xa6),'content':generateRandomSeed()}],_0x4da4ab={'sulv1':_0x339ebe[_0x3d1e3e(0xdd)]??0x1,'sulv2':_0x339ebe[_0x3d1e3e(0xe4)]??0x1,'sulv3':_0x339ebe['plotOpt_rateErotic']??0x1,'sulv4':_0x339ebe[_0x3d1e3e(0x8b)]??0x1};let _0x4b36c7=_0x339ebe[_0x3d1e3e(0xd6)]||'',_0x4a27c9=_0x339ebe[_0x3d1e3e(0xf5)]||'';for(const _0x2d19fa in _0x4da4ab){const _0x3066ed=_0x4da4ab[_0x2d19fa],_0x57eb6f=new RegExp(_0x2d19fa[_0x3d1e3e(0xd4)](/[-\/\\^$*+?.()|[\]{}]/g,'\x5c$&'),'g');_0x4b36c7=_0x4b36c7['replace'](_0x57eb6f,_0x3066ed),_0x4a27c9=_0x4a27c9[_0x3d1e3e(0xd4)](_0x57eb6f,_0x3066ed);}let _0x478a4a=await getPlotOptimizedWorldbookContent(_0xd3261f,_0x339ebe);try{if(_0x339ebe[_0x3d1e3e(0x78)]!==![]&&globalThis[_0x3d1e3e(0xd9)]?.[_0x3d1e3e(0xc7)]&&globalThis[_0x3d1e3e(0xd9)]?.[_0x3d1e3e(0x7d)]){const _0x1c912f=(_0x3d7e5d??'')['toString'](),_0x25ced3=(_0x478a4a??'')[_0x3d1e3e(0xa8)](),_0x46fa7b=/<%[=_\-]?/[_0x3d1e3e(0xa7)](_0x1c912f),_0x2c2081=/<%[=_\-]?/[_0x3d1e3e(0xa7)](_0x25ced3),_0x3935cd=/<%[=_\-]?/g,_0x56436f=/[-_]?%>/g,_0x1329e6=(_0x1c912f[_0x3d1e3e(0xb0)](_0x3935cd)||[])['length'],_0x284b22=(_0x1c912f[_0x3d1e3e(0xb0)](_0x56436f)||[])['length'],_0x2a4a38=(_0x25ced3[_0x3d1e3e(0xb0)](_0x3935cd)||[])[_0x3d1e3e(0xbd)],_0x55ca35=(_0x25ced3['match'](_0x56436f)||[])['length'],_0x4cc1fb=_0x46fa7b&&_0x1329e6===_0x284b22&&_0x1329e6>0x0,_0x5b4db6=_0x2c2081&&_0x2a4a38===_0x55ca35&&_0x2a4a38>0x0;if(_0x46fa7b||_0x2c2081){const _0x6c83b5=await globalThis[_0x3d1e3e(0xd9)][_0x3d1e3e(0x7d)]({'runType':_0x3d1e3e(0xdc),'isDryRun':![]});try{if(_0x4cc1fb){const _0x5cd6ce=await globalThis[_0x3d1e3e(0xd9)][_0x3d1e3e(0xc7)](_0x1c912f,_0x6c83b5,{'_with':!![]});typeof _0x5cd6ce==='string'&&_0x5cd6ce[_0x3d1e3e(0xbd)]>0x0&&(_0xfe6926[_0x3d1e3e(0xb5)]=_0x5cd6ce);}else _0x46fa7b&&console['warn']('[ST-Amily2-Chat-Optimisation][PlotOpt]\x20检测到未闭合的\x20EJS\x20标签(用户输入),已跳过预处理。');}catch(_0x5f1796){return console[_0x3d1e3e(0x81)](_0x3d1e3e(0x8e),_0x5f1796),toastr[_0x3d1e3e(0x81)](_0x3d1e3e(0xe5),_0x3d1e3e(0xc1)),null;}try{if(_0x5b4db6){const _0x3db642=await globalThis[_0x3d1e3e(0xd9)][_0x3d1e3e(0xc7)](_0x25ced3,_0x6c83b5,{'_with':!![]});typeof _0x3db642==='string'&&_0x3db642[_0x3d1e3e(0xbd)]>0x0&&(_0x478a4a=_0x3db642);}else _0x2c2081&&console['warn'](_0x3d1e3e(0xc6));}catch(_0x166b70){try{if(globalThis['EjsTemplate']?.['getSyntaxErrorInfo']&&typeof _0x166b70?.['message']===_0x3d1e3e(0xc2)){const _0x1f53fd=globalThis[_0x3d1e3e(0xd9)][_0x3d1e3e(0xee)](_0x25ced3);console[_0x3d1e3e(0x81)](_0x3d1e3e(0xab),_0x166b70?.[_0x3d1e3e(0xe9)]+(_0x1f53fd||''));}else console[_0x3d1e3e(0x81)](_0x3d1e3e(0x91),_0x166b70);try{const _0x31d8cf=0x7d0,_0x52d864=typeof _0x25ced3==='string'?_0x25ced3[_0x3d1e3e(0x92)](0x0,_0x31d8cf):String(_0x25ced3)['slice'](0x0,_0x31d8cf),_0x3e8102=(_0x25ced3?.[_0x3d1e3e(0xbd)]||0x0)>_0x31d8cf;try{window[_0x3d1e3e(0x9d)]=window[_0x3d1e3e(0x9d)]||{},window[_0x3d1e3e(0x9d)][_0x3d1e3e(0xf7)]=(_0x166b70?.[_0x3d1e3e(0xe9)]||String(_0x166b70))+'',window['Amily2PlotOptDebug'][_0x3d1e3e(0xd2)]=_0x52d864,window[_0x3d1e3e(0x9d)][_0x3d1e3e(0x8d)]=_0x3e8102,window['Amily2PlotOptDebug']['worldOpenClose']={'open':_0x2a4a38,'close':_0x55ca35};}catch(_0xa341bc){}console[_0x3d1e3e(0xc5)](_0x3d1e3e(0x88)+_0x3e8102+')'),console[_0x3d1e3e(0xb8)](_0x52d864),console[_0x3d1e3e(0x71)](),console[_0x3d1e3e(0x96)](_0x3d1e3e(0xb1),{'open':_0x2a4a38,'close':_0x55ca35}),console[_0x3d1e3e(0x81)](_0x3d1e3e(0x9b));}catch(_0x53ea81){console[_0x3d1e3e(0x81)](_0x3d1e3e(0x89),_0x53ea81);}}catch(_0x32c747){console[_0x3d1e3e(0x81)](_0x3d1e3e(0xf9),_0x32c747);}return toastr[_0x3d1e3e(0x81)]('EJS\x20预处理世界书失败,已中止。',_0x3d1e3e(0xc1)),null;}}}}catch(_0x430e25){return console['error'](_0x3d1e3e(0x93),_0x430e25),toastr[_0x3d1e3e(0x81)](_0x3d1e3e(0xb7),'Amily2号'),null;}let _0x286b52='';if(_0x339ebe[_0x3d1e3e(0xe0)])try{const {convertTablesToCsvStringForContentOnly:_0x38d247}=await import(_0x3d1e3e(0xc8)),_0x2e5baf=_0x3d1e3e(0xe8),_0x441526=_0x38d247();_0x441526[_0x3d1e3e(0xac)]()&&(_0x286b52=_0x2e5baf['replace'](_0x3d1e3e(0x7b),_0x441526));}catch(_0x18c788){console[_0x3d1e3e(0x81)](_0x3d1e3e(0x7e),_0x18c788);}let _0x33f326='';const _0x55cf5d=_0x339ebe[_0x3d1e3e(0x73)]||0x0;if(_0x55cf5d>0x0&&_0x5c6909[_0x3d1e3e(0xbd)]>0x0){const _0x2e77c3=_0x5c6909[_0x3d1e3e(0x92)](-_0x55cf5d),_0x321d1c=_0x339ebe[_0x3d1e3e(0xa2)]??![],_0x5d4c61=_0x321d1c?(_0x339ebe[_0x3d1e3e(0x85)]||'')[_0x3d1e3e(0xa3)](',')[_0x3d1e3e(0xf3)](_0xa0cb49=>_0xa0cb49[_0x3d1e3e(0xac)]())[_0x3d1e3e(0x9e)](Boolean):[],_0x792d85=_0x339ebe[_0x3d1e3e(0x9f)]||[];_0x33f326=_0x2e77c3[_0x3d1e3e(0xf3)](_0x9ad018=>{const _0x11184d=_0x3d1e3e;if(_0x9ad018['mes']&&_0x9ad018['mes']['trim']()){let _0x106b1e=_0x9ad018['mes'][_0x11184d(0xac)]();if(_0x321d1c&&_0x5d4c61['length']>0x0){const _0x3235e1=extractBlocksByTags(_0x106b1e,_0x5d4c61);_0x3235e1[_0x11184d(0xbd)]>0x0&&(_0x106b1e=_0x3235e1[_0x11184d(0xe3)]('\x0a\x0a'));}return _0x106b1e=applyExclusionRules(_0x106b1e,_0x792d85),_0x106b1e?(_0x9ad018[_0x11184d(0xf6)]?_0x5a236b:_0x3e5336)+':\x20'+_0x106b1e:null;}return null;})[_0x3d1e3e(0x9e)](Boolean)[_0x3d1e3e(0xe3)]('\x0a');}const _0x121e17=getMixedOrder(_0x3d1e3e(0xdc))||[];let _0x2d983f=0x0;for(const _0x1f5263 of _0x121e17){if(_0x1f5263[_0x3d1e3e(0xce)]==='prompt')_0x4eb58f&&_0x4eb58f[_0x2d983f]&&(_0x2d8b9c[_0x3d1e3e(0x6f)](_0x4eb58f[_0x2d983f]),_0x2d983f++);else{if(_0x1f5263[_0x3d1e3e(0xce)]===_0x3d1e3e(0x99))switch(_0x1f5263['id']){case _0x3d1e3e(0xde):_0x4b36c7[_0x3d1e3e(0xac)]()&&_0x2d8b9c['push']({'role':'system','content':_0x4b36c7[_0x3d1e3e(0xac)]()});break;case _0x3d1e3e(0x77):_0x4a27c9['trim']()&&_0x2d8b9c['push']({'role':'system','content':_0x4a27c9[_0x3d1e3e(0xac)]()});break;case _0x3d1e3e(0xa0):_0x478a4a[_0x3d1e3e(0xac)]()&&_0x2d8b9c[_0x3d1e3e(0x6f)]({'role':_0x3d1e3e(0x94),'content':_0x3d1e3e(0xca)+_0x478a4a[_0x3d1e3e(0xac)]()+'世界书内容>'});break;case'tableEnabled':_0x286b52&&_0x2d8b9c[_0x3d1e3e(0x6f)]({'role':_0x3d1e3e(0x94),'content':_0x286b52});break;case _0x3d1e3e(0xf4):_0x33f326&&_0x2d8b9c[_0x3d1e3e(0x6f)]({'role':_0x3d1e3e(0x94),'content':_0x3d1e3e(0x80)+_0x33f326+'\x0a前文内容>'});break;case _0x3d1e3e(0x98):_0x2d8b9c[_0x3d1e3e(0x6f)]({'role':'user','content':_0x3d1e3e(0x8c)+_0xfe6926[_0x3d1e3e(0xb5)]});break;}}}console['groupCollapsed']('['+extensionName+']\x20发送给AI的最终请求内容'),console[_0x3d1e3e(0xae)](_0x2d8b9c),console[_0x3d1e3e(0x71)]();let _0x250a23='',_0x4452de=0x0;const _0x1e48b9=0x3;let _0x2c9a55=![];while(_0x4452de<_0x1e48b9&&!_0x2c9a55){if(_0x538852['isCancelled'])return console['log']('['+extensionName+_0x3d1e3e(0xeb)),null;_0x4452de++,console[_0x3d1e3e(0xb8)]('['+extensionName+_0x3d1e3e(0xb4)+_0x4452de+_0x3d1e3e(0xf1));const _0x16259c=_0x339ebe[_0x3d1e3e(0xa9)]?await callJqyhAI(_0x2d8b9c):await callAI(_0x2d8b9c,_0x3d1e3e(0xdc));if(_0x538852['isCancelled'])return console[_0x3d1e3e(0xb8)]('['+extensionName+_0x3d1e3e(0x72)),null;if(!_0x16259c){console[_0x3d1e3e(0x96)]('['+extensionName+']\x20第\x20'+_0x4452de+'\x20次尝试获取响应失败,AI返回为空。');continue;}const _0x3ac684=extractContentByTag(_0x16259c,'plot'),_0x2c29e9=_0x3ac684?.['trim']()?_0x3ac684[_0x3d1e3e(0xac)]():_0x16259c['trim']();_0x2c29e9[_0x3d1e3e(0xbd)]>=0x64?(_0x250a23=_0x16259c,_0x2c9a55=!![],console[_0x3d1e3e(0xb8)]('['+extensionName+']\x20第\x20'+_0x4452de+_0x3d1e3e(0xb3)+_0x2c29e9[_0x3d1e3e(0xbd)]+')\x20符合要求。')):console[_0x3d1e3e(0x96)]('['+extensionName+_0x3d1e3e(0x9a)+_0x4452de+_0x3d1e3e(0xe7)+_0x2c29e9[_0x3d1e3e(0xbd)]+',小于100字符。');}if(!_0x2c9a55)return console['error']('['+extensionName+_0x3d1e3e(0xc4)+_0x1e48b9+_0x3d1e3e(0x97)),toastr['error'](_0x3d1e3e(0xe1)+_0x1e48b9+_0x3d1e3e(0xef),_0x3d1e3e(0xed)),null;console[_0x3d1e3e(0xc5)]('['+extensionName+_0x3d1e3e(0xfa)),console[_0x3d1e3e(0xb8)](_0x250a23),console[_0x3d1e3e(0x71)]();const _0x428912=extractContentByTag(_0x250a23,_0x3d1e3e(0xd5)),_0x184da3=_0x428912?.[_0x3d1e3e(0xac)]()?_0x428912[_0x3d1e3e(0xac)]():_0x250a23[_0x3d1e3e(0xac)]();if(_0x184da3){let _0x38d361='',_0x5e09a5=_0x339ebe['plotOpt_finalSystemDirective']?.[_0x3d1e3e(0xac)]()||'';const _0x3b86f1={'sulv1':_0x339ebe[_0x3d1e3e(0xdd)]??0x1,'sulv2':_0x339ebe['plotOpt_ratePersonal']??0x1,'sulv3':_0x339ebe['plotOpt_rateErotic']??0x1,'sulv4':_0x339ebe[_0x3d1e3e(0x8b)]??0x1};for(const _0x182a45 in _0x3b86f1){const _0x33de63=_0x3b86f1[_0x182a45],_0x1b46ae=new RegExp(_0x182a45[_0x3d1e3e(0xd4)](/[-\/\\^$*+?.()|[\]{}]/g,'\x5c$&'),'g');_0x5e09a5=_0x5e09a5[_0x3d1e3e(0xd4)](_0x1b46ae,_0x33de63);}return _0x5e09a5?_0x38d361=_0x5e09a5['replace'](_0x3d1e3e(0xc0),_0x184da3):_0x38d361=_0x184da3,{'contentToAppend':_0x38d361};}else return null;}catch(_0x192cd3){return console[_0x3d1e3e(0x81)]('['+extensionName+']\x20剧情优化任务发生严重错误:',_0x192cd3),toastr[_0x3d1e3e(0x81)](_0x3d1e3e(0xbc)+_0x192cd3[_0x3d1e3e(0xe9)],'严重错误'),null;}finally{console[_0x3d1e3e(0xba)](_0x3d1e3e(0x8f)),console[_0x3d1e3e(0x71)]();}}