Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 64f0aa0c0b | |||
| 8ddc50a0a9 |
@@ -60,6 +60,10 @@
|
||||
.action-btn:hover { background: #e8e8e8; border-color: #ccc; }
|
||||
.action-btn.copied { color: #10a37f; border-color: #10a37f; background: #e8f5e9; }
|
||||
.action-btn.regenerate:hover { color: #667eea; border-color: #667eea; }
|
||||
.action-btn.edit:hover { color: #10a37f; border-color: #10a37f; }
|
||||
|
||||
/* 用户消息编辑样式 */
|
||||
.edit-textarea:focus { outline: none; border-color: #10a37f; box-shadow: 0 0 0 2px rgba(16,163,127,0.1); }
|
||||
|
||||
/* 版本切换控件 - 简洁版 */
|
||||
.version-switcher { display: none; align-items: center; gap: 4px; margin-left: 4px; }
|
||||
@@ -197,8 +201,8 @@
|
||||
</div>
|
||||
<div class="file-preview-area" id="filePreviewArea"></div>
|
||||
<div class="quick-phrases-bar">
|
||||
<div class="tool-toggle">
|
||||
<input type="checkbox" id="enableSearch" checked>
|
||||
<div class="tool-toggle" id="toolToggleArea">
|
||||
<input type="checkbox" id="enableSearch" checked onchange="showToolWarning()">
|
||||
<label for="enableSearch"><i class="ri-search-line"></i> 搜索</label>
|
||||
</div>
|
||||
<button class="add-phrase-btn" onclick="showAddPhraseModal()"><i class="ri-add-line"></i> 添加</button>
|
||||
@@ -287,6 +291,8 @@
|
||||
const res = await fetch('/api/v2/providers');
|
||||
const data = await res.json();
|
||||
providers = data.providers || [];
|
||||
// 加载后检查工具支持(如果agents已加载)
|
||||
if (agents.length > 0) showToolWarning();
|
||||
} catch (e) { console.error('加载Provider失败:', e); }
|
||||
}
|
||||
|
||||
@@ -298,6 +304,52 @@
|
||||
return provider?.supports_vision || false;
|
||||
}
|
||||
|
||||
// 检查当前Agent是否支持某个工具
|
||||
function checkAgentToolSupport(toolType) {
|
||||
const agent = agents.find(a => a.id === currentAgentId);
|
||||
if (!agent) return false;
|
||||
const agentTools = agent.tools || [];
|
||||
return agentTools.includes(toolType);
|
||||
}
|
||||
|
||||
// 获取当前Agent不支持的工具列表(用户已启用但Agent不支持)
|
||||
function getUnsupportedTools() {
|
||||
const unsupported = [];
|
||||
const enableSearch = document.getElementById('enableSearch').checked;
|
||||
if (enableSearch && !checkAgentToolSupport('search')) {
|
||||
unsupported.push('搜索');
|
||||
}
|
||||
return unsupported;
|
||||
}
|
||||
|
||||
// 显示工具不支持提示
|
||||
function showToolWarning() {
|
||||
const unsupported = getUnsupportedTools();
|
||||
const warningDiv = document.getElementById('tool-warning-tip');
|
||||
|
||||
if (unsupported.length > 0) {
|
||||
const agent = agents.find(a => a.id === currentAgentId);
|
||||
const agentName = agent?.display_name || agent?.name || '当前Agent';
|
||||
const msg = `<i class="ri-alert-line"></i> <strong>${agentName}</strong> 不支持 <strong>${unsupported.join('、')}</strong> 工具,请关闭或切换Agent`;
|
||||
|
||||
if (warningDiv) {
|
||||
warningDiv.innerHTML = msg;
|
||||
warningDiv.style.display = 'block';
|
||||
} else {
|
||||
const newWarning = document.createElement('div');
|
||||
newWarning.id = 'tool-warning-tip';
|
||||
newWarning.style.cssText = 'margin-top:8px;padding:8px 12px;background:#fff3cd;border:1px solid #ffc107;border-radius:6px;font-size:13px;color:#856404;';
|
||||
newWarning.innerHTML = msg;
|
||||
document.getElementById('toolToggleArea').appendChild(newWarning);
|
||||
}
|
||||
// 禁用发送按钮
|
||||
document.getElementById('sendBtn').disabled = true;
|
||||
} else {
|
||||
if (warningDiv) warningDiv.style.display = 'none';
|
||||
document.getElementById('sendBtn').disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 加载Agent
|
||||
async function loadAgents() {
|
||||
try {
|
||||
@@ -307,6 +359,8 @@
|
||||
const defaultAgent = agents.find(a => a.is_default) || agents[0];
|
||||
if (defaultAgent) currentAgentId = defaultAgent.id;
|
||||
renderAgentSelect();
|
||||
// 加载后检查工具支持
|
||||
showToolWarning();
|
||||
} catch (e) { console.error('加载Agent失败:', e); }
|
||||
}
|
||||
|
||||
@@ -329,6 +383,8 @@
|
||||
if (ws?.readyState === WebSocket.OPEN) ws.send(JSON.stringify({ action: 'switch_agent', agent_id: currentAgentId }));
|
||||
await createNewConversation();
|
||||
showAgentSwitchNotice();
|
||||
// 切换Agent后检查工具支持
|
||||
showToolWarning();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,6 +496,9 @@
|
||||
html += `<span class="version-label" id="${messageId}_version_label">1/1</span>`;
|
||||
html += `<button class="version-arrow" onclick="switchVersion('${messageId}', 1)" data-dir="next"><i class="ri-arrow-right-s-line"></i></button>`;
|
||||
html += `</span>`;
|
||||
} else {
|
||||
// 用户消息添加编辑按钮
|
||||
html += `<button class="action-btn edit" onclick="editUserMessage(this)" title="编辑并重新发送"><i class="ri-edit-line"></i> 编辑</button>`;
|
||||
}
|
||||
html += `</div>`;
|
||||
|
||||
@@ -742,6 +801,136 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑用户消息并重新发送
|
||||
let editingUserMessage = null; // 正在编辑的用户消息元素
|
||||
|
||||
function editUserMessage(btn) {
|
||||
const messageDiv = btn.closest('.message.user');
|
||||
if (!messageDiv) return;
|
||||
|
||||
// 获取消息内容
|
||||
const contentDiv = messageDiv.querySelector('.user-message-text');
|
||||
const originalContent = contentDiv.textContent;
|
||||
const actionsDiv = messageDiv.querySelector('.message-actions');
|
||||
|
||||
// 保存原始状态用于取消
|
||||
editingUserMessage = {
|
||||
element: messageDiv,
|
||||
originalContent: originalContent,
|
||||
contentDiv: contentDiv,
|
||||
actionsDiv: actionsDiv
|
||||
};
|
||||
|
||||
// 将消息文本变成可编辑的textarea
|
||||
contentDiv.innerHTML = `<textarea class="edit-textarea" style="width:100%;min-height:60px;padding:8px;border:1px solid #ddd;border-radius:8px;font-size:15px;resize:vertical;">${escapeHtml(originalContent)}</textarea>`;
|
||||
|
||||
// 隐藏原有操作按钮,显示编辑操作按钮
|
||||
actionsDiv.innerHTML = `
|
||||
<button class="action-btn" onclick="confirmEditMessage()" style="background:#10a37f;color:white;border-color:#10a37f;"><i class="ri-check-line"></i> 确认</button>
|
||||
<button class="action-btn" onclick="cancelEditMessage()"><i class="ri-close-line"></i> 取消</button>
|
||||
`;
|
||||
|
||||
// 聚焦到textarea
|
||||
const textarea = contentDiv.querySelector('.edit-textarea');
|
||||
textarea.focus();
|
||||
textarea.setSelectionRange(textarea.value.length, textarea.value.length);
|
||||
|
||||
// 添加Ctrl+Enter快捷键确认
|
||||
textarea.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Enter' && e.ctrlKey) {
|
||||
e.preventDefault();
|
||||
confirmEditMessage();
|
||||
}
|
||||
if (e.key === 'Escape') {
|
||||
e.preventDefault();
|
||||
cancelEditMessage();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function cancelEditMessage() {
|
||||
if (!editingUserMessage) return;
|
||||
|
||||
// 恢复原始内容
|
||||
editingUserMessage.contentDiv.innerHTML = escapeHtml(editingUserMessage.originalContent);
|
||||
|
||||
// 恢复原始操作按钮
|
||||
editingUserMessage.actionsDiv.innerHTML = `
|
||||
<button class="action-btn" onclick="copyMessage(this)"><i class="ri-file-copy-line"></i> 复制</button>
|
||||
<button class="action-btn edit" onclick="editUserMessage(this)" title="编辑并重新发送"><i class="ri-edit-line"></i> 编辑</button>
|
||||
`;
|
||||
|
||||
editingUserMessage = null;
|
||||
}
|
||||
|
||||
function confirmEditMessage() {
|
||||
if (!editingUserMessage) return;
|
||||
|
||||
const textarea = editingUserMessage.contentDiv.querySelector('.edit-textarea');
|
||||
const newContent = textarea.value.trim();
|
||||
|
||||
if (!newContent) {
|
||||
alert('消息内容不能为空');
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果内容没有变化,直接取消编辑
|
||||
if (newContent === editingUserMessage.originalContent) {
|
||||
cancelEditMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
// 更新消息内容
|
||||
editingUserMessage.contentDiv.innerHTML = escapeHtml(newContent);
|
||||
|
||||
// 恢复操作按钮
|
||||
editingUserMessage.actionsDiv.innerHTML = `
|
||||
<button class="action-btn" onclick="copyMessage(this)"><i class="ri-file-copy-line"></i> 复制</button>
|
||||
<button class="action-btn edit" onclick="editUserMessage(this)" title="编辑并重新发送"><i class="ri-edit-line"></i> 编辑</button>
|
||||
`;
|
||||
|
||||
// 更新最后用户消息记录
|
||||
lastUserMessage = newContent;
|
||||
|
||||
// 找到下一条assistant消息,设置重新生成标志
|
||||
const container = document.getElementById('messagesContainer');
|
||||
const allMessages = container.querySelectorAll('.message');
|
||||
let nextAssistantId = null;
|
||||
|
||||
for (let i = 0; i < allMessages.length; i++) {
|
||||
if (allMessages[i] === editingUserMessage.element && i + 1 < allMessages.length) {
|
||||
const nextMsg = allMessages[i + 1];
|
||||
if (nextMsg.classList.contains('assistant')) {
|
||||
nextAssistantId = nextMsg.id || nextMsg.dataset.messageId;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (nextAssistantId) {
|
||||
isRegenerating = true;
|
||||
regeneratingMessageId = nextAssistantId;
|
||||
showLoadingIndicator(nextAssistantId);
|
||||
} else {
|
||||
// 没有assistant消息,需要创建新的
|
||||
isRegenerating = false;
|
||||
regeneratingMessageId = null;
|
||||
}
|
||||
|
||||
editingUserMessage = null;
|
||||
|
||||
// 重新发送编辑后的消息
|
||||
document.getElementById('sendBtn').disabled = true;
|
||||
if (ws?.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({
|
||||
action: 'chat',
|
||||
message: newContent,
|
||||
conversation_id: currentConversationId,
|
||||
agent_id: currentAgentId
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||||
}
|
||||
@@ -897,6 +1086,16 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查工具支持
|
||||
const unsupported = getUnsupportedTools();
|
||||
if (unsupported.length > 0) {
|
||||
const agent = agents.find(a => a.id === currentAgentId);
|
||||
const agentName = agent?.display_name || agent?.name || '当前Agent';
|
||||
alert(`⚠️ ${agentName} 不支持 ${unsupported.join('、')} 工具\n\n请关闭不支持的工具,或切换到支持该工具的Agent。`);
|
||||
document.getElementById('sendBtn').disabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
document.getElementById('sendBtn').disabled = true;
|
||||
input.value = '';
|
||||
input.style.height = 'auto';
|
||||
|
||||
BIN
uploads/images/1776137541_298f5318.png
Normal file
BIN
uploads/images/1776137541_298f5318.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 147 KiB |
Reference in New Issue
Block a user