Skip to content

Commit 82449c7

Browse files
committed
fix: 修复对话历史恢复时用户输入显示空白-历史消息仅存{role,content},恢复时用户消息缺少textContent导致气泡空白,新增restoreUserMessage还原文本与图片(从content中剥离![](data URL)markdown图片还原images),历史打开对话时用户输入与图片正常显示
1 parent 239924c commit 82449c7

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

‎JuggleNet6.Frontend/src/views/ai/AssistantRun.vue‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,26 @@ async function loadHistory() {
316316
} catch { historyList.value = [] }
317317
}
318318
319+
/** 从历史用户消息还原文本与图片(图片以 ![](data URL) markdown 存于 content) */
320+
function restoreUserMessage(m: any) {
321+
if (m.role !== 'user') return m
322+
const images: string[] = []
323+
let text = m.content || ''
324+
text = text.replace(/!\[[^\]]*\]\((data:image[^)]+)\)/g, (_all: string, url: string) => {
325+
images.push(url)
326+
return ''
327+
})
328+
return { role: 'user', content: m.content, textContent: text.trim(), images }
329+
}
330+
319331
async function openConversation(id: number) {
320332
try {
321333
const res: any = await request.get(`/ai/conversation/${id}`)
322334
const conv = res.data
323335
conversation.value = { id: conv.id, status: conv.status }
324-
try { messages.value = JSON.parse(conv.messages || '[]') } catch { messages.value = [] }
336+
try {
337+
messages.value = (JSON.parse(conv.messages || '[]') as any[]).map(restoreUserMessage)
338+
} catch { messages.value = [] }
325339
try { finalOutputs.value = JSON.parse(conv.outputs || '{}') } catch { finalOutputs.value = {} }
326340
historyVisible.value = false
327341
await nextTick()

0 commit comments

Comments
 (0)