From cc3a05e9badc28ee526e7d2232b6411543264999 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Fri, 12 Sep 2025 12:39:14 +0800 Subject: [PATCH] Update prese_state.js --- PresetSettings/prese_state.js | 45 ++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/PresetSettings/prese_state.js b/PresetSettings/prese_state.js index fd1759c..30ec597 100644 --- a/PresetSettings/prese_state.js +++ b/PresetSettings/prese_state.js @@ -1,4 +1,5 @@ import { SETTINGS_KEY, defaultPrompts, defaultMixedOrder } from './config.js'; +import { safeTriggerSlash } from '../core/tavernhelper-compatibility.js'; let presetManager = { activePreset: '默认预设', @@ -225,10 +226,10 @@ export function savePresets() { toastr.success(`预设 "${presetManager.activePreset}" 已保存!`); } -export function getPresetPrompts(sectionKey) { +export async function getPresetPrompts(sectionKey) { const presets = currentPresets[sectionKey]; const order = currentMixedOrder[sectionKey]; - + if (!presets || presets.length === 0 || !order) { console.warn(`Amily2: getPresetPrompts - 没有找到 ${sectionKey} 的数据`); return null; @@ -237,14 +238,40 @@ export function getPresetPrompts(sectionKey) { const orderedPrompts = []; console.log(`Amily2: getPresetPrompts - ${sectionKey} 顺序:`, order); - - order.forEach((item, index) => { - if (item.type === 'prompt' && presets[item.index] !== undefined) { - const prompt = JSON.parse(JSON.stringify(presets[item.index])); - orderedPrompts.push(prompt); - console.log(`Amily2: 添加提示词 ${index}:`, { role: prompt.role, content: prompt.content.substring(0, 50) + '...' }); + + const originalToastr = window.toastr; + const dummyToastr = { + success: () => {}, + info: () => {}, + warning: () => {}, + error: () => {}, + clear: () => {} + }; + + try { + window.toastr = dummyToastr; + + for (const [index, item] of order.entries()) { + if (item.type === 'prompt' && presets[item.index] !== undefined) { + const prompt = JSON.parse(JSON.stringify(presets[item.index])); + + if (prompt.content) { + try { + const command = `/echo ${prompt.content}`; + const replacedContent = await safeTriggerSlash(command); + prompt.content = replacedContent; + } catch (error) { + console.error(`[Amily2] 宏替换失败 for prompt at index ${index}:`, error); + } + } + + orderedPrompts.push(prompt); + console.log(`Amily2: 添加提示词 ${index}:`, { role: prompt.role, content: prompt.content.substring(0, 50) + '...' }); + } } - }); + } finally { + window.toastr = originalToastr; + } console.log(`Amily2: getPresetPrompts - ${sectionKey} 返回 ${orderedPrompts.length} 个提示词`); return orderedPrompts.length > 0 ? orderedPrompts : null;