From ddb67cfb6fa2ad96052c4e5b93dc842b5ba675e3 Mon Sep 17 00:00:00 2001 From: xuxin <15279969124@163.com> Date: Fri, 29 May 2026 17:22:22 +0800 Subject: [PATCH] =?UTF-8?q?AI=E5=8A=A9=E6=89=8B=E8=81=8A=E5=A4=A9=E6=97=B6?= =?UTF-8?q?=E5=80=99=E7=9A=84=E5=8E=86=E5=8F=B2=E6=B6=88=E6=81=AF=E7=BB=84?= =?UTF-8?q?=E8=A3=85=E5=8E=BB=E6=8E=89=E5=88=97=E8=A1=A8=E5=92=8C=E6=8A=95?= =?UTF-8?q?=E9=80=92=E8=BF=9B=E5=BA=A6=E7=AD=89=E9=9D=9E=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E8=81=8A=E5=A4=A9=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/Agent.vue | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/views/Agent.vue b/src/views/Agent.vue index aacbf38..21e3ca2 100644 --- a/src/views/Agent.vue +++ b/src/views/Agent.vue @@ -436,21 +436,18 @@ async function loadDefaultResumeId() { /** * 将 chatMessages 组装为 AI 对话接口需要的 history 格式 - * user / assistant → content 取 chatMessages.content - * recommend / apply_progress → content 取 chatMessages.extra + * 只保留 user 和 assistant 类型的消息,recommend / apply_progress 不纳入 + * 最终只取最近的 10 条(从数组末尾往上取) */ function buildChatHistory(): AgentChatHistoryItem[] { - return chatMessages.value.map(msg => { - const role = (msg.type === 'user') ? 'user' : 'assistant' - let content = '' - if (msg.type === 'user' || msg.type === 'assistant') { - content = msg.content || '' - } else { - /* recommend / apply_progress — 用 extra 作为内容 */ - content = msg.extra || msg.content || '' - } - return { role, content } - }) + const filtered = chatMessages.value + .filter(msg => msg.type === 'user' || msg.type === 'assistant') + .map(msg => ({ + role: msg.type as 'user' | 'assistant', + content: msg.content || '' + })) + /* 只取最近 10 条 */ + return filtered.slice(-10) } /**