From 9ee9fa0b52a11747409c39b98783462d6a3e6c99 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Thu, 13 Aug 2026 20:57:08 +0800 Subject: [PATCH] =?UTF-8?q?fix(frontend):=20=E4=BF=AE=E5=A4=8D=E5=8D=A0?= =?UTF-8?q?=E4=BD=8D=E8=A1=8C=E6=A0=B7=E5=BC=8F=E5=B9=B6=E6=8A=8A=E8=AE=B0?= =?UTF-8?q?=E5=BF=86=E8=A1=8C=E7=BB=9F=E4=B8=80=E6=94=B6=E8=BF=9B=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E8=BD=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 「正在准备回答」占位节点缺少 .tool-event 包装,图标定位与行高规则都挂在该 层下,shimmer 文案因行高不足被裁切。补上包装,与同组件其他步骤结构一致。 Agent 模式的记忆行原先是悬在时间轴上方的独立卡片,现在作为时间轴首个节点 渲染,折叠时随中间步骤一起收起。召回列表、展开状态与「忘记」调用抽成 useChatMemoryRow,两条时间轴共用,避免各写一套后行为分叉。 --- frontend/src/composables/useChatMemoryRow.ts | 50 +++++++++++++++++ .../AgentStreamDisplay.style.test.mjs | 16 ++++++ .../chat/components/AgentStreamDisplay.vue | 45 ++++++++++++++++ .../RagPipelineProgress.style.test.mjs | 23 ++++++-- .../chat/components/RagPipelineProgress.vue | 53 ++++++------------- frontend/src/views/chat/components/botmsg.vue | 13 +++-- 6 files changed, 153 insertions(+), 47 deletions(-) create mode 100644 frontend/src/composables/useChatMemoryRow.ts diff --git a/frontend/src/composables/useChatMemoryRow.ts b/frontend/src/composables/useChatMemoryRow.ts new file mode 100644 index 00000000..37457ab1 --- /dev/null +++ b/frontend/src/composables/useChatMemoryRow.ts @@ -0,0 +1,50 @@ +import { computed, ref } from 'vue' +import { MessagePlugin } from 'tdesign-vue-next' +import { useI18n } from 'vue-i18n' +import { deleteMemoryItem } from '@/api/memory' + +export type UsedMemory = { id: string; kind: string; content: string } + +/** + * State for the "memories used by this turn" timeline row. + * + * Both timelines (the quick-answer pipeline and the agent stream) show the same + * row, so the recall list, the expand state and the forget call live here rather + * than being written twice and drifting apart. + */ +export function useChatMemoryRow(getUsedMemories: () => UsedMemory[] | undefined) { + const { t } = useI18n() + + const expanded = ref(false) + const forgettingId = ref('') + const forgottenIds = ref([]) + + const memoryItems = computed(() => { + const used = getUsedMemories() + if (!Array.isArray(used)) return [] + return used.filter((memory) => memory?.id && !forgottenIds.value.includes(memory.id)) + }) + + const hasMemory = computed(() => memoryItems.value.length > 0) + + const toggle = () => { + expanded.value = !expanded.value + } + + // Forgetting from the answer is the shortest path from noticing a wrong memory + // to it being gone, which is where users actually notice one. + const forget = async (memory: { id: string }) => { + forgettingId.value = memory.id + try { + await deleteMemoryItem(memory.id) + forgottenIds.value = [...forgottenIds.value, memory.id] + MessagePlugin.success(t('chat.memoryForgotten')) + } catch (error: any) { + MessagePlugin.error(error?.message || t('chat.memoryForgetFailed')) + } finally { + forgettingId.value = '' + } + } + + return { memoryItems, hasMemory, expanded, forgettingId, toggle, forget } +} diff --git a/frontend/src/views/chat/components/AgentStreamDisplay.style.test.mjs b/frontend/src/views/chat/components/AgentStreamDisplay.style.test.mjs index ddc17c7a..0b335949 100644 --- a/frontend/src/views/chat/components/AgentStreamDisplay.style.test.mjs +++ b/frontend/src/views/chat/components/AgentStreamDisplay.style.test.mjs @@ -92,6 +92,22 @@ test('only the collapsed root summary shows an expand chevron', () => { assert.doesNotMatch(source, /isEventExpanded\(event\.event_id\) \? 'chevron/) }) +// Recalled memory is one more thing the turn did before answering, so it rides +// the same timeline as the steps instead of sitting in a card above them. It has +// to travel into the collapsed tree with them, and appear exactly once. +test('recalled memory rides the agent timeline as its leading row', () => { + const template = source.split('\s*\n\s* { assert.doesNotMatch(source, /&\.action-pending\s*\{[\s\S]*&::after/) }) diff --git a/frontend/src/views/chat/components/AgentStreamDisplay.vue b/frontend/src/views/chat/components/AgentStreamDisplay.vue index 92397ed3..913a8bbd 100644 --- a/frontend/src/views/chat/components/AgentStreamDisplay.vue +++ b/frontend/src/views/chat/components/AgentStreamDisplay.vue @@ -18,6 +18,14 @@
+