feat: 会话历史回溯

This commit is contained in:
2026-03-02 11:29:07 +08:00
parent 338c67d5b8
commit bd0a5a8c6b
7 changed files with 76 additions and 21 deletions

View File

@@ -29,7 +29,7 @@ export const createProject = (data: CreateProjectParamsType): Promise<any> => {
}
/**
* 获取项目信息
* 获取项目信息和会话历史
* @param data 获取项目信息参数
* @param data.id 项目id
* @returns 获取项目信息

View File

@@ -32,7 +32,7 @@ export const versionTree = (data) => {
* @param data 获取节点缩略信息的参数
* @param data.projectId 项目id
* @param data.id 节点id
* @returns 获取节点缩略信息
* @returns 回溯该节点之前的会话列表
*/
export const getNodeAncestors = (data) => {
return request({

View File

@@ -14,7 +14,7 @@ export const useAgentStore = defineStore('agent', () => {
type: string
area: string
style: string
} | null>(null)
} | null>(null)
// 保存项目初始数据
const setInitialProjectData = (data: {

View File

@@ -67,8 +67,6 @@
watch(
sketchList,
(newVal) => {
console.log('添加图片链接--------')
emits('update:sketchList', newVal)
},
{ deep: true }
@@ -120,7 +118,7 @@
},
skipUserMessage = false
) => {
console.log('Message sent:', message)
// console.log('Message sent:', message)
isPaused.value = false
isGenerating.value = true
params.message = message.text
@@ -213,7 +211,7 @@
while (flag) {
const { done, value } = await reader.read()
if (done) {
console.log('传输结束 end---', contentBody)
// console.log('传输结束 end---', contentBody)
aiMessage.streaming = false
aiMessage.loading = false
isGenerating.value = false
@@ -361,8 +359,47 @@
)
}
const setChatInfo = (data) => {
// messageList.value = list
const { ancestors, current } = data
const imgList = []
const ancestorsList = []
if (ancestors) {
ancestors.forEach((item) => {
const list = item.dialogue.map((el, index) => {
if (el.image_url) {
imgList.push(el.image_url)
}
return {
...el,
text: el.content,
isUser: el.role === 'user',
id: index + 1
}
})
ancestorsList.push(...list)
})
}
const currentList = current.dialogue.map((item, index) => {
if (item.image_url) {
imgList.push(item.image_url)
}
return {
...item,
text: item.content,
isUser: item.role === 'user',
id: index + 1 + ancestorsList.length
}
})
messageList.value = [...ancestorsList, ...currentList]
params.versionID = current.id
sketchList.value = imgList
// console.log('messagelist:', messageList.value)
// debugger
}
defineExpose({
inputRef
setChatInfo
})
</script>

View File

@@ -221,5 +221,8 @@
ul {
list-style-position: inside;
}
code {
white-space: pre-wrap;
}
}
</style>

View File

@@ -13,6 +13,7 @@
ref="VersionTreeIndexRef"
v-model:versionTreeData="versionTreeData"
@restore="handleRestore"
@selectNode="handleSelectNode"
/>
</div>
</template>
@@ -24,13 +25,14 @@
import VersionTreeIndex from './components/versionTree/index.vue'
import { useProjectStore } from '@/stores'
import { getProjectInfo } from '@/api/agent'
import { clearNodeChat, getNodeAncestors } from '@/api/versitonTree'
import { useRoute } from 'vue-router'
const route = useRoute()
const projectStore = useProjectStore()
const agentTitle = ref('Retro Sofa Sketch')
const previewType = ref<'sketch' | 'report'>('sketch')
const route = useRoute()
const VersionTreeIndexRef = ref()
const agentRef = ref()
const sketchList = ref([])
@@ -45,20 +47,37 @@
})
const handleRestore = () => {
console.log('-----------', agentRef.value.inputRef.addReportTag)
// agentRef.value?.inputRef?.addReportTag('Restore')
clearNodeChat({ projectId: projectStore.state.id, id: projectStore.state.nodeId }).then(
(res) => {}
)
}
const handleSelectNode = () => {
console.log('handleSelectNode')
getNodeAncestors({ projectId: projectStore.state.id, id: projectStore.state.nodeId }).then(
(res) => {
console.log('res', res)
agentRef.value.setChatInfo(res)
}
)
}
agentRef.value?.inputRef?.addReportTag('Restore')
const handleGetProjectInfoAndHistory = () => {
getProjectInfo({ id: projectStore.state.id }).then((res) => {
// console.log('1111111',res);
agentRef.value.setChatInfo(res.conversation)
projectStore.setProject(res.project)
})
}
const proJectId = computed(() => route.params.id)
const projectStore = useProjectStore()
watch(
() => proJectId.value,
(newVal, oldVal) => {
if (newVal) {
projectStore.clearProject()
projectStore.setId(newVal)
}
}
)
@@ -66,18 +85,14 @@
() => projectStore.state.id,
(newVal, oldVal) => {
if (newVal) {
getProjectInfo({ id: newVal }).then((res) => {
projectStore.setProject(res.project)
})
handleGetProjectInfoAndHistory()
}
}
)
onMounted(() => {
if (projectStore.state.id) {
getProjectInfo({ id: projectStore.state.id }).then((res) => {
projectStore.setProject(res.project)
})
handleGetProjectInfoAndHistory()
}
})
</script>

View File

@@ -573,7 +573,7 @@
})
// console.log('Create project with:', params)
router.push('/home/agent', { query: params })
router.push(`/home/agent/${projectres}`, { query: params })
}
// 暴露方法给父组件