feat: 会话历史回溯
This commit is contained in:
@@ -29,7 +29,7 @@ export const createProject = (data: CreateProjectParamsType): Promise<any> => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取项目信息
|
* 获取项目信息和会话历史
|
||||||
* @param data 获取项目信息参数
|
* @param data 获取项目信息参数
|
||||||
* @param data.id 项目id
|
* @param data.id 项目id
|
||||||
* @returns 获取项目信息
|
* @returns 获取项目信息
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export const versionTree = (data) => {
|
|||||||
* @param data 获取节点缩略信息的参数
|
* @param data 获取节点缩略信息的参数
|
||||||
* @param data.projectId 项目id
|
* @param data.projectId 项目id
|
||||||
* @param data.id 节点id
|
* @param data.id 节点id
|
||||||
* @returns 获取节点缩略信息
|
* @returns 回溯该节点之前的会话列表
|
||||||
*/
|
*/
|
||||||
export const getNodeAncestors = (data) => {
|
export const getNodeAncestors = (data) => {
|
||||||
return request({
|
return request({
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export const useAgentStore = defineStore('agent', () => {
|
|||||||
type: string
|
type: string
|
||||||
area: string
|
area: string
|
||||||
style: string
|
style: string
|
||||||
} | null>(null)
|
} | null>(null)
|
||||||
|
|
||||||
// 保存项目初始数据
|
// 保存项目初始数据
|
||||||
const setInitialProjectData = (data: {
|
const setInitialProjectData = (data: {
|
||||||
|
|||||||
@@ -67,8 +67,6 @@
|
|||||||
watch(
|
watch(
|
||||||
sketchList,
|
sketchList,
|
||||||
(newVal) => {
|
(newVal) => {
|
||||||
console.log('添加图片链接--------')
|
|
||||||
|
|
||||||
emits('update:sketchList', newVal)
|
emits('update:sketchList', newVal)
|
||||||
},
|
},
|
||||||
{ deep: true }
|
{ deep: true }
|
||||||
@@ -120,7 +118,7 @@
|
|||||||
},
|
},
|
||||||
skipUserMessage = false
|
skipUserMessage = false
|
||||||
) => {
|
) => {
|
||||||
console.log('Message sent:', message)
|
// console.log('Message sent:', message)
|
||||||
isPaused.value = false
|
isPaused.value = false
|
||||||
isGenerating.value = true
|
isGenerating.value = true
|
||||||
params.message = message.text
|
params.message = message.text
|
||||||
@@ -213,7 +211,7 @@
|
|||||||
while (flag) {
|
while (flag) {
|
||||||
const { done, value } = await reader.read()
|
const { done, value } = await reader.read()
|
||||||
if (done) {
|
if (done) {
|
||||||
console.log('传输结束 end---', contentBody)
|
// console.log('传输结束 end---', contentBody)
|
||||||
aiMessage.streaming = false
|
aiMessage.streaming = false
|
||||||
aiMessage.loading = false
|
aiMessage.loading = false
|
||||||
isGenerating.value = 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({
|
defineExpose({
|
||||||
inputRef
|
setChatInfo
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -221,5 +221,8 @@
|
|||||||
ul {
|
ul {
|
||||||
list-style-position: inside;
|
list-style-position: inside;
|
||||||
}
|
}
|
||||||
|
code {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
ref="VersionTreeIndexRef"
|
ref="VersionTreeIndexRef"
|
||||||
v-model:versionTreeData="versionTreeData"
|
v-model:versionTreeData="versionTreeData"
|
||||||
@restore="handleRestore"
|
@restore="handleRestore"
|
||||||
|
@selectNode="handleSelectNode"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -24,13 +25,14 @@
|
|||||||
import VersionTreeIndex from './components/versionTree/index.vue'
|
import VersionTreeIndex from './components/versionTree/index.vue'
|
||||||
import { useProjectStore } from '@/stores'
|
import { useProjectStore } from '@/stores'
|
||||||
import { getProjectInfo } from '@/api/agent'
|
import { getProjectInfo } from '@/api/agent'
|
||||||
|
import { clearNodeChat, getNodeAncestors } from '@/api/versitonTree'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
const projectStore = useProjectStore()
|
||||||
|
|
||||||
const agentTitle = ref('Retro Sofa Sketch')
|
const agentTitle = ref('Retro Sofa Sketch')
|
||||||
const previewType = ref<'sketch' | 'report'>('sketch')
|
const previewType = ref<'sketch' | 'report'>('sketch')
|
||||||
const route = useRoute()
|
|
||||||
|
|
||||||
const VersionTreeIndexRef = ref()
|
const VersionTreeIndexRef = ref()
|
||||||
const agentRef = ref()
|
const agentRef = ref()
|
||||||
const sketchList = ref([])
|
const sketchList = ref([])
|
||||||
@@ -45,20 +47,37 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
const handleRestore = () => {
|
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 proJectId = computed(() => route.params.id)
|
||||||
const projectStore = useProjectStore()
|
|
||||||
watch(
|
watch(
|
||||||
() => proJectId.value,
|
() => proJectId.value,
|
||||||
(newVal, oldVal) => {
|
(newVal, oldVal) => {
|
||||||
if (newVal) {
|
if (newVal) {
|
||||||
projectStore.clearProject()
|
projectStore.clearProject()
|
||||||
projectStore.setId(newVal)
|
projectStore.setId(newVal)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -66,18 +85,14 @@
|
|||||||
() => projectStore.state.id,
|
() => projectStore.state.id,
|
||||||
(newVal, oldVal) => {
|
(newVal, oldVal) => {
|
||||||
if (newVal) {
|
if (newVal) {
|
||||||
getProjectInfo({ id: newVal }).then((res) => {
|
handleGetProjectInfoAndHistory()
|
||||||
projectStore.setProject(res.project)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (projectStore.state.id) {
|
if (projectStore.state.id) {
|
||||||
getProjectInfo({ id: projectStore.state.id }).then((res) => {
|
handleGetProjectInfoAndHistory()
|
||||||
projectStore.setProject(res.project)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -573,7 +573,7 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
// console.log('Create project with:', params)
|
// console.log('Create project with:', params)
|
||||||
router.push('/home/agent', { query: params })
|
router.push(`/home/agent/${projectres}`, { query: params })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 暴露方法给父组件
|
// 暴露方法给父组件
|
||||||
|
|||||||
Reference in New Issue
Block a user