2025-08-25 13:57:47 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* AgentID验证工具类
|
|
|
|
|
|
* 统一处理AgentID相关的验证逻辑
|
|
|
|
|
|
*/
|
|
|
|
|
|
export class AgentValidator {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 验证AgentID是否存在
|
|
|
|
|
|
* @param {string} agentId - 要验证的AgentID
|
|
|
|
|
|
* @param {string} operation - 操作名称,用于错误提示
|
|
|
|
|
|
* @returns {boolean} 验证是否通过
|
|
|
|
|
|
*/
|
|
|
|
|
|
static validateAgentId(agentId, operation = '操作') {
|
|
|
|
|
|
if (!agentId) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
console.warn(`未指定AgentID,无法${operation}`)
|
|
|
|
|
|
return false
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return true
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 验证AgentID并显示错误提示
|
|
|
|
|
|
* @param {string} agentId - 要验证的AgentID
|
|
|
|
|
|
* @param {string} operation - 操作名称
|
|
|
|
|
|
* @param {Function} errorHandler - 错误处理函数
|
|
|
|
|
|
* @returns {boolean} 验证是否通过
|
|
|
|
|
|
*/
|
|
|
|
|
|
static validateAgentIdWithError(agentId, operation, errorHandler) {
|
|
|
|
|
|
if (!agentId) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const message = `未指定AgentID,无法${operation}`
|
2025-08-25 13:57:47 +08:00
|
|
|
|
if (errorHandler) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
errorHandler(message)
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return false
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return true
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 验证对话相关操作的前置条件
|
|
|
|
|
|
* @param {string} agentId - AgentID
|
|
|
|
|
|
* @param {string} chatId - 对话ID(可选)
|
|
|
|
|
|
* @param {string} operation - 操作名称
|
|
|
|
|
|
* @param {Function} errorHandler - 错误处理函数
|
|
|
|
|
|
* @returns {boolean} 验证是否通过
|
|
|
|
|
|
*/
|
|
|
|
|
|
static validateChatOperation(agentId, chatId, operation, errorHandler) {
|
|
|
|
|
|
// 验证AgentID
|
|
|
|
|
|
if (!this.validateAgentIdWithError(agentId, operation, errorHandler)) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return false
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果需要验证chatId
|
|
|
|
|
|
if (chatId !== undefined && !chatId) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const message = `请先选择对话`
|
2025-08-25 13:57:47 +08:00
|
|
|
|
if (errorHandler) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
errorHandler(message)
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return false
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return true
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 验证重命名操作的参数
|
|
|
|
|
|
* @param {string} chatId - 对话ID
|
|
|
|
|
|
* @param {string} title - 新标题
|
|
|
|
|
|
* @param {string} agentId - AgentID
|
|
|
|
|
|
* @param {Function} errorHandler - 错误处理函数
|
|
|
|
|
|
* @returns {boolean} 验证是否通过
|
|
|
|
|
|
*/
|
|
|
|
|
|
static validateRenameOperation(chatId, title, agentId, errorHandler) {
|
|
|
|
|
|
// 验证基本参数
|
|
|
|
|
|
if (!chatId || !title) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const message = '未指定对话ID或标题,无法重命名对话'
|
2025-08-25 13:57:47 +08:00
|
|
|
|
if (errorHandler) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
errorHandler(message)
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return false
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 验证标题不为空
|
|
|
|
|
|
if (!title.trim()) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const message = '标题不能为空'
|
2025-08-25 13:57:47 +08:00
|
|
|
|
if (errorHandler) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
errorHandler(message)
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return false
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 验证AgentID
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return this.validateAgentIdWithError(agentId, '重命名对话', errorHandler)
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 验证分享操作的前置条件
|
|
|
|
|
|
* @param {string} chatId - 对话ID
|
|
|
|
|
|
* @param {Object} agent - 当前智能体对象
|
|
|
|
|
|
* @param {Function} errorHandler - 错误处理函数
|
|
|
|
|
|
* @returns {boolean} 验证是否通过
|
|
|
|
|
|
*/
|
|
|
|
|
|
static validateShareOperation(chatId, agent, errorHandler) {
|
|
|
|
|
|
if (!chatId || !agent) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const message = '请先选择对话'
|
2025-08-25 13:57:47 +08:00
|
|
|
|
if (errorHandler) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
errorHandler(message)
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return false
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return true
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 验证加载操作的前置条件
|
|
|
|
|
|
* @param {string} agentId - AgentID
|
|
|
|
|
|
* @param {string} operation - 操作名称
|
|
|
|
|
|
* @returns {boolean} 验证是否通过
|
|
|
|
|
|
*/
|
|
|
|
|
|
static validateLoadOperation(agentId, operation = '加载状态') {
|
|
|
|
|
|
if (!agentId) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
console.warn(`未指定AgentID,无法${operation}`)
|
|
|
|
|
|
return false
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return true
|
2025-08-25 13:57:47 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|