bugfix: 多条消息的卡片展示
This commit is contained in:
@@ -353,10 +353,7 @@
|
||||
})
|
||||
}
|
||||
})
|
||||
// 通知 Preview 有新 sketch 正在加载,传入 sketch 索引
|
||||
MyEvent.emit('loading-sketch', sketchList.value.length - 1)
|
||||
MyEvent.emit('OpenSketch')
|
||||
// contentBody += `<slot slot-name="sketch"></slot>`
|
||||
}
|
||||
if (eventName === 'reportName' || eventName === 'reportTitle') {
|
||||
aiMessage.reportName = jsonData.reportName || jsonData.reportTitle
|
||||
@@ -470,13 +467,7 @@
|
||||
}
|
||||
|
||||
// 处理对话列表,将连续的 assistant 消息合并为一条
|
||||
const processDialogue = (
|
||||
dialogue,
|
||||
startIndex,
|
||||
existingImgList,
|
||||
sessionId,
|
||||
firstReportIndex = -1
|
||||
) => {
|
||||
const processDialogue = (dialogue, startIndex, existingImgList, sessionId) => {
|
||||
if (!dialogue || dialogue.length === 0) return []
|
||||
|
||||
const result = []
|
||||
@@ -485,7 +476,6 @@
|
||||
while (i < dialogue.length) {
|
||||
const item = dialogue[i]
|
||||
if (item.role === 'user') {
|
||||
// user 角色直接添加
|
||||
result.push({
|
||||
...item,
|
||||
text: item.content,
|
||||
@@ -495,42 +485,42 @@
|
||||
})
|
||||
i++
|
||||
} else if (item.role === 'assistant') {
|
||||
// assistant 角色,拼接直到下一个 user
|
||||
|
||||
let combinedContent = item.content || ''
|
||||
let combinedThinkingText = item.reasoning || ''
|
||||
let combinedImageUrl = item.image_url || null
|
||||
let reportName = item.reportName || null
|
||||
let webAddress = item.webAddress || null
|
||||
// 继续往后找连续的 assistant 消息
|
||||
let combinedReport = item.report || ''
|
||||
let hasReportSlot = !!item.report
|
||||
let hasUrlSlot = !!item.webAddress
|
||||
|
||||
let j = i + 1
|
||||
while (j < dialogue.length && dialogue[j].role === 'assistant') {
|
||||
combinedContent += dialogue[j].content || ''
|
||||
combinedThinkingText += dialogue[j].reasoning || ''
|
||||
// 如果有 image_url 则保留
|
||||
if (dialogue[j].image_url) {
|
||||
combinedImageUrl = dialogue[j].image_url
|
||||
}
|
||||
if (dialogue[j].reportName) {
|
||||
reportName = dialogue[j].reportName
|
||||
}
|
||||
if (dialogue[j].webAddress) {
|
||||
combinedContent += `<slot slot-name="url"></slot>`
|
||||
webAddress = dialogue[j].webAddress
|
||||
// console.log('webAddress22222222222222', dialogue[j].webAddress)
|
||||
// debugger
|
||||
const next = dialogue[j]
|
||||
combinedContent += next.content || ''
|
||||
combinedThinkingText += next.reasoning || ''
|
||||
combinedReport += next.report || ''
|
||||
if (next.image_url) combinedImageUrl = next.image_url
|
||||
if (next.reportName) reportName = next.reportName
|
||||
if (next.report) hasReportSlot = true
|
||||
if (next.webAddress) {
|
||||
webAddress = next.webAddress
|
||||
hasUrlSlot = true
|
||||
}
|
||||
j++
|
||||
}
|
||||
|
||||
// 如果 firstReportIndex 在当前合并范围内,则把 slot 追加到末尾
|
||||
if (firstReportIndex >= i && firstReportIndex < j) {
|
||||
if (hasUrlSlot) {
|
||||
combinedContent += `<slot slot-name="url"></slot>`
|
||||
}
|
||||
if (hasReportSlot) {
|
||||
combinedContent += `<slot slot-name="card" title="Report" content="Report"></slot>`
|
||||
}
|
||||
|
||||
result.push({
|
||||
...item,
|
||||
reportName,
|
||||
report: combinedReport,
|
||||
content: combinedContent,
|
||||
thinkingText: combinedThinkingText,
|
||||
text: combinedContent,
|
||||
@@ -543,7 +533,6 @@
|
||||
|
||||
i = j
|
||||
} else {
|
||||
// 其他角色直接添加
|
||||
result.push({
|
||||
...item,
|
||||
text: item.content,
|
||||
@@ -560,35 +549,11 @@
|
||||
const processSession = (session, imgList, ancestorsList, idCounterRef) => {
|
||||
if (!session) return
|
||||
|
||||
// 1. 找到第一个 report 项的索引,供 processDialogue 使用
|
||||
let firstReportIndex = -1
|
||||
if (session.dialogue) {
|
||||
for (let i = 0; i < session.dialogue.length; i++) {
|
||||
if (session.dialogue[i].report) {
|
||||
firstReportIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 收集 report 内容并保存到 sessionStorage
|
||||
let reportStr = ''
|
||||
session.dialogue?.forEach((item) => {
|
||||
if (item.report) {
|
||||
reportStr += item.report
|
||||
}
|
||||
})
|
||||
if (reportStr && session.id) {
|
||||
sessionStorage.setItem(`reportsContent_${session.id}`, reportStr)
|
||||
}
|
||||
|
||||
// 3. 收集 sketchIDAndUrl 到 imgList
|
||||
if (session.sketchIDAndUrl) {
|
||||
imgList.push(session.sketchIDAndUrl)
|
||||
}
|
||||
|
||||
// 4. 处理 dialogue
|
||||
const list = processDialogue(session.dialogue, 0, imgList, session.id, firstReportIndex)
|
||||
const list = processDialogue(session.dialogue, 0, imgList, session.id)
|
||||
list.forEach((el) => {
|
||||
el.id = idCounterRef.value++
|
||||
})
|
||||
@@ -636,6 +601,7 @@
|
||||
item.text += `<slot slot-name="sketch"></slot>`
|
||||
}
|
||||
})
|
||||
console.log('ancestorslist', ancestorsList)
|
||||
messageList.value = [...ancestorsList]
|
||||
params.versionID = current?.id
|
||||
sketchList.value = imgList
|
||||
|
||||
Reference in New Issue
Block a user