mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-25 16:43:55 +08:00
Fix agent snapshot history issues
This commit is contained in:
@@ -169,6 +169,28 @@ function handleInputConfirm() {
|
||||
// 是否禁用历史记忆输入框
|
||||
const isMemoryDisabled = computed(() => formData.value.memModelId !== 'Memory_mem_local_short')
|
||||
|
||||
function normalizeFunctionParams(paramInfo: any) {
|
||||
if (!paramInfo)
|
||||
return {}
|
||||
if (typeof paramInfo === 'string') {
|
||||
try {
|
||||
const parsed = JSON.parse(paramInfo)
|
||||
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {}
|
||||
}
|
||||
catch {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
return typeof paramInfo === 'object' && !Array.isArray(paramInfo) ? { ...paramInfo } : {}
|
||||
}
|
||||
|
||||
function normalizeAgentFunctions(functions: any[] = []) {
|
||||
return functions.map(item => ({
|
||||
...item,
|
||||
paramInfo: normalizeFunctionParams(item.paramInfo),
|
||||
}))
|
||||
}
|
||||
|
||||
// 打开上下文源编辑弹窗
|
||||
function openContextProviderDialog() {
|
||||
uni.navigateTo({
|
||||
@@ -191,11 +213,12 @@ async function loadAgentDetail() {
|
||||
loading.value = true
|
||||
tempSummaryMemory.value = ''
|
||||
const detail = await getAgentDetail(agentId.value)
|
||||
formData.value = { ...detail }
|
||||
const normalizedFunctions = normalizeAgentFunctions(detail.functions || [])
|
||||
formData.value = { ...detail, functions: normalizedFunctions }
|
||||
|
||||
// 更新插件store
|
||||
pluginStore.setCurrentAgentId(agentId.value)
|
||||
pluginStore.setCurrentFunctions(detail.functions || [])
|
||||
pluginStore.setCurrentFunctions(normalizedFunctions)
|
||||
|
||||
// 更新语速音调
|
||||
speedPitchStore.updateSpeedPitch({
|
||||
@@ -626,6 +649,7 @@ async function saveAgent() {
|
||||
...speedPitchStore.speedPitch,
|
||||
ttsLanguage: formData.value.language,
|
||||
contextProviders: providerStore.providers,
|
||||
functions: normalizeAgentFunctions(formData.value.functions || []),
|
||||
}
|
||||
await updateAgent(agentId.value, saveData)
|
||||
loadAgentDetail()
|
||||
@@ -663,7 +687,7 @@ function handleTools() {
|
||||
|
||||
// 确保store中有最新数据
|
||||
pluginStore.setCurrentAgentId(agentId.value)
|
||||
pluginStore.setCurrentFunctions(formData.value.functions || [])
|
||||
pluginStore.setCurrentFunctions(normalizeAgentFunctions(formData.value.functions || []))
|
||||
pluginStore.setAllFunctions(allFunctions.value)
|
||||
|
||||
uni.navigateTo({
|
||||
@@ -688,7 +712,7 @@ async function handleUpdateAgentTags() {
|
||||
|
||||
// 监听store中的插件配置变化
|
||||
watch(() => pluginStore.currentFunctions, (newFunctions) => {
|
||||
formData.value.functions = newFunctions
|
||||
formData.value.functions = normalizeAgentFunctions(newFunctions || [])
|
||||
}, { deep: true })
|
||||
|
||||
onMounted(async () => {
|
||||
|
||||
@@ -41,17 +41,32 @@ const tempParams = ref<Record<string, any>>({})
|
||||
const arrayTextCache = ref<Record<string, string>>({})
|
||||
const jsonTextCache = ref<Record<string, string>>({})
|
||||
|
||||
function normalizeFunctionParams(paramInfo: any, fallback: Record<string, any> = {}) {
|
||||
if (!paramInfo)
|
||||
return { ...fallback }
|
||||
if (typeof paramInfo === 'string') {
|
||||
try {
|
||||
const parsed = JSON.parse(paramInfo)
|
||||
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : { ...fallback }
|
||||
}
|
||||
catch {
|
||||
return { ...fallback }
|
||||
}
|
||||
}
|
||||
return typeof paramInfo === 'object' && !Array.isArray(paramInfo) ? { ...fallback, ...paramInfo } : { ...fallback }
|
||||
}
|
||||
|
||||
async function mergeFunctions() {
|
||||
selectedList.value = functions.value.map((mapping) => {
|
||||
const meta = allFunctions.value.find(f => f.id === mapping.pluginId)
|
||||
if (!meta) {
|
||||
return { id: mapping.pluginId, name: mapping.pluginId, params: {} }
|
||||
return { id: mapping.pluginId, name: mapping.pluginId, params: normalizeFunctionParams(mapping.paramInfo) }
|
||||
}
|
||||
|
||||
return {
|
||||
id: mapping.pluginId,
|
||||
name: meta.name,
|
||||
params: mapping.paramInfo || { ...meta.params },
|
||||
params: normalizeFunctionParams(mapping.paramInfo, meta.params),
|
||||
fieldsMeta: meta.fieldsMeta,
|
||||
}
|
||||
})
|
||||
@@ -91,7 +106,7 @@ function selectFunction(func: any) {
|
||||
selectedList.value = [...selectedList.value, {
|
||||
id: func.id,
|
||||
name: func.name,
|
||||
params: { ...func.params },
|
||||
params: normalizeFunctionParams(func.params),
|
||||
fieldsMeta: func.fieldsMeta,
|
||||
}]
|
||||
|
||||
@@ -118,7 +133,7 @@ function editFunction(func: any) {
|
||||
currentFunction.value = func
|
||||
|
||||
// 直接使用当前函数的参数
|
||||
tempParams.value = { ...func.params }
|
||||
tempParams.value = normalizeFunctionParams(func.params)
|
||||
|
||||
// 初始化文本缓存
|
||||
if (func.fieldsMeta) {
|
||||
@@ -252,7 +267,7 @@ function getFieldRemark(field: any) {
|
||||
watch(() => selectedList.value, (newSelectedList) => {
|
||||
const finalFunctions = newSelectedList.map(f => ({
|
||||
pluginId: f.id,
|
||||
paramInfo: f.params,
|
||||
paramInfo: normalizeFunctionParams(f.params),
|
||||
}))
|
||||
pluginStore.updateFunctions(finalFunctions)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user