mirror of
https://github.com/SilenceLurker/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 13:35:51 +00:00
Update cwb_uiManager.js
This commit is contained in:
@@ -184,7 +184,7 @@ function createCharCardViewerPopupHtml(displayItems) {
|
||||
}
|
||||
|
||||
function bindCharCardViewerPopupEvents($popup) {
|
||||
$popup.on('change', '.cwb-insertion-position', function () {
|
||||
$popup.on('change', '.cwb-insertion-position', function() {
|
||||
const $this = $(this);
|
||||
const $depthContainer = $this.closest('.cwb-insertion-settings-content').find('.cwb-insertion-depth-container');
|
||||
if ($this.val() === 'at_depth') {
|
||||
@@ -200,7 +200,7 @@ function bindCharCardViewerPopupEvents($popup) {
|
||||
showCharCardViewerPopup();
|
||||
});
|
||||
|
||||
$popup.find('#cwb-manual-update-btn').on('click', async function () {
|
||||
$popup.find('#cwb-manual-update-btn').on('click', async function() {
|
||||
const $button = $(this);
|
||||
$button.prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i> 更新中...');
|
||||
await manualUpdateLogic();
|
||||
@@ -217,7 +217,7 @@ function bindCharCardViewerPopupEvents($popup) {
|
||||
$popup.find(`#cwb-char-content-${targetUid}`).addClass('active');
|
||||
});
|
||||
|
||||
$popup.find('.cwb-cyber-tab__delete').on('click', async function (e) {
|
||||
$popup.find('.cwb-cyber-tab__delete').on('click', async function(e) {
|
||||
e.stopPropagation();
|
||||
if (confirm('您确定要删除这个角色条目吗?此操作不可撤销。')) {
|
||||
const uidToDelete = $(this).data('char-uid');
|
||||
@@ -235,9 +235,9 @@ function bindCharCardViewerPopupEvents($popup) {
|
||||
}
|
||||
});
|
||||
|
||||
$popup.find('#cwb-viewer-delete-all').on('click', async function () {
|
||||
$popup.find('#cwb-viewer-delete-all').on('click', async function() {
|
||||
if (confirm('您确定要清除当前聊天中的所有角色卡和总览吗?此操作将删除所有相关条目,且不可撤销。')) {
|
||||
const allUids = $popup.find('.cwb-cyber-tab__button').map(function () {
|
||||
const allUids = $popup.find('.cwb-cyber-tab__button').map(function() {
|
||||
return $(this).data('char-uid');
|
||||
}).get();
|
||||
if (allUids.length > 0) {
|
||||
@@ -278,18 +278,10 @@ function bindCharCardViewerPopupEvents($popup) {
|
||||
if ($field.data('is-array')) {
|
||||
value = value.split('\n').map(l => l.trim()).filter(Boolean);
|
||||
}
|
||||
if (path) {
|
||||
if(path){
|
||||
setNestedValue(collectedData, path, value);
|
||||
}
|
||||
});
|
||||
let localTavernHelper = TavernHelper;
|
||||
if (!localTavernHelper) {
|
||||
// TavernHelper 未定义的情况下触发,但是为什么?
|
||||
(localTavernHelper = window.TavernHelper);
|
||||
if (localTavernHelper) {
|
||||
TavernHelper = localTavernHelper;
|
||||
}
|
||||
}
|
||||
const finalContentToSave = buildCustomFormat(collectedData);
|
||||
const allEntries = await TavernHelper.getLorebookEntries(book);
|
||||
const entryToUpdate = allEntries.find(e => e.uid === targetUid);
|
||||
@@ -334,14 +326,7 @@ function bindCharCardViewerPopupEvents($popup) {
|
||||
order: finalEntryData.order,
|
||||
hasDepthField: 'depth' in finalEntryData
|
||||
});
|
||||
localTavernHelper = TavernHelper;
|
||||
if (!localTavernHelper) {
|
||||
// TavernHelper 未定义的情况下触发,但是为什么?
|
||||
(localTavernHelper = window.TavernHelper);
|
||||
if (localTavernHelper) {
|
||||
TavernHelper = localTavernHelper;
|
||||
}
|
||||
}
|
||||
|
||||
await TavernHelper.setLorebookEntries(book, [finalEntryData]);
|
||||
showToastr('success', '角色卡已成功保存!');
|
||||
} catch (error) {
|
||||
@@ -368,14 +353,6 @@ export async function showCharCardViewerPopup() {
|
||||
bindCharCardViewerPopupEvents($(`#${CHAR_CARD_VIEWER_POPUP_ID}`));
|
||||
return;
|
||||
}
|
||||
let localTavernHelper = TavernHelper;
|
||||
if (!localTavernHelper) {
|
||||
// TavernHelper 未定义的情况下触发,但是为什么?
|
||||
(localTavernHelper = window.TavernHelper);
|
||||
if (localTavernHelper) {
|
||||
TavernHelper = localTavernHelper;
|
||||
}
|
||||
}
|
||||
const allEntries = await TavernHelper.getLorebookEntries(book);
|
||||
let currentChatId = state.currentChatFileIdentifier;
|
||||
|
||||
@@ -430,6 +407,7 @@ export async function showCharCardViewerPopup() {
|
||||
const characterEntries = relevantEntries
|
||||
.filter(entry => !entry.keys.includes('Amily2角色总集'))
|
||||
.map(entry => {
|
||||
try {
|
||||
logDebug(`[DEBUG] 原始条目数据 UID:${entry.uid}`, {
|
||||
position: entry.position,
|
||||
depth: entry.depth,
|
||||
@@ -469,8 +447,12 @@ export async function showCharCardViewerPopup() {
|
||||
insertionDepth: finalDepth,
|
||||
insertionOrder: entry.order ?? 7001,
|
||||
};
|
||||
} catch (e) {
|
||||
logError(`解析角色条目失败 (UID: ${entry.uid}),已跳过。`, e);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(c => c.parsed && Object.keys(c.parsed).length > 0);
|
||||
.filter(c => c && c.parsed && Object.keys(c.parsed).length > 0);
|
||||
|
||||
displayItems = displayItems.concat(characterEntries);
|
||||
|
||||
@@ -641,39 +623,39 @@ export function updateViewerButtonVisibility() {
|
||||
export function bindCwbApiEvents() {
|
||||
console.log('[CWB] Binding API events');
|
||||
|
||||
$('#cwb-api-url').off('input').on('input', function () {
|
||||
$('#cwb-api-url').off('input').on('input', function() {
|
||||
const value = $(this).val();
|
||||
extension_settings[extensionName].cwb_api_url = value;
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#cwb-api-key').off('input').on('input', function () {
|
||||
$('#cwb-api-key').off('input').on('input', function() {
|
||||
const value = $(this).val();
|
||||
extension_settings[extensionName].cwb_api_key = value;
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#cwb-model').off('input').on('input', function () {
|
||||
$('#cwb-model').off('input').on('input', function() {
|
||||
const value = $(this).val();
|
||||
extension_settings[extensionName].cwb_model = value;
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#cwb-temperature').off('input').on('input', function () {
|
||||
$('#cwb-temperature').off('input').on('input', function() {
|
||||
const value = parseFloat($(this).val());
|
||||
$('#cwb-temperature-value').text(value);
|
||||
extension_settings[extensionName].cwb_temperature = value;
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#cwb-max-tokens').off('input').on('input', function () {
|
||||
$('#cwb-max-tokens').off('input').on('input', function() {
|
||||
const value = parseInt($(this).val());
|
||||
$('#cwb-max-tokens-value').text(value);
|
||||
extension_settings[extensionName].cwb_max_tokens = value;
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#cwb-test-connection').off('click').on('click', async function () {
|
||||
$('#cwb-test-connection').off('click').on('click', async function() {
|
||||
const $button = $(this);
|
||||
$button.prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i> 测试中...');
|
||||
|
||||
@@ -686,7 +668,7 @@ export function bindCwbApiEvents() {
|
||||
}
|
||||
});
|
||||
|
||||
$('#cwb-fetch-models').off('click').on('click', async function () {
|
||||
$('#cwb-fetch-models').off('click').on('click', async function() {
|
||||
const $button = $(this);
|
||||
$button.prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i> 获取中...');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user