AI助手聊天时候的历史消息组装去掉列表和投递进度等非对话聊天内容

This commit is contained in:
xuxin
2026-05-29 17:22:22 +08:00
parent 59ac8ab783
commit ddb67cfb6f
+10 -13
View File
@@ -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)
}
/**