合并代码,解决冲突
(cherry picked from commit 8b23bd771f04ceb1b9c1e3ae021d75001af5ba2f)
This commit is contained in:
1 parent
23badf7456
commit
93e99793d8
10 files changed
+626
-84
No files matched your search
@@ -611,7 +611,7 @@ const isSidebarCollapsed = ref(false);
|
||||
const copiedIndex = ref<number | null>(null);
|
||||
|
||||
// 从 useChat 中解构出消息列表、思考状态、会话 ID 与发送函数
|
||||
const { messages, isThinking, conversationId, sendMessage } = useChat();
|
||||
const { messages, isThinking, conversationId, runs, activeRunId, activateRun, createNewChatView, sendMessage } = useChat();
|
||||
const input = ref('');
|
||||
const currentAgent = ref<any>(null);
|
||||
const userAgents = ref<Array<{ id: number; name: string; description: string; icon_url?: string; dify_app_type?: 'chatflow' | 'workflow' }>>([]);
|
||||
@@ -1623,6 +1623,48 @@ interface ChatHistoryItem {
|
||||
}
|
||||
const history = ref<ChatHistoryItem[]>([]);
|
||||
|
||||
type DisplayHistoryItem = ChatHistoryItem & { __runId?: number; __status?: string };
|
||||
|
||||
const activeHistoryKey = computed(() => {
|
||||
if (conversationId.value) return conversationId.value;
|
||||
if (activeRunId.value) return `pending:${activeRunId.value}`;
|
||||
return '';
|
||||
});
|
||||
|
||||
const displayHistory = computed<DisplayHistoryItem[]>(() => {
|
||||
const server = history.value || [];
|
||||
const serverIds = new Set(server.map((h) => h.conversation_id));
|
||||
const pending: DisplayHistoryItem[] = (runs.value || [])
|
||||
.filter((r) => r.runId !== activeRunId.value)
|
||||
.map((r) => ({
|
||||
id: 0,
|
||||
conversation_id: r.conversationId || `pending:${r.runId}`,
|
||||
title: (r.query || '').trim(),
|
||||
created_at: r.createdAt,
|
||||
__runId: r.runId,
|
||||
__status: r.status,
|
||||
}))
|
||||
.filter((item) => item.conversation_id.startsWith('pending:') || !serverIds.has(item.conversation_id));
|
||||
|
||||
const merged = [...pending, ...server] as DisplayHistoryItem[];
|
||||
merged.sort((a, b) => String(b.created_at || '').localeCompare(String(a.created_at || '')));
|
||||
return merged;
|
||||
});
|
||||
|
||||
const handleHistorySelect = (item: DisplayHistoryItem) => {
|
||||
if (item.__runId) {
|
||||
activateRun(item.__runId);
|
||||
} else {
|
||||
const run = runs.value.find((r) => r.conversationId === item.conversation_id);
|
||||
if (run && run.status === 'running') {
|
||||
activateRun(run.runId);
|
||||
} else {
|
||||
loadConversation(item.conversation_id);
|
||||
}
|
||||
}
|
||||
isSidebarOpen.value = false;
|
||||
};
|
||||
|
||||
// 预设问题:从路由 query.preset 中读取(如果有)
|
||||
const presetQuestion = computed(() => {
|
||||
const q = route.query.preset;
|
||||
@@ -1892,7 +1934,8 @@ const clearAllHistory = async () => {
|
||||
});
|
||||
if (res.ok) {
|
||||
history.value = [];
|
||||
if (conversationId.value) {
|
||||
runs.value = [];
|
||||
if (conversationId.value || activeRunId.value) {
|
||||
startNewChat();
|
||||
}
|
||||
}
|
||||
@@ -1923,9 +1966,11 @@ const deleteHistoryItem = async (id: string, event: Event) => {
|
||||
};
|
||||
|
||||
const loadConversation = async (id: string) => {
|
||||
if (conversationId.value === id) return;
|
||||
if (conversationId.value === id && !activeRunId.value) return;
|
||||
|
||||
try {
|
||||
activeRunId.value = null;
|
||||
isThinking.value = false;
|
||||
const res = await fetch(`/api/chat/messages?conversation_id=${id}&agent_id=${agentId}`, { headers: getAuthHeaders() });
|
||||
if (res.ok) {
|
||||
messages.value = await res.json();
|
||||
@@ -1939,8 +1984,7 @@ const loadConversation = async (id: string) => {
|
||||
};
|
||||
|
||||
const startNewChat = () => {
|
||||
messages.value = [];
|
||||
conversationId.value = null;
|
||||
createNewChatView();
|
||||
};
|
||||
|
||||
const loadAgent = async () => {
|
||||
@@ -2043,6 +2087,17 @@ watch(
|
||||
}
|
||||
);
|
||||
|
||||
watch(
|
||||
() => conversationId.value,
|
||||
async (id, prev) => {
|
||||
if (!id || id === prev) return;
|
||||
const exists = history.value.some((item) => item.conversation_id === id);
|
||||
if (!exists) {
|
||||
await loadHistory();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('pagehide', onPageHide);
|
||||
window.removeEventListener('hxops:logout', onAuthLogout);
|
||||
@@ -2165,29 +2220,32 @@ const showChatRating = ref(false);
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between px-4 py-2">
|
||||
<span class="text-xs font-semibold text-muted">{{ $t('chat.history') }}</span>
|
||||
<button v-if="history.length > 0" @click="clearAllHistory" class="text-xs text-muted transition-colors hover:text-secondary">
|
||||
<span class="text-xs font-semibold text-slate-500 dark:text-slate-400">{{ $t('chat.history') }}</span>
|
||||
<button v-if="displayHistory.length > 0" @click="clearAllHistory" class="text-xs text-slate-400 transition-colors hover:text-slate-600 dark:hover:text-slate-200">
|
||||
{{ $t('chat.clearAll') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-y-auto px-2 scrollbar-thin">
|
||||
<div v-if="history.length === 0" class="py-8 text-center text-sm italic text-muted">{{ $t('chat.noHistory') }}</div>
|
||||
<div v-if="displayHistory.length === 0" class="py-8 text-center text-sm italic text-slate-400">{{ $t('chat.noHistory') }}</div>
|
||||
<div v-else class="space-y-0.5">
|
||||
<div
|
||||
v-for="item in history"
|
||||
v-for="item in displayHistory"
|
||||
:key="item.conversation_id"
|
||||
class="chat-history-item"
|
||||
:class="{ 'chat-history-item--active': conversationId === item.conversation_id }"
|
||||
class="group relative flex w-full items-center justify-between rounded-lg transition-colors"
|
||||
:class="activeHistoryKey === item.conversation_id ? 'bg-brand-50 dark:bg-brand-900/20' : 'hover:bg-slate-50 dark:hover:bg-slate-800/50'"
|
||||
>
|
||||
<button
|
||||
class="chat-history-link"
|
||||
:class="{ 'chat-history-link--active': conversationId === item.conversation_id }"
|
||||
@click="loadConversation(item.conversation_id); isSidebarOpen = false;"
|
||||
class="flex-1 truncate px-3 py-2.5 text-left text-sm pr-8"
|
||||
:class="activeHistoryKey === item.conversation_id
|
||||
? 'font-medium text-brand-700 dark:text-brand-300'
|
||||
: 'text-slate-600 dark:text-slate-300'"
|
||||
@click="handleHistorySelect(item)"
|
||||
>
|
||||
{{ item.title || $t('chat.newChat') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="!(item as any).__runId"
|
||||
@click="deleteHistoryItem(item.conversation_id, $event)"
|
||||
class="absolute right-2 p-1.5 text-muted opacity-0 transition-opacity hover:text-red-500 group-hover:opacity-100"
|
||||
:title="$t('chat.clearOneRecord')"
|
||||
|
||||
Reference in new issue
Block a user