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