mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 01:23:55 +08:00
Merge pull request #635 from xinnan-tech/Web_Agent_Api_Test
Web agent api test
This commit is contained in:
@@ -0,0 +1,100 @@
|
|||||||
|
import RequestService from '../httpRequest'
|
||||||
|
import {getServiceUrl} from '../api'
|
||||||
|
|
||||||
|
|
||||||
|
export default {
|
||||||
|
// 获取智能体列表
|
||||||
|
getAgentList(callback) {
|
||||||
|
RequestService.sendRequest()
|
||||||
|
.url(`${getServiceUrl()}/api/v1/agent/list`)
|
||||||
|
.method('GET')
|
||||||
|
.success((res) => {
|
||||||
|
RequestService.clearRequestTime();
|
||||||
|
callback(res);
|
||||||
|
})
|
||||||
|
.fail(() => {
|
||||||
|
RequestService.reAjaxFun(() => {
|
||||||
|
this.getAgentList(callback);
|
||||||
|
});
|
||||||
|
}).send();
|
||||||
|
},
|
||||||
|
// 添加智能体
|
||||||
|
addAgent(agentName, callback) {
|
||||||
|
RequestService.sendRequest()
|
||||||
|
.url(`${getServiceUrl()}/api/v1/agent`)
|
||||||
|
.method('POST')
|
||||||
|
.data({agentName: agentName})
|
||||||
|
.success((res) => {
|
||||||
|
RequestService.clearRequestTime();
|
||||||
|
callback(res);
|
||||||
|
})
|
||||||
|
.fail(() => {
|
||||||
|
RequestService.reAjaxFun(() => {
|
||||||
|
this.addAgent(agentName, callback);
|
||||||
|
});
|
||||||
|
}).send();
|
||||||
|
},
|
||||||
|
// 删除智能体
|
||||||
|
deleteAgent(agentId, callback) {
|
||||||
|
RequestService.sendRequest()
|
||||||
|
.url(`${getServiceUrl()}/api/v1/agent/${agentId}`)
|
||||||
|
.method('DELETE')
|
||||||
|
.success((res) => {
|
||||||
|
RequestService.clearRequestTime();
|
||||||
|
callback(res);
|
||||||
|
})
|
||||||
|
.fail(() => {
|
||||||
|
RequestService.reAjaxFun(() => {
|
||||||
|
this.deleteAgent(agentId, callback);
|
||||||
|
});
|
||||||
|
}).send();
|
||||||
|
},
|
||||||
|
// 获取智能体配置
|
||||||
|
getDeviceConfig(deviceId, callback) {
|
||||||
|
RequestService.sendRequest()
|
||||||
|
.url(`${getServiceUrl()}/api/v1/agent/${deviceId}`)
|
||||||
|
.method('GET')
|
||||||
|
.success((res) => {
|
||||||
|
RequestService.clearRequestTime();
|
||||||
|
callback(res);
|
||||||
|
})
|
||||||
|
.fail((err) => {
|
||||||
|
console.error('获取配置失败:', err);
|
||||||
|
RequestService.reAjaxFun(() => {
|
||||||
|
this.getDeviceConfig(deviceId, callback);
|
||||||
|
});
|
||||||
|
}).send();
|
||||||
|
},
|
||||||
|
// 配置智能体
|
||||||
|
updateAgentConfig(agentId, configData, callback) {
|
||||||
|
RequestService.sendRequest()
|
||||||
|
.url(`${getServiceUrl()}/api/v1/agent/${agentId}`)
|
||||||
|
.method('PUT')
|
||||||
|
.data(configData)
|
||||||
|
.success((res) => {
|
||||||
|
RequestService.clearRequestTime();
|
||||||
|
callback(res);
|
||||||
|
})
|
||||||
|
.fail(() => {
|
||||||
|
RequestService.reAjaxFun(() => {
|
||||||
|
this.updateAgentConfig(agentId, configData, callback);
|
||||||
|
});
|
||||||
|
}).send();
|
||||||
|
},
|
||||||
|
// 新增方法:获取智能体模板
|
||||||
|
getAgentTemplate(callback) { // 移除templateName参数
|
||||||
|
RequestService.sendRequest()
|
||||||
|
.url(`${getServiceUrl()}/api/v1/agent/template`)
|
||||||
|
.method('GET')
|
||||||
|
.success((res) => {
|
||||||
|
RequestService.clearRequestTime();
|
||||||
|
callback(res);
|
||||||
|
})
|
||||||
|
.fail((err) => {
|
||||||
|
console.error('获取模板失败:', err);
|
||||||
|
RequestService.reAjaxFun(() => {
|
||||||
|
this.getAgentTemplate(callback);
|
||||||
|
});
|
||||||
|
}).send();
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -70,21 +70,6 @@ export default {
|
|||||||
});
|
});
|
||||||
}).send();
|
}).send();
|
||||||
},
|
},
|
||||||
// 获取智能体列表
|
|
||||||
getAgentList(callback) {
|
|
||||||
RequestService.sendRequest()
|
|
||||||
.url(`${getServiceUrl()}/api/v1/user/agent`)
|
|
||||||
.method('GET')
|
|
||||||
.success((res) => {
|
|
||||||
RequestService.clearRequestTime();
|
|
||||||
callback(res);
|
|
||||||
})
|
|
||||||
.fail(() => {
|
|
||||||
RequestService.reAjaxFun(() => {
|
|
||||||
this.getAgentList(callback);
|
|
||||||
});
|
|
||||||
}).send();
|
|
||||||
},
|
|
||||||
// 用户信息获取
|
// 用户信息获取
|
||||||
getUserInfo(callback) {
|
getUserInfo(callback) {
|
||||||
RequestService.sendRequest()
|
RequestService.sendRequest()
|
||||||
@@ -101,37 +86,6 @@ export default {
|
|||||||
})
|
})
|
||||||
}).send()
|
}).send()
|
||||||
},
|
},
|
||||||
// 添加智能体
|
|
||||||
addAgent(agentName, callback) {
|
|
||||||
RequestService.sendRequest()
|
|
||||||
.url(`${getServiceUrl()}/api/v1/user/agent`)
|
|
||||||
.method('POST')
|
|
||||||
.data({name: agentName})
|
|
||||||
.success((res) => {
|
|
||||||
RequestService.clearRequestTime();
|
|
||||||
callback(res);
|
|
||||||
})
|
|
||||||
.fail(() => {
|
|
||||||
RequestService.reAjaxFun(() => {
|
|
||||||
this.addAgent(agentName, callback);
|
|
||||||
});
|
|
||||||
}).send();
|
|
||||||
},
|
|
||||||
// 删除智能体
|
|
||||||
deleteAgent(agentId, callback) {
|
|
||||||
RequestService.sendRequest()
|
|
||||||
.url(`${getServiceUrl()}/api/v1/user/agent/${agentId}`)
|
|
||||||
.method('DELETE')
|
|
||||||
.success((res) => {
|
|
||||||
RequestService.clearRequestTime();
|
|
||||||
callback(res);
|
|
||||||
})
|
|
||||||
.fail(() => {
|
|
||||||
RequestService.reAjaxFun(() => {
|
|
||||||
this.deleteAgent(agentId, callback);
|
|
||||||
});
|
|
||||||
}).send();
|
|
||||||
},
|
|
||||||
// 修改用户密码
|
// 修改用户密码
|
||||||
changePassword(oldPassword, newPassword, successCallback, errorCallback) {
|
changePassword(oldPassword, newPassword, successCallback, errorCallback) {
|
||||||
RequestService.sendRequest()
|
RequestService.sendRequest()
|
||||||
@@ -152,38 +106,7 @@ export default {
|
|||||||
})
|
})
|
||||||
.send();
|
.send();
|
||||||
},
|
},
|
||||||
// 获取智能体配置
|
|
||||||
getDeviceConfig(deviceId, callback) {
|
|
||||||
RequestService.sendRequest()
|
|
||||||
.url(`${getServiceUrl()}/api/v1/user/agent/${deviceId}`)
|
|
||||||
.method('GET')
|
|
||||||
.success((res) => {
|
|
||||||
RequestService.clearRequestTime();
|
|
||||||
callback(res);
|
|
||||||
})
|
|
||||||
.fail((err) => {
|
|
||||||
console.error('获取配置失败:', err);
|
|
||||||
RequestService.reAjaxFun(() => {
|
|
||||||
this.getDeviceConfig(deviceId, callback);
|
|
||||||
});
|
|
||||||
}).send();
|
|
||||||
},
|
|
||||||
// 配置智能体
|
|
||||||
updateAgentConfig(agentId, configData, callback) {
|
|
||||||
RequestService.sendRequest()
|
|
||||||
.url(`${getServiceUrl()}/api/v1/user/agent/${agentId}`)
|
|
||||||
.method('PUT')
|
|
||||||
.data(configData)
|
|
||||||
.success((res) => {
|
|
||||||
RequestService.clearRequestTime();
|
|
||||||
callback(res);
|
|
||||||
})
|
|
||||||
.fail(() => {
|
|
||||||
RequestService.reAjaxFun(() => {
|
|
||||||
this.updateAgentConfig(agentId, configData, callback);
|
|
||||||
});
|
|
||||||
}).send();
|
|
||||||
},
|
|
||||||
// 已绑设备
|
// 已绑设备
|
||||||
getAgentBindDevices(agentId, callback) {
|
getAgentBindDevices(agentId, callback) {
|
||||||
RequestService.sendRequest()
|
RequestService.sendRequest()
|
||||||
@@ -233,20 +156,4 @@ export default {
|
|||||||
});
|
});
|
||||||
}).send();
|
}).send();
|
||||||
},
|
},
|
||||||
// 新增方法:获取智能体模板
|
|
||||||
getAgentTemplate(templateName, callback) {
|
|
||||||
RequestService.sendRequest()
|
|
||||||
.url(`${getServiceUrl()}/api/v1/user/agent/templateId`)
|
|
||||||
.method('GET')
|
|
||||||
.success((res) => {
|
|
||||||
RequestService.clearRequestTime();
|
|
||||||
callback(res);
|
|
||||||
})
|
|
||||||
.fail((err) => {
|
|
||||||
console.error('获取模板失败:', err);
|
|
||||||
RequestService.reAjaxFun(() => {
|
|
||||||
this.getAgentTemplate(templateName, callback);
|
|
||||||
});
|
|
||||||
}).send();
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<div style="width: 40px;height: 40px;border-radius: 50%;background: #5778ff;display: flex;align-items: center;justify-content: center;">
|
<div style="width: 40px;height: 40px;border-radius: 50%;background: #5778ff;display: flex;align-items: center;justify-content: center;">
|
||||||
<img loading="lazy" src="@/assets/home/equipment.png" alt="" style="width: 18px;height: 15px;" />
|
<img loading="lazy" src="@/assets/home/equipment.png" alt="" style="width: 18px;height: 15px;" />
|
||||||
</div>
|
</div>
|
||||||
添加智慧体
|
添加智能体
|
||||||
</div>
|
</div>
|
||||||
<div style="height: 1px;background: #e8f0ff;" />
|
<div style="height: 1px;background: #e8f0ff;" />
|
||||||
<div style="margin: 22px 15px;">
|
<div style="margin: 22px 15px;">
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
<div style="color: red;display: inline-block;">*</div> 智慧体名称:
|
<div style="color: red;display: inline-block;">*</div> 智慧体名称:
|
||||||
</div>
|
</div>
|
||||||
<div class="input-46" style="margin-top: 12px;">
|
<div class="input-46" style="margin-top: 12px;">
|
||||||
<el-input placeholder="请输入智慧体名称.." v-model="wisdomBodyName" />
|
<el-input placeholder="请输入智能体名称.." v-model="wisdomBodyName" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="display: flex;margin: 15px 15px;gap: 7px;">
|
<div style="display: flex;margin: 15px 15px;gap: 7px;">
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import userApi from '@/apis/module/user';
|
import userApi from '@/apis/module/agent';
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -43,7 +43,7 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
confirm() {
|
confirm() {
|
||||||
if (!this.wisdomBodyName.trim()) {
|
if (!this.wisdomBodyName.trim()) {
|
||||||
this.$message.error('请输入智慧体名称');
|
this.$message.error('请输入智能体名称');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
userApi.addAgent(this.wisdomBodyName, (res) => {
|
userApi.addAgent(this.wisdomBodyName, (res) => {
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ export default {
|
|||||||
},
|
},
|
||||||
// 获取智能体列表
|
// 获取智能体列表
|
||||||
fetchAgentList() {
|
fetchAgentList() {
|
||||||
import('@/apis/module/user').then(({ default: userApi }) => {
|
import('@/apis/module/agent').then(({ default: userApi }) => {
|
||||||
userApi.getAgentList(({data}) => {
|
userApi.getAgentList(({data}) => {
|
||||||
this.originalDevices = data.data.map(item => ({
|
this.originalDevices = data.data.map(item => ({
|
||||||
...item,
|
...item,
|
||||||
@@ -106,7 +106,7 @@ export default {
|
|||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning'
|
type: 'warning'
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
import('@/apis/module/user').then(({ default: userApi }) => {
|
import('@/apis/module/agent').then(({ default: userApi }) => {
|
||||||
userApi.deleteAgent(agentId, (res) => {
|
userApi.deleteAgent(agentId, (res) => {
|
||||||
if (res.data.code === 0) {
|
if (res.data.code === 0) {
|
||||||
this.$message.success('删除成功');
|
this.$message.success('删除成功');
|
||||||
|
|||||||
@@ -59,7 +59,7 @@
|
|||||||
清除
|
清除
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="color: #979db1;font-size:11px;">{{ form.langCode.length }}/1000</div>
|
<div style="color: #979db1;font-size:11px;">{{ (form.langCode || '').length }}/1000</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@@ -132,7 +132,7 @@ export default {
|
|||||||
{label: '意图识别模型(Intent)', key: 'intentModelId'},
|
{label: '意图识别模型(Intent)', key: 'intentModelId'},
|
||||||
{label: '记忆模型(Memory)', key: 'memModelId'}
|
{label: '记忆模型(Memory)', key: 'memModelId'}
|
||||||
],
|
],
|
||||||
templates: ['台湾女友', '土豆子', '英语老师', '好奇小男孩', '汪汪队队长'],
|
templates: ['湾湾小何', '星际游子', '英语老师', '好奇男孩', '汪汪队长'],
|
||||||
loadingTemplate: false
|
loadingTemplate: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -153,8 +153,8 @@ export default {
|
|||||||
language: this.form.language,
|
language: this.form.language,
|
||||||
sort: this.form.sort
|
sort: this.form.sort
|
||||||
};
|
};
|
||||||
import('@/apis/module/user').then(({default: userApi}) => {
|
import('@/apis/module/agent').then(({default: agentApi}) => {
|
||||||
userApi.updateAgentConfig(this.$route.query.agentId, configData, ({data}) => {
|
agentApi.updateAgentConfig(this.$route.query.agentId, configData, ({data}) => {
|
||||||
if (data.code === 0) {
|
if (data.code === 0) {
|
||||||
this.$message.success('配置保存成功');
|
this.$message.success('配置保存成功');
|
||||||
} else {
|
} else {
|
||||||
@@ -192,27 +192,31 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
selectTemplate(templateName) {
|
selectTemplate(templateName) {
|
||||||
if (this.loadingTemplate) return;
|
if (this.loadingTemplate) return;
|
||||||
|
this.loadingTemplate = true;
|
||||||
this.loadingTemplate = true;
|
import('@/apis/module/agent').then(({default: agentApi}) => {
|
||||||
import('@/apis/module/user').then(({default: userApi}) => {
|
agentApi.getAgentTemplate((response) => { // 移除参数传递
|
||||||
userApi.getAgentTemplate(
|
this.loadingTemplate = false;
|
||||||
{templateName},
|
if (response.data.code === 0) {
|
||||||
(response) => {
|
// 在客户端过滤匹配的模板
|
||||||
this.loadingTemplate = false;
|
const matchedTemplate = response.data.data.find(
|
||||||
if (response.data.code === 0 && response.data.data.length > 0) {
|
t => t.agentName === templateName
|
||||||
this.applyTemplateData(response.data.data[0]);
|
);
|
||||||
this.$message.success(`「${templateName}」模板已应用`);
|
if (matchedTemplate) {
|
||||||
} else {
|
this.applyTemplateData(matchedTemplate);
|
||||||
this.$message.warning(`未找到「${templateName}」模板`);
|
this.$message.success(`「${templateName}」模板已应用`);
|
||||||
}
|
} else {
|
||||||
}
|
this.$message.warning(`未找到「${templateName}」模板`);
|
||||||
);
|
}
|
||||||
}).catch((error) => {
|
} else {
|
||||||
this.loadingTemplate = false;
|
this.$message.error(response.data.msg || '获取模板失败');
|
||||||
this.$message.error('模板加载失败');
|
}
|
||||||
console.error('接口异常:', error);
|
});
|
||||||
});
|
}).catch((error) => {
|
||||||
|
this.loadingTemplate = false;
|
||||||
|
this.$message.error('模板加载失败');
|
||||||
|
console.error('接口异常:', error);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
applyTemplateData(templateData) {
|
applyTemplateData(templateData) {
|
||||||
this.form = {
|
this.form = {
|
||||||
@@ -232,8 +236,8 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
fetchAgentConfig(agentId) {
|
fetchAgentConfig(agentId) {
|
||||||
import('@/apis/module/user').then(({default: userApi}) => {
|
import('@/apis/module/agent').then(({default: agentApi}) => {
|
||||||
userApi.getDeviceConfig(agentId, ({data}) => {
|
agentApi.getDeviceConfig(agentId, ({data}) => {
|
||||||
if (data.code === 0) {
|
if (data.code === 0) {
|
||||||
this.form = {
|
this.form = {
|
||||||
...this.form,
|
...this.form,
|
||||||
|
|||||||
Reference in New Issue
Block a user