feat: sketch卡片固定出现在对话底部
This commit is contained in:
@@ -221,12 +221,17 @@
|
||||
const decoder = new TextDecoder()
|
||||
let previousEventName = '' // 记录上一个事件名称
|
||||
let hasReportStarted = false // 标记 report 是否已经开始
|
||||
|
||||
let hasSketchEvent = false
|
||||
try {
|
||||
let flag = true
|
||||
while (flag) {
|
||||
const { done, value } = await reader.read()
|
||||
if (done) {
|
||||
// console.log('传输结束 end---', contentBody)
|
||||
if (hasSketchEvent) {
|
||||
aiMessage.text += `<slot slot-name="sketch"></slot>`
|
||||
}
|
||||
|
||||
aiMessage.streaming = false
|
||||
aiMessage.loading = false
|
||||
isGenerating.value = false
|
||||
@@ -251,7 +256,7 @@
|
||||
|
||||
if (!hasReportStarted && eventName === 'report') {
|
||||
isGeneratingReport.value = true
|
||||
contentBody += `<slot slot-name="card" title="123" content="123">123</slot>`
|
||||
contentBody += `<slot slot-name="card" title="Report" content="Report"></slot>`
|
||||
hasReportStarted = true
|
||||
}
|
||||
|
||||
@@ -319,20 +324,21 @@
|
||||
// console.log('jsonData', jsonData)
|
||||
if (jsonData.webAddress) {
|
||||
aiMessage.webAddress = JSON.parse(jsonData.webAddress)
|
||||
contentBody += `<slot slot-name="url">123</slot>`
|
||||
contentBody += `<slot slot-name="url"></slot>`
|
||||
}
|
||||
if (jsonData.title) {
|
||||
emits('setTitle', jsonData.title)
|
||||
}
|
||||
|
||||
if (hasSketch) {
|
||||
hasSketchEvent = true
|
||||
sketchList.value.push({
|
||||
[Object.keys(jsonData)[0]]: jsonData[Object.keys(jsonData)[0]]
|
||||
})
|
||||
// 通知 Preview 有新 sketch 正在加载,传入 sketch 索引
|
||||
MyEvent.emit('loading-sketch', sketchList.value.length - 1)
|
||||
MyEvent.emit('OpenSketch')
|
||||
contentBody += `<slot slot-name="sketch"></slot>`
|
||||
// contentBody += `<slot slot-name="sketch"></slot>`
|
||||
}
|
||||
if (eventName === 'report') {
|
||||
reportsContent.value += jsonData.report
|
||||
@@ -355,6 +361,7 @@
|
||||
}
|
||||
}
|
||||
if (jsonData.type === 'end') {
|
||||
console.log('end------hasSketch', hasSketch)
|
||||
aiMessage.streaming = false
|
||||
aiMessage.loading = false
|
||||
isGenerating.value = false
|
||||
@@ -364,7 +371,10 @@
|
||||
} catch (e) {
|
||||
// 检查是否为纯文本 [DONE]
|
||||
if (jsonText.trim() === '[DONE]') {
|
||||
console.log('done-----------hasSketch', hasSketch)
|
||||
|
||||
console.log('结束-----------------------')
|
||||
aiMessage.text = contentBody
|
||||
aiMessage.streaming = false
|
||||
aiMessage.loading = false
|
||||
isGenerating.value = false
|
||||
@@ -463,11 +473,16 @@
|
||||
// assistant 角色,拼接直到下一个 user
|
||||
let combinedContent = item.content || ''
|
||||
let combinedThinkingText = item.reasoning || ''
|
||||
let combinedImageUrl = item.image_url || null
|
||||
// 继续往后找连续的 assistant 消息
|
||||
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
|
||||
}
|
||||
j++
|
||||
}
|
||||
|
||||
@@ -476,6 +491,7 @@
|
||||
content: combinedContent,
|
||||
thinkingText: combinedThinkingText,
|
||||
text: combinedContent,
|
||||
image_url: combinedImageUrl,
|
||||
isUser: false,
|
||||
id: result.length + 1,
|
||||
sessionId: sessionId
|
||||
@@ -512,7 +528,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 收集 report 内容并保存到 localStorage
|
||||
// 2. 收集 report 内容并保存到 sessionStorage
|
||||
let reportStr = ''
|
||||
session.dialogue?.forEach((item) => {
|
||||
if (item.report) {
|
||||
@@ -536,9 +552,7 @@
|
||||
ancestorsList.push(...list)
|
||||
}
|
||||
|
||||
const setChatInfo = (info) => {
|
||||
console.log('11111111111',info);
|
||||
|
||||
const setChatInfo = (info) => {
|
||||
const initialData = agentStore.getInitialProjectData
|
||||
if (isGenerating.value || initialData) return
|
||||
|
||||
@@ -556,39 +570,27 @@ const setChatInfo = (info) => {
|
||||
params.configParams.style = project.style
|
||||
params.configParams.temperature = project.temperature
|
||||
}
|
||||
// 如果没有数据,直接返回
|
||||
if (!data) {
|
||||
messageList.value = []
|
||||
return
|
||||
}
|
||||
const { ancestors, current } = data
|
||||
|
||||
// 处理单个会话(ancestor 或 current)
|
||||
|
||||
const imgList = []
|
||||
const ancestorsList = []
|
||||
const idCounterRef = { value: 1 }
|
||||
|
||||
// 处理所有 ancestors
|
||||
ancestors?.forEach((item) => {
|
||||
processSession(item, imgList, ancestorsList, idCounterRef)
|
||||
})
|
||||
|
||||
// 处理 current
|
||||
processSession(current, imgList, ancestorsList, idCounterRef)
|
||||
|
||||
// 延迟设置新数据,确保 UI 有时间响应清空操作
|
||||
nextTick(() => {
|
||||
// 找到每个 sessionId 对应的最后一项,插入sketch卡片
|
||||
const sessionLastIndexMap = new Map<string, number>()
|
||||
ancestorsList.forEach((item, index) => {
|
||||
console.log('item', item)
|
||||
// if (item.image_url) {
|
||||
sessionLastIndexMap.set(item.sessionId, index)
|
||||
// }
|
||||
})
|
||||
sessionLastIndexMap.forEach((lastIndex) => {
|
||||
ancestorsList[lastIndex].text += '<slot slot-name="sketch"></slot>'
|
||||
ancestorsList.forEach((item) => {
|
||||
if (item.image_url) {
|
||||
item.text += `<slot slot-name="sketch"></slot>`
|
||||
}
|
||||
})
|
||||
|
||||
messageList.value = [...ancestorsList]
|
||||
|
||||
Reference in New Issue
Block a user