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 格式 * 将 chatMessages 组装为 AI 对话接口需要的 history 格式
* user / assistant → content 取 chatMessages.content * 只保留 user assistant 类型的消息,recommend / apply_progress 不纳入
* recommend / apply_progress → content 取 chatMessages.extra * 最终只取最近的 10 条(从数组末尾往上取)
*/ */
function buildChatHistory(): AgentChatHistoryItem[] { function buildChatHistory(): AgentChatHistoryItem[] {
return chatMessages.value.map(msg => { const filtered = chatMessages.value
const role = (msg.type === 'user') ? 'user' : 'assistant' .filter(msg => msg.type === 'user' || msg.type === 'assistant')
let content = '' .map(msg => ({
if (msg.type === 'user' || msg.type === 'assistant') { role: msg.type as 'user' | 'assistant',
content = msg.content || '' content: msg.content || ''
} else { }))
/* recommend / apply_progress — 用 extra 作为内容 */ /* 只取最近 10 条 */
content = msg.extra || msg.content || '' return filtered.slice(-10)
}
return { role, content }
})
} }
/** /**