repair bug
This commit is contained in:
1 parent
dc805b250f
commit
2c85508336
2 files changed
+127
-18
No files matched your search
@@ -13,7 +13,7 @@
|
||||
import { ref, onMounted, computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useChat } from '../composables/useChat';
|
||||
import { Send, Bot, Loader2, ArrowLeft, Plus, Menu, Star, Copy, Edit2, RotateCw, Check } from 'lucide-vue-next';
|
||||
import { Send, Bot, Loader2, ArrowLeft, Plus, Menu, Star, Copy, Edit2, RotateCw, Check, X, Trash2 } from 'lucide-vue-next';
|
||||
import { marked } from 'marked';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { config } from '../config';
|
||||
@@ -263,7 +263,9 @@ const getSourceLinks = (resources: any[] = []): SourceFileLink[] => {
|
||||
if (isNoisySourceName(name)) continue;
|
||||
// 根据配置决定是否显示 MD 文件
|
||||
if ( (isMarkdownFileName(name) || isMarkdownByUrl(url))) continue;
|
||||
const key = `${name}|${url}`;
|
||||
|
||||
// Deduplicate by name if it looks like a filename, else by name + base URL
|
||||
const key = looksLikeFileName(name) ? name : `${name}|${url.split('?')[0]}`;
|
||||
if (!map.has(key)) {
|
||||
map.set(key, { name, url });
|
||||
}
|
||||
@@ -288,12 +290,12 @@ const getMessageLinks = (msg: any): SourceFileLink[] => {
|
||||
if (isNoisySourceName(link.name)) continue;
|
||||
if ( (isMarkdownFileName(link.name) || isMarkdownByUrl(link.url))) continue;
|
||||
if (isMarkdownFileName(link.name)) {
|
||||
const key = `${link.name}|${link.url}`;
|
||||
const key = looksLikeFileName(link.name) ? link.name : `${link.name}|${link.url.split('?')[0]}`;
|
||||
if (!map.has(key)) map.set(key, link);
|
||||
continue;
|
||||
}
|
||||
if (isNoisySourceUrl(link.url) && !looksLikeFileName(link.name)) continue;
|
||||
const key = `${link.name}|${link.url}`;
|
||||
const key = looksLikeFileName(link.name) ? link.name : `${link.name}|${link.url.split('?')[0]}`;
|
||||
if (!map.has(key)) map.set(key, link);
|
||||
}
|
||||
};
|
||||
@@ -484,6 +486,43 @@ const loadHistory = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const clearAllHistory = async () => {
|
||||
if (!confirm('确定要清除全部聊天历史记录吗?此操作不可恢复。')) return;
|
||||
try {
|
||||
const res = await fetch(`/api/chat/sessions?agent_id=${agentId}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
if (res.ok) {
|
||||
history.value = [];
|
||||
if (conversationId.value) {
|
||||
startNewChat();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to clear history', e);
|
||||
}
|
||||
};
|
||||
|
||||
const deleteHistoryItem = async (id: string, event: Event) => {
|
||||
event.stopPropagation();
|
||||
if (!confirm('确定要删除这条聊天记录吗?')) return;
|
||||
try {
|
||||
const res = await fetch(`/api/chat/sessions/${id}?agent_id=${agentId}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
if (res.ok) {
|
||||
history.value = history.value.filter(h => h.conversation_id !== id);
|
||||
if (conversationId.value === id) {
|
||||
startNewChat();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to delete history item', e);
|
||||
}
|
||||
};
|
||||
|
||||
const loadConversation = async (id: string) => {
|
||||
if (conversationId.value === id) return;
|
||||
|
||||
@@ -607,25 +646,42 @@ const submitFeedback = async () => {
|
||||
<span class="text-sm font-semibold uppercase tracking-[0.14em] text-slate-500 dark:text-slate-300">{{ $t('chat.history') }}</span>
|
||||
<ThemeToggleButton />
|
||||
</div>
|
||||
<button @click="startNewChat(); isSidebarOpen = false;" class="mt-3 inline-flex w-[92%] max-w-[320px] self-center items-center justify-center gap-2 rounded-xl bg-gradient-to-r from-cyan-500 to-blue-500 px-5 py-2.5 text-sm font-semibold text-white shadow-sm shadow-cyan-500/20 transition-all hover:from-cyan-400 hover:to-blue-400 hover:shadow-md hover:shadow-cyan-500/25 md:mt-4 md:w-[88%] md:max-w-none md:py-3">
|
||||
<Plus class="h-4 w-4" /> {{ $t('chat.newChat') }}
|
||||
</button>
|
||||
<div class="mt-3 flex items-center gap-2 md:mt-4">
|
||||
<button @click="startNewChat(); isSidebarOpen = false;" class="flex-1 inline-flex items-center justify-center gap-2 rounded-xl bg-gradient-to-r from-cyan-500 to-blue-500 px-4 py-2.5 text-sm font-semibold text-white shadow-sm shadow-cyan-500/20 transition-all hover:from-cyan-400 hover:to-blue-400 hover:shadow-md hover:shadow-cyan-500/25 md:py-3">
|
||||
<Plus class="h-4 w-4" /> {{ $t('chat.newChat') }}
|
||||
</button>
|
||||
<button v-if="history.length > 0" @click="clearAllHistory" class="inline-flex items-center justify-center gap-1 rounded-xl border border-red-200 bg-red-50 px-2 py-2.5 text-xs font-semibold text-red-600 transition-all hover:bg-red-100 hover:text-red-700 dark:border-red-900/30 dark:bg-red-900/20 dark:text-red-400 dark:hover:bg-red-900/40 md:px-3 md:py-3" title="全部清除">
|
||||
<Trash2 class="h-4 w-4" /> <span class="hidden md:inline">全部清除</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-y-auto px-2.5 py-2.5 scrollbar-thin md:px-3 md:py-3">
|
||||
<div v-if="history.length === 0" class="py-8 text-center text-sm italic text-slate-400 md:py-10">{{ $t('chat.noHistory') }}</div>
|
||||
<div v-else class="divide-y divide-slate-200/70 dark:divide-slate-700/70">
|
||||
<button
|
||||
v-for="item in history"
|
||||
:key="item.conversation_id"
|
||||
class="w-full truncate px-2 py-3 text-left text-sm transition-colors md:px-3"
|
||||
:class="conversationId === item.conversation_id
|
||||
? 'font-semibold text-cyan-700 dark:text-cyan-200'
|
||||
: 'text-slate-600 hover:bg-slate-100/70 hover:text-slate-900 dark:text-slate-300 dark:hover:bg-slate-800/60 dark:hover:text-slate-100'"
|
||||
@click="loadConversation(item.conversation_id); isSidebarOpen = false;"
|
||||
>
|
||||
{{ item.title || $t('chat.newChat') }}
|
||||
</button>
|
||||
<div
|
||||
v-for="item in history"
|
||||
:key="item.conversation_id"
|
||||
class="group relative flex w-full items-center justify-between transition-colors"
|
||||
:class="conversationId === item.conversation_id ? 'bg-slate-100/50 dark:bg-slate-800/30' : 'hover:bg-slate-100/70 dark:hover:bg-slate-800/60'"
|
||||
>
|
||||
<button
|
||||
class="flex-1 truncate px-2 py-3 text-left text-sm md:px-3 pr-8"
|
||||
:class="conversationId === item.conversation_id
|
||||
? 'font-semibold text-cyan-700 dark:text-cyan-200'
|
||||
: 'text-slate-600 hover:text-slate-900 dark:text-slate-300 dark:hover:text-slate-100'"
|
||||
@click="loadConversation(item.conversation_id); isSidebarOpen = false;"
|
||||
>
|
||||
{{ item.title || $t('chat.newChat') }}
|
||||
</button>
|
||||
<button
|
||||
@click="deleteHistoryItem(item.conversation_id, $event)"
|
||||
class="absolute right-2 p-1.5 text-slate-400 opacity-0 transition-opacity hover:text-red-500 group-hover:opacity-100 dark:hover:text-red-400"
|
||||
title="清除该记录"
|
||||
>
|
||||
<X class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user