mirror of
https://github.com/SilenceLurker/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 07:45:51 +00:00
Update prese_state.js
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { SETTINGS_KEY, defaultPrompts, defaultMixedOrder } from './config.js';
|
import { SETTINGS_KEY, defaultPrompts, defaultMixedOrder } from './config.js';
|
||||||
|
import { safeTriggerSlash } from '../core/tavernhelper-compatibility.js';
|
||||||
|
|
||||||
let presetManager = {
|
let presetManager = {
|
||||||
activePreset: '默认预设',
|
activePreset: '默认预设',
|
||||||
@@ -225,10 +226,10 @@ export function savePresets() {
|
|||||||
toastr.success(`预设 "${presetManager.activePreset}" 已保存!`);
|
toastr.success(`预设 "${presetManager.activePreset}" 已保存!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPresetPrompts(sectionKey) {
|
export async function getPresetPrompts(sectionKey) {
|
||||||
const presets = currentPresets[sectionKey];
|
const presets = currentPresets[sectionKey];
|
||||||
const order = currentMixedOrder[sectionKey];
|
const order = currentMixedOrder[sectionKey];
|
||||||
|
|
||||||
if (!presets || presets.length === 0 || !order) {
|
if (!presets || presets.length === 0 || !order) {
|
||||||
console.warn(`Amily2: getPresetPrompts - 没有找到 ${sectionKey} 的数据`);
|
console.warn(`Amily2: getPresetPrompts - 没有找到 ${sectionKey} 的数据`);
|
||||||
return null;
|
return null;
|
||||||
@@ -237,14 +238,40 @@ export function getPresetPrompts(sectionKey) {
|
|||||||
const orderedPrompts = [];
|
const orderedPrompts = [];
|
||||||
|
|
||||||
console.log(`Amily2: getPresetPrompts - ${sectionKey} 顺序:`, order);
|
console.log(`Amily2: getPresetPrompts - ${sectionKey} 顺序:`, order);
|
||||||
|
|
||||||
order.forEach((item, index) => {
|
const originalToastr = window.toastr;
|
||||||
if (item.type === 'prompt' && presets[item.index] !== undefined) {
|
const dummyToastr = {
|
||||||
const prompt = JSON.parse(JSON.stringify(presets[item.index]));
|
success: () => {},
|
||||||
orderedPrompts.push(prompt);
|
info: () => {},
|
||||||
console.log(`Amily2: 添加提示词 ${index}:`, { role: prompt.role, content: prompt.content.substring(0, 50) + '...' });
|
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} 个提示词`);
|
console.log(`Amily2: getPresetPrompts - ${sectionKey} 返回 ${orderedPrompts.length} 个提示词`);
|
||||||
return orderedPrompts.length > 0 ? orderedPrompts : null;
|
return orderedPrompts.length > 0 ? orderedPrompts : null;
|
||||||
|
|||||||
Reference in New Issue
Block a user