mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
working agents fetching
This commit is contained in:
parent
b0f8f73006
commit
bbe6730205
3 changed files with 195 additions and 38 deletions
|
|
@ -10,22 +10,22 @@ knife4j:
|
||||||
|
|
||||||
# Server configuration
|
# Server configuration
|
||||||
server:
|
server:
|
||||||
secret: a3c1734a-1efe-4ab7-8f43-98f88b874e4b
|
secret: d153e93c-bb2f-42e7-8045-a1ee47a1dcfc
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
druid:
|
druid:
|
||||||
#MySQL - Local Docker Configuration
|
#MySQL
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
# # Railway MySQL Configuration - Updated for Railway database
|
||||||
# Local Docker MySQL Configuration
|
# url: jdbc:mysql://yamanote.proxy.rlwy.net:16958/railway?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&useSSL=true&allowPublicKeyRetrieval=true
|
||||||
url: jdbc:mysql://localhost:3307/manager_api?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&useSSL=false&allowPublicKeyRetrieval=true
|
|
||||||
username: manager
|
|
||||||
password: managerpassword
|
|
||||||
|
|
||||||
# Railway MySQL Configuration (commented out for local development)
|
|
||||||
# url: jdbc:mysql://crossover.proxy.rlwy.net:56145/railway?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&useSSL=true&allowPublicKeyRetrieval=true
|
|
||||||
# username: root
|
# username: root
|
||||||
# password: XjOWQwtGNcoMIELTjoMoaaBTfKiBjVcA
|
# password: cTefiuLmZSMqGpcQImUmBIsUBhNyUvrK
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
# Railway MySQL Configuration - Updated for Railway database
|
||||||
|
url: jdbc:mysql://crossover.proxy.rlwy.net:56145/railway?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Kolkata&nullCatalogMeansCurrent=true&useSSL=true&allowPublicKeyRetrieval=true
|
||||||
|
username: root
|
||||||
|
password: XjOWQwtGNcoMIELTjoMoaaBTfKiBjVcA
|
||||||
|
|
||||||
initial-size: 10
|
initial-size: 10
|
||||||
max-active: 100
|
max-active: 100
|
||||||
min-idle: 10
|
min-idle: 10
|
||||||
|
|
@ -49,23 +49,19 @@ spring:
|
||||||
multi-statement-allow: true
|
multi-statement-allow: true
|
||||||
data:
|
data:
|
||||||
redis:
|
redis:
|
||||||
# Local Docker Redis Configuration
|
# Railway Redis Configuration
|
||||||
host: localhost # Local Redis服务器地址
|
host: yamanote.proxy.rlwy.net # Railway Redis服务器地址
|
||||||
port: 6380 # Local Redis服务器连接端口
|
port: 34938 # Railway Redis服务器连接端口
|
||||||
password: redispassword # Local Redis服务器连接密码
|
password: YbdhwguVUNowduNpDZjuSefZFhBXiOEP # Railway Redis服务器连接密码
|
||||||
|
username: default # Railway Redis用户名
|
||||||
database: 0 # Redis数据库索引(默认为0)
|
database: 0 # Redis数据库索引(默认为0)
|
||||||
timeout: 10000ms # 连接超时时间(毫秒)
|
timeout: 30000ms # 连接超时时间(毫秒)- 增加超时时间
|
||||||
ssl:
|
ssl:
|
||||||
enabled: false # 本地开发不需要SSL
|
enabled: false # 尝试禁用SSL,Railway可能不需要
|
||||||
|
|
||||||
# Railway Redis Configuration (commented out for local development)
|
|
||||||
# host: yamanote.proxy.rlwy.net # Railway Redis服务器地址
|
|
||||||
# port: 34938 # Railway Redis服务器连接端口
|
|
||||||
# password: YbdhwguVUNowduNpDZjuSefZFhBXiOEP # Railway Redis服务器连接密码
|
|
||||||
# username: default # Railway Redis用户名
|
|
||||||
lettuce:
|
lettuce:
|
||||||
pool:
|
pool:
|
||||||
max-active: 8 # 连接池最大连接数(使用负值表示没有限制)
|
max-active: 8 # 连接池最大连接数(使用负值表示没有限制)
|
||||||
max-idle: 8 # 连接池中的最大空闲连接
|
max-idle: 8 # 连接池中的最大空闲连接
|
||||||
min-idle: 0 # 连接池中的最小空闲连接
|
min-idle: 0 # 连接池中的最小空闲连接
|
||||||
shutdown-timeout: 100ms # 客户端优雅关闭的等待时间
|
shutdown-timeout: 100ms # 客户端优雅关闭的等待时间
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,9 +84,33 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
|
console.log('Home component mounted, fetching agent list'); // Debug log
|
||||||
this.fetchAgentList();
|
this.fetchAgentList();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
activated() {
|
||||||
|
// This runs when component is activated (useful if using keep-alive)
|
||||||
|
console.log('Home component activated, fetching agent list'); // Debug log
|
||||||
|
this.fetchAgentList();
|
||||||
|
},
|
||||||
|
|
||||||
|
created() {
|
||||||
|
console.log('Home component created'); // Debug log
|
||||||
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
'$route'(to, from) {
|
||||||
|
// Watch for route changes - refetch data when navigating back to home
|
||||||
|
console.log('Route changed:', from.path, '->', to.path); // Debug log
|
||||||
|
if (to.name === 'home' || to.path === '/home') {
|
||||||
|
console.log('Navigated back to home, refetching agent list'); // Debug log
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.fetchAgentList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
showAddDialog() {
|
showAddDialog() {
|
||||||
this.addDeviceDialogVisible = true
|
this.addDeviceDialogVisible = true
|
||||||
|
|
@ -129,24 +153,34 @@ export default {
|
||||||
// 获取智能体列表
|
// 获取智能体列表
|
||||||
fetchAgentList() {
|
fetchAgentList() {
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
|
console.log('Starting to fetch agent list...'); // Debug log
|
||||||
|
|
||||||
// 根据用户角色决定使用哪个API
|
// 根据用户角色决定使用哪个API
|
||||||
const isAdmin = this.$store.getters.getIsSuperAdmin;
|
const isAdmin = this.$store.getters.getIsSuperAdmin;
|
||||||
|
console.log('User is admin:', isAdmin); // Debug log
|
||||||
|
|
||||||
if (isAdmin) {
|
if (isAdmin) {
|
||||||
// 管理员:获取所有智能体
|
// 管理员:获取所有智能体
|
||||||
Api.agent.getAgentList(({ data }) => {
|
console.log('Fetching admin agent list...'); // Debug log
|
||||||
this.handleAgentListResponse(data);
|
Api.agent.getAgentList((response) => {
|
||||||
|
console.log('Admin API response received:', response); // Debug log
|
||||||
|
// Extract response.data to match expected structure
|
||||||
|
this.handleAgentListResponse(response.data);
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
console.error('Failed to fetch admin agent list:', error);
|
console.error('Failed to fetch admin agent list:', error);
|
||||||
|
this.$message.error('Failed to load agent list. Please check your connection and try again.');
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// 普通用户:只获取自己的智能体
|
// 普通用户:只获取自己的智能体
|
||||||
Api.agent.getUserAgentList(({ data }) => {
|
console.log('Fetching user agent list...'); // Debug log
|
||||||
this.handleAgentListResponse(data);
|
Api.agent.getUserAgentList((response) => {
|
||||||
|
console.log('User API response received:', response); // Debug log
|
||||||
|
// Extract response.data to match expected structure
|
||||||
|
this.handleAgentListResponse(response.data);
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
console.error('Failed to fetch user agent list:', error);
|
console.error('Failed to fetch user agent list:', error);
|
||||||
|
this.$message.error('Failed to load your agents. Please check your connection and try again.');
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -154,14 +188,43 @@ export default {
|
||||||
|
|
||||||
// 处理智能体列表响应
|
// 处理智能体列表响应
|
||||||
handleAgentListResponse(data) {
|
handleAgentListResponse(data) {
|
||||||
if (data?.data) {
|
console.log('Raw API Response:', data); // Debug log
|
||||||
// 对于用户API,数据直接在data中;对于管理员API,数据在data.list中
|
|
||||||
const agentList = data.data.list || data.data;
|
|
||||||
|
|
||||||
this.originalDevices = agentList.map(item => ({
|
if (data) {
|
||||||
...item,
|
// The parameter 'data' is already response.data from the API call
|
||||||
agentId: item.id
|
let agentList = [];
|
||||||
}));
|
|
||||||
|
// The API response structure is nested: response.data.data.list
|
||||||
|
if (data.data && data.data.list && Array.isArray(data.data.list)) {
|
||||||
|
// For admin API: data.data.list (nested structure)
|
||||||
|
agentList = data.data.list;
|
||||||
|
console.log('Using data.data.list structure'); // Debug log
|
||||||
|
} else if (data.list && Array.isArray(data.list)) {
|
||||||
|
// For fallback: data.list
|
||||||
|
agentList = data.list;
|
||||||
|
console.log('Using data.list structure'); // Debug log
|
||||||
|
} else if (Array.isArray(data.data)) {
|
||||||
|
// For user API: data.data (direct array)
|
||||||
|
agentList = data.data;
|
||||||
|
console.log('Using data.data array structure'); // Debug log
|
||||||
|
} else if (Array.isArray(data)) {
|
||||||
|
// For direct array: data
|
||||||
|
agentList = data;
|
||||||
|
console.log('Using direct array structure'); // Debug log
|
||||||
|
} else {
|
||||||
|
console.error('Unexpected API response structure:', data);
|
||||||
|
console.error('Available keys in data:', Object.keys(data || {})); // Debug log
|
||||||
|
this.$message.error('Failed to load agent list: Invalid response format');
|
||||||
|
this.isLoading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Agent list before processing:', agentList); // Debug log
|
||||||
|
|
||||||
|
// 处理agent数据并获取模型名称
|
||||||
|
this.processAgentListWithModelNames(agentList);
|
||||||
|
|
||||||
|
console.log('Final processed devices:', this.originalDevices); // Debug log
|
||||||
|
|
||||||
// 动态设置骨架屏数量(可选)
|
// 动态设置骨架屏数量(可选)
|
||||||
this.skeletonCount = Math.min(
|
this.skeletonCount = Math.min(
|
||||||
|
|
@ -170,6 +233,9 @@ export default {
|
||||||
);
|
);
|
||||||
|
|
||||||
this.handleSearchReset();
|
this.handleSearchReset();
|
||||||
|
} else {
|
||||||
|
console.error('No data in API response:', data);
|
||||||
|
this.$message.error('Failed to load agent list: No data received');
|
||||||
}
|
}
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
},
|
},
|
||||||
|
|
@ -196,6 +262,101 @@ export default {
|
||||||
});
|
});
|
||||||
}).catch(() => { });
|
}).catch(() => { });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 处理agent列表并获取模型名称
|
||||||
|
async processAgentListWithModelNames(agentList) {
|
||||||
|
// 首先创建基本的设备列表
|
||||||
|
const basicDevices = agentList
|
||||||
|
.filter(item => item && (item.id || item.agentId))
|
||||||
|
.map(item => ({
|
||||||
|
...item,
|
||||||
|
agentId: item.agentId || item.id,
|
||||||
|
agentName: item.agentName || item.name || 'Unknown Agent',
|
||||||
|
// 暂时使用模型ID,稍后会被替换为模型名称
|
||||||
|
llmModelName: item.llmModelId || 'Not configured',
|
||||||
|
ttsModelName: item.ttsModelId || 'Not configured',
|
||||||
|
ttsVoiceName: item.ttsVoiceId || 'Default',
|
||||||
|
deviceCount: item.deviceCount || 0,
|
||||||
|
memModelId: item.memModelId || 'Memory_nomem',
|
||||||
|
lastConnectedAt: item.lastConnectedAt || null,
|
||||||
|
systemPrompt: item.systemPrompt || 'No system prompt configured',
|
||||||
|
ownerUsername: item.ownerUsername || null,
|
||||||
|
// 保留原始ID用于获取模型名称
|
||||||
|
originalLlmModelId: item.llmModelId,
|
||||||
|
originalTtsModelId: item.ttsModelId,
|
||||||
|
originalTtsVoiceId: item.ttsVoiceId
|
||||||
|
}));
|
||||||
|
|
||||||
|
console.log('Basic devices processed:', basicDevices); // Debug log
|
||||||
|
|
||||||
|
// 设置基本数据先显示
|
||||||
|
this.originalDevices = basicDevices;
|
||||||
|
this.handleSearchReset();
|
||||||
|
|
||||||
|
// 异步获取模型名称并更新
|
||||||
|
this.fetchModelNamesForDevices();
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取所有设备的模型名称
|
||||||
|
fetchModelNamesForDevices() {
|
||||||
|
const uniqueLlmModels = [...new Set(this.originalDevices.map(d => d.originalLlmModelId).filter(Boolean))];
|
||||||
|
const uniqueTtsModels = [...new Set(this.originalDevices.map(d => d.originalTtsModelId).filter(Boolean))];
|
||||||
|
const uniqueVoiceIds = [...new Set(this.originalDevices.map(d => d.originalTtsVoiceId).filter(Boolean))];
|
||||||
|
|
||||||
|
console.log('Fetching names for:', { uniqueLlmModels, uniqueTtsModels, uniqueVoiceIds });
|
||||||
|
|
||||||
|
// 获取LLM模型名称
|
||||||
|
uniqueLlmModels.forEach(modelId => {
|
||||||
|
Api.model.getModelConfig(modelId, (response) => {
|
||||||
|
console.log(`LLM Model response for ${modelId}:`, response);
|
||||||
|
if (response.data && response.data.code === 0) {
|
||||||
|
const modelName = response.data.data?.modelName || modelId;
|
||||||
|
this.updateDeviceModelName('llmModelName', modelId, modelName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取TTS模型名称
|
||||||
|
uniqueTtsModels.forEach(modelId => {
|
||||||
|
Api.model.getModelConfig(modelId, (response) => {
|
||||||
|
console.log(`TTS Model response for ${modelId}:`, response);
|
||||||
|
if (response.data && response.data.code === 0) {
|
||||||
|
const modelName = response.data.data?.modelName || modelId;
|
||||||
|
this.updateDeviceModelName('ttsModelName', modelId, modelName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取TTS声音名称 (暂时跳过自定义语音,只显示ID)
|
||||||
|
console.log('Voice IDs will be displayed as-is for now');
|
||||||
|
},
|
||||||
|
|
||||||
|
// 更新设备的模型名称
|
||||||
|
updateDeviceModelName(field, originalId, newName) {
|
||||||
|
const fieldMapping = {
|
||||||
|
'llmModelName': 'originalLlmModelId',
|
||||||
|
'ttsModelName': 'originalTtsModelId',
|
||||||
|
'ttsVoiceName': 'originalTtsVoiceId'
|
||||||
|
};
|
||||||
|
|
||||||
|
this.originalDevices = this.originalDevices.map(device => {
|
||||||
|
if (device[fieldMapping[field]] === originalId) {
|
||||||
|
return { ...device, [field]: newName };
|
||||||
|
}
|
||||||
|
return device;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 如果当前显示的是搜索结果,也要更新搜索结果
|
||||||
|
this.devices = this.devices.map(device => {
|
||||||
|
if (device[fieldMapping[field]] === originalId) {
|
||||||
|
return { ...device, [field]: newName };
|
||||||
|
}
|
||||||
|
return device;
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`Updated ${field} for ${originalId} to: ${newName}`);
|
||||||
|
},
|
||||||
|
|
||||||
handleShowChatHistory({ agentId, agentName }) {
|
handleShowChatHistory({ agentId, agentName }) {
|
||||||
this.currentAgentId = agentId;
|
this.currentAgentId = agentId;
|
||||||
this.currentAgentName = agentName;
|
this.currentAgentName = agentName;
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@
|
||||||
"production": {
|
"production": {
|
||||||
"chat_servers": [
|
"chat_servers": [
|
||||||
|
|
||||||
"ws://192.168.1.98:8000/toy/v1/"
|
"ws://64.227.170.31:8000/toy/v1/"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"development": {
|
"development": {
|
||||||
"chat_servers": [
|
"chat_servers": [
|
||||||
|
|
||||||
"ws://192.168.1.98:8000/toy/v1/"
|
"ws://64.227.170.31:8000/toy/v1/"
|
||||||
|
|
||||||
],
|
],
|
||||||
"mac_addresss": [
|
"mac_addresss": [
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue