mirror of
https://github.com/Minidoracat/mcp-feedback-enhanced.git
synced 2025-07-27 02:22:26 +08:00
🐛 修復常用提示詞管理無法正確設定自動提交的問題
This commit is contained in:
parent
e6bf5f74ec
commit
5950a5be17
@ -415,7 +415,8 @@
|
||||
// 3. 初始化設定頁籤 UI
|
||||
this.promptSettingsUI = new window.MCPFeedback.Prompt.PromptSettingsUI({
|
||||
promptManager: this.promptManager,
|
||||
promptModal: this.promptModal
|
||||
promptModal: this.promptModal,
|
||||
settingsManager: this.settingsManager
|
||||
});
|
||||
this.promptSettingsUI.init('#promptManagementContainer');
|
||||
|
||||
@ -574,7 +575,7 @@
|
||||
}
|
||||
|
||||
// 現在可以安全地將舊會話加入歷史記錄
|
||||
this.sessionManager.addSessionToHistory(oldSessionData);
|
||||
this.sessionManager.dataManager.addSessionToHistory(oldSessionData);
|
||||
} else {
|
||||
console.log('⚠️ 無法獲取當前會話數據,跳過歷史記錄保存');
|
||||
// 仍然需要更新當前會話 ID
|
||||
@ -1079,8 +1080,8 @@
|
||||
FeedbackApp.prototype.checkAndStartAutoSubmit = function() {
|
||||
console.log('🔍 檢查自動提交條件...');
|
||||
|
||||
if (!this.autoSubmitManager || !this.settingsManager) {
|
||||
console.log('⚠️ 自動提交管理器或設定管理器未初始化');
|
||||
if (!this.autoSubmitManager || !this.settingsManager || !this.promptManager) {
|
||||
console.log('⚠️ 自動提交管理器、設定管理器或提示詞管理器未初始化');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1095,6 +1096,23 @@
|
||||
timeout: autoSubmitTimeout
|
||||
});
|
||||
|
||||
// 雙重檢查:設定中的 promptId 和提示詞的 isAutoSubmit 狀態
|
||||
let validAutoSubmitPrompt = null;
|
||||
if (autoSubmitPromptId) {
|
||||
const prompt = this.promptManager.getPromptById(autoSubmitPromptId);
|
||||
if (prompt && prompt.isAutoSubmit) {
|
||||
validAutoSubmitPrompt = prompt;
|
||||
} else {
|
||||
console.log('⚠️ 自動提交提示詞驗證失敗:', {
|
||||
promptExists: !!prompt,
|
||||
isAutoSubmit: prompt ? prompt.isAutoSubmit : false
|
||||
});
|
||||
// 清空無效的自動提交設定
|
||||
this.settingsManager.set('autoSubmitPromptId', null);
|
||||
this.settingsManager.set('autoSubmitEnabled', false);
|
||||
}
|
||||
}
|
||||
|
||||
// 檢查當前狀態是否為等待回饋
|
||||
const currentState = this.uiManager ? this.uiManager.getFeedbackState() : null;
|
||||
const isWaitingForFeedback = currentState === window.MCPFeedback.Utils.CONSTANTS.FEEDBACK_WAITING;
|
||||
@ -1102,7 +1120,7 @@
|
||||
console.log('🔍 當前回饋狀態:', currentState, '是否等待回饋:', isWaitingForFeedback);
|
||||
|
||||
// 如果所有條件都滿足,啟動自動提交
|
||||
if (autoSubmitEnabled && autoSubmitPromptId && autoSubmitTimeout && isWaitingForFeedback) {
|
||||
if (autoSubmitEnabled && validAutoSubmitPrompt && autoSubmitTimeout && isWaitingForFeedback) {
|
||||
console.log('✅ 自動提交條件滿足,啟動倒數計時器');
|
||||
this.autoSubmitManager.start(autoSubmitTimeout, autoSubmitPromptId);
|
||||
this.updateAutoSubmitStatus('enabled', autoSubmitTimeout);
|
||||
@ -1153,17 +1171,37 @@
|
||||
FeedbackApp.prototype.performAutoSubmit = function() {
|
||||
console.log('⏰ 執行自動提交...');
|
||||
|
||||
if (!this.autoSubmitManager || !this.promptManager) {
|
||||
console.error('❌ 自動提交管理器或提示詞管理器未初始化');
|
||||
if (!this.autoSubmitManager || !this.promptManager || !this.settingsManager) {
|
||||
console.error('❌ 自動提交管理器、提示詞管理器或設定管理器未初始化');
|
||||
this.autoSubmitManager && this.autoSubmitManager.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
const promptId = this.autoSubmitManager.currentPromptId;
|
||||
const autoSubmitPromptId = this.settingsManager.get('autoSubmitPromptId');
|
||||
|
||||
// 雙重檢查:確保 promptId 有效且與設定一致
|
||||
if (!promptId || !autoSubmitPromptId || promptId !== autoSubmitPromptId) {
|
||||
console.error('❌ 自動提交提示詞 ID 不一致或為空:', {
|
||||
currentPromptId: promptId,
|
||||
settingsPromptId: autoSubmitPromptId
|
||||
});
|
||||
this.pauseAutoSubmit('提示詞 ID 不一致');
|
||||
return;
|
||||
}
|
||||
|
||||
const prompt = this.promptManager.getPromptById(promptId);
|
||||
|
||||
if (!prompt) {
|
||||
console.error('❌ 找不到自動提交提示詞:', promptId);
|
||||
window.MCPFeedback.Utils.showMessage('自動提交失敗:找不到指定的提示詞', window.MCPFeedback.Utils.CONSTANTS.MESSAGE_ERROR);
|
||||
this.pauseAutoSubmit('找不到指定的提示詞');
|
||||
return;
|
||||
}
|
||||
|
||||
// 檢查提示詞的 isAutoSubmit 狀態
|
||||
if (!prompt.isAutoSubmit) {
|
||||
console.error('❌ 提示詞不是自動提交狀態:', prompt.name);
|
||||
this.pauseAutoSubmit('提示詞不是自動提交狀態');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1193,6 +1231,38 @@
|
||||
this.autoSubmitManager.stop();
|
||||
};
|
||||
|
||||
/**
|
||||
* 暫停自動提交功能(當檢查失敗時)
|
||||
*/
|
||||
FeedbackApp.prototype.pauseAutoSubmit = function(reason) {
|
||||
console.error('⏸️ 暫停自動提交功能,原因:', reason);
|
||||
|
||||
// 停止倒數計時器
|
||||
if (this.autoSubmitManager) {
|
||||
this.autoSubmitManager.stop();
|
||||
}
|
||||
|
||||
// 清空自動提交設定
|
||||
if (this.settingsManager) {
|
||||
this.settingsManager.set('autoSubmitEnabled', false);
|
||||
this.settingsManager.set('autoSubmitPromptId', null);
|
||||
}
|
||||
|
||||
// 清空所有提示詞的自動提交標記
|
||||
if (this.promptManager) {
|
||||
this.promptManager.clearAutoSubmitPrompt();
|
||||
}
|
||||
|
||||
// 更新 UI 狀態
|
||||
this.updateAutoSubmitStatus('disabled');
|
||||
|
||||
// 顯示錯誤訊息
|
||||
const message = window.i18nManager ?
|
||||
window.i18nManager.t('autoSubmit.paused', '自動提交已暫停:') + reason :
|
||||
'自動提交已暫停:' + reason;
|
||||
window.MCPFeedback.Utils.showMessage(message, window.MCPFeedback.Utils.CONSTANTS.MESSAGE_ERROR);
|
||||
};
|
||||
|
||||
/**
|
||||
* 顯示倒數計時器
|
||||
*/
|
||||
|
@ -23,6 +23,7 @@
|
||||
// 依賴注入
|
||||
this.promptManager = options.promptManager || null;
|
||||
this.promptModal = options.promptModal || null;
|
||||
this.settingsManager = options.settingsManager || null;
|
||||
|
||||
// UI 元素
|
||||
this.container = null;
|
||||
@ -320,23 +321,40 @@
|
||||
this.promptManager.clearAutoSubmitPrompt();
|
||||
this.showSuccess(this.t('prompts.management.autoSubmitCancelled', '已取消自動提交設定'));
|
||||
|
||||
// 更新設定管理器中的自動提交提示詞 ID
|
||||
if (window.MCPFeedback && window.MCPFeedback.settingsManager) {
|
||||
window.MCPFeedback.settingsManager.set('autoSubmitPromptId', null);
|
||||
// 清空設定管理器中的自動提交設定
|
||||
if (this.settingsManager) {
|
||||
this.settingsManager.set('autoSubmitPromptId', null);
|
||||
this.settingsManager.set('autoSubmitEnabled', false);
|
||||
console.log('🔄 已清空自動提交設定');
|
||||
} else {
|
||||
console.warn('⚠️ settingsManager 未設定,無法清空自動提交設定');
|
||||
}
|
||||
} else {
|
||||
// 設定為自動提交
|
||||
this.promptManager.setAutoSubmitPrompt(promptId);
|
||||
this.showSuccess(this.t('prompts.management.autoSubmitSet', '已設定為自動提交提示詞:') + prompt.name);
|
||||
|
||||
// 更新設定管理器中的自動提交提示詞 ID
|
||||
if (window.MCPFeedback && window.MCPFeedback.settingsManager) {
|
||||
window.MCPFeedback.settingsManager.set('autoSubmitPromptId', promptId);
|
||||
// 更新設定管理器中的自動提交設定
|
||||
if (this.settingsManager) {
|
||||
console.log('🔧 設定前的 autoSubmitPromptId:', this.settingsManager.get('autoSubmitPromptId'));
|
||||
this.settingsManager.set('autoSubmitPromptId', promptId);
|
||||
this.settingsManager.set('autoSubmitEnabled', true);
|
||||
console.log('✅ 已設定自動提交提示詞 ID:', promptId);
|
||||
console.log('🔧 設定後的 autoSubmitPromptId:', this.settingsManager.get('autoSubmitPromptId'));
|
||||
} else {
|
||||
console.warn('⚠️ settingsManager 未設定,無法更新自動提交設定');
|
||||
}
|
||||
}
|
||||
|
||||
// 更新自動提交下拉選單
|
||||
this.updateAutoSubmitSelect();
|
||||
|
||||
// 觸發自動提交狀態變更事件
|
||||
if (this.settingsManager && this.settingsManager.triggerAutoSubmitStateChange) {
|
||||
this.settingsManager.triggerAutoSubmitStateChange(prompt.isAutoSubmit);
|
||||
} else {
|
||||
console.warn('⚠️ settingsManager 或 triggerAutoSubmitStateChange 方法未設定');
|
||||
}
|
||||
} catch (error) {
|
||||
this.showError(error.message);
|
||||
}
|
||||
@ -346,8 +364,10 @@
|
||||
* 更新自動提交下拉選單
|
||||
*/
|
||||
PromptSettingsUI.prototype.updateAutoSubmitSelect = function() {
|
||||
console.log('🔄 updateAutoSubmitSelect 開始執行');
|
||||
const autoSubmitSelect = document.getElementById('autoSubmitPromptSelect');
|
||||
if (!autoSubmitSelect || !this.promptManager) {
|
||||
console.log('❌ updateAutoSubmitSelect: 缺少必要元素');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -359,6 +379,7 @@
|
||||
// 新增所有提示詞選項
|
||||
const prompts = this.promptManager.getAllPrompts();
|
||||
let autoSubmitPromptId = null;
|
||||
console.log('🔄 updateAutoSubmitSelect 檢查提示詞:', prompts.map(p => ({id: p.id, name: p.name, isAutoSubmit: p.isAutoSubmit})));
|
||||
|
||||
prompts.forEach(function(prompt) {
|
||||
const option = document.createElement('option');
|
||||
@ -367,13 +388,26 @@
|
||||
if (prompt.isAutoSubmit) {
|
||||
option.selected = true;
|
||||
autoSubmitPromptId = prompt.id;
|
||||
console.log('🔄 找到自動提交提示詞:', prompt.name, prompt.id);
|
||||
}
|
||||
autoSubmitSelect.appendChild(option);
|
||||
});
|
||||
|
||||
// 同步更新設定管理器中的自動提交提示詞 ID
|
||||
if (autoSubmitPromptId && window.MCPFeedback && window.MCPFeedback.settingsManager) {
|
||||
window.MCPFeedback.settingsManager.set('autoSubmitPromptId', autoSubmitPromptId);
|
||||
if (this.settingsManager) {
|
||||
console.log('🔄 updateAutoSubmitSelect 設定前:', this.settingsManager.get('autoSubmitPromptId'));
|
||||
if (autoSubmitPromptId) {
|
||||
this.settingsManager.set('autoSubmitPromptId', autoSubmitPromptId);
|
||||
this.settingsManager.set('autoSubmitEnabled', true);
|
||||
console.log('🔄 updateAutoSubmitSelect 同步設定:', autoSubmitPromptId);
|
||||
} else {
|
||||
this.settingsManager.set('autoSubmitPromptId', null);
|
||||
this.settingsManager.set('autoSubmitEnabled', false);
|
||||
console.log('🔄 updateAutoSubmitSelect 清空設定');
|
||||
}
|
||||
console.log('🔄 updateAutoSubmitSelect 設定後:', this.settingsManager.get('autoSubmitPromptId'));
|
||||
} else {
|
||||
console.warn('⚠️ updateAutoSubmitSelect: settingsManager 未設定,無法同步設定');
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -364,6 +364,11 @@
|
||||
SettingsManager.prototype.triggerAutoSubmitStateChange = function(enabled) {
|
||||
if (this.onAutoSubmitStateChange) {
|
||||
const settings = this.getAutoSubmitSettings();
|
||||
console.log('🔍 triggerAutoSubmitStateChange 調試:', {
|
||||
enabled: enabled,
|
||||
settings: settings,
|
||||
currentSettings: this.currentSettings
|
||||
});
|
||||
this.onAutoSubmitStateChange(enabled, settings);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user