feat(ai-house): 支持 Markdown 并优化找房交互

This commit is contained in:
2026-08-08 06:48:09 +08:00
parent d6861ab8c4
commit 87890a10ed
8 changed files with 138 additions and 241 deletions
+23 -41
View File
@@ -29,47 +29,29 @@ function createPageVm() {
return vm
}
function receiveLocationResponse(fieldName, locationCards) {
const vm = createPageVm()
const response = {
type: 'house_ai_result',
answer: '已按已维护的地点资料筛选,以下地点可供参考。'
}
response[fieldName] = locationCards
vm.handleSocketMessage(JSON.stringify(response))
return vm.messages.find((message) => message.type === 'location')
}
const locationCard = {
location_id: 101,
city: '南宁市',
location_name: '五象航洋城',
parent_location_name: '五象新区',
tags: ['停车方便'],
knowledge_items: [{
topic: 'parking',
title: '停车',
parking_available: true,
parking_fee: '月租 300 元'
const vm = createPageVm()
vm.handleSocketMessage(JSON.stringify({
type: 'house_ai_result',
answer: '航洋城附近通勤方便,停车以现场政策为准。',
locationCards: [{
locationId: 101,
locationName: '航洋城',
knowledgeItems: [{ title: '停车' }]
}],
houses: [{
houseId: 201,
houseTitle: '航洋城附近两居室',
files: []
}]
}
}))
const locationMessage = receiveLocationResponse('location_cards', JSON.stringify([locationCard]))
assert.equal(vm.messages.filter((message) => message.type === 'location').length, 0,
'地点资料不应在小程序中创建卡片消息')
assert.equal(vm.messages.filter((message) => message.type === 'text').length, 1,
'地点资料应由 AI 直接组织为文本回答')
assert.equal(vm.messages.find((message) => message.type === 'text').content,
'航洋城附近通勤方便,停车以现场政策为准。')
assert.equal(vm.messages.filter((message) => message.type === 'list').length, 1,
'房源结果仍应创建房源卡片消息')
assert.ok(locationMessage, '地点咨询回包应创建地点卡片消息')
assert.ok(Array.isArray(locationMessage.locationCards), '地点卡片应转换为数组')
assert.equal(locationMessage.locationCards[0].locationId, 101)
assert.equal(locationMessage.locationCards[0].locationName, '五象航洋城')
assert.equal(locationMessage.locationCards[0].knowledgeItems[0].parkingAvailable, true)
const backendLocationMessage = receiveLocationResponse('locationCards', [{
locationId: 102,
city: '南宁市',
locationName: '会展航洋城',
knowledgeItems: []
}])
assert.ok(backendLocationMessage, '后端驼峰地点卡片回包应保持兼容')
assert.equal(backendLocationMessage.locationCards[0].locationName, '会展航洋城')
console.log('地点咨询回包能够创建可渲染的地点卡片消息')
console.log('地点资料仅由 AI 组织为文本,页面不渲染地点卡片')