Compare commits

...

1 Commits

Author SHA1 Message Date
claude[bot] 38f587bc58 🌐 chore: translate non-English comments to English in openapi services
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-27 03:21:36 +00:00
9 changed files with 125 additions and 125 deletions
+4 -4
View File
@@ -46,7 +46,7 @@ export function addFilesUrlPrefix<T extends { path?: string; url?: string }>(fil
export async function parseFormData(c: Context): Promise<FormData> {
const contentType = c.req.header('content-type') || '';
if (!/multipart\/form-data/i.test(contentType)) {
throw new Error('Content-Type 必须是 multipart/form-data');
throw new Error('Content-Type must be multipart/form-data');
}
// Prefer formidable (streaming, robust); fall back to native formData() on failure
@@ -54,14 +54,14 @@ export async function parseFormData(c: Context): Promise<FormData> {
const webReq = c.req.raw as Request;
const webBody = webReq.body;
if (!webBody) {
throw new Error('解析失败:当前请求缺少可读的 body 流');
throw new Error('Parse failed: request body stream is missing or not readable');
}
// Convert Web ReadableStream to Node Readable (Node 18+)
const nodeReadable =
typeof Readable?.fromWeb === 'function' ? Readable.fromWeb(webBody as any) : null;
if (!nodeReadable) {
throw new Error('解析失败:运行时不支持 Readable.fromWeb,将不进行回退');
throw new Error('Parse failed: runtime does not support Readable.fromWeb, no fallback will be attempted');
}
// Construct a minimal Node-like IncomingMessage for formidable
@@ -125,6 +125,6 @@ export async function parseFormData(c: Context): Promise<FormData> {
return fd;
} catch (e) {
// Re-throw the error to let the caller handle it via unified exception handling
throw e instanceof Error ? e : new Error('parseFormData 解析失败');
throw e instanceof Error ? e : new Error('parseFormData parsing failed');
}
}
@@ -36,7 +36,7 @@ export class AgentGroupService extends BaseService {
// Permission check
const permissionResult = await this.resolveOperationPermission('AGENT_READ');
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权访问助理分类列表');
throw this.createAuthorizationError(permissionResult.message || 'No permission to access agent group list');
}
// Build query conditions
@@ -55,7 +55,7 @@ export class AgentGroupService extends BaseService {
return agentGroupList;
} catch (error) {
this.handleServiceError(error, '获取助理分类列表');
this.handleServiceError(error, 'Get agent group list');
}
}
@@ -71,7 +71,7 @@ export class AgentGroupService extends BaseService {
// Permission check
const permissionResult = await this.resolveOperationPermission('AGENT_READ');
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权访问此助理分类');
throw this.createAuthorizationError(permissionResult.message || 'No permission to access this agent group');
}
// Build query conditions
@@ -92,7 +92,7 @@ export class AgentGroupService extends BaseService {
return agentGroup;
} catch (error) {
this.handleServiceError(error, '获取助理分类详情');
this.handleServiceError(error, 'Get agent group detail');
}
}
@@ -108,7 +108,7 @@ export class AgentGroupService extends BaseService {
// Permission check
const permissionResult = await this.resolveOperationPermission('AGENT_CREATE');
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权创建助理分类');
throw this.createAuthorizationError(permissionResult.message || 'No permission to create agent group');
}
const [result] = await this.db
@@ -121,13 +121,13 @@ export class AgentGroupService extends BaseService {
.returning();
if (!result) {
throw this.createBusinessError('助理分类创建失败');
throw this.createBusinessError('Failed to create agent group');
}
this.log('info', 'Agent group created successfully', { id: result.id, name: request.name });
return result.id;
} catch (error) {
this.handleServiceError(error, '创建助理分类');
this.handleServiceError(error, 'Create agent group');
}
}
@@ -143,7 +143,7 @@ export class AgentGroupService extends BaseService {
// Permission check
const permissionResult = await this.resolveOperationPermission('AGENT_UPDATE');
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权更新助理分类');
throw this.createAuthorizationError(permissionResult.message || 'No permission to update agent group');
}
const { id, ...updateData } = request;
@@ -151,7 +151,7 @@ export class AgentGroupService extends BaseService {
// Check if agent group exists
const existingGroup = await this.sessionGroupModel.findById(id);
if (!existingGroup) {
throw this.createBusinessError(`助理分类 ID "${id}" 不存在`);
throw this.createBusinessError(`Agent group ID "${id}" does not exist`);
}
await this.db
@@ -161,7 +161,7 @@ export class AgentGroupService extends BaseService {
this.log('info', 'Agent group updated successfully', { id });
} catch (error) {
this.handleServiceError(error, '更新助理分类');
this.handleServiceError(error, 'Update agent group');
}
}
@@ -177,13 +177,13 @@ export class AgentGroupService extends BaseService {
// Permission check
const permissionResult = await this.resolveOperationPermission('AGENT_DELETE');
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权删除助理分类');
throw this.createAuthorizationError(permissionResult.message || 'No permission to delete agent group');
}
// Check if agent group exists
const existingGroup = await this.sessionGroupModel.findById(request.id);
if (!existingGroup) {
throw this.createBusinessError(`助理分类 ID "${request.id}" 不存在`);
throw this.createBusinessError(`Agent group ID "${request.id}" does not exist`);
}
// Build query conditions
@@ -197,7 +197,7 @@ export class AgentGroupService extends BaseService {
this.log('info', 'Agent group deleted successfully', { id: request.id });
} catch (error) {
this.handleServiceError(error, '删除助理分类');
this.handleServiceError(error, 'Delete agent group');
}
}
}
+27 -27
View File
@@ -33,7 +33,7 @@ export class AgentService extends BaseService {
* @returns The user's Agent list
*/
async queryAgents(request: GetAgentsRequest): ServiceResult<AgentListResponse> {
this.log('info', '获取 Agent 列表', { request });
this.log('info', 'Get Agent list', { request });
const { keyword } = request;
@@ -58,14 +58,14 @@ export class AgentService extends BaseService {
const [agentsList, totalResult] = await Promise.all([query, countQuery]);
this.log('info', `查询到 ${agentsList.length} Agent`);
this.log('info', `Found ${agentsList.length} Agent(s)`);
return {
agents: agentsList,
total: totalResult[0]?.count ?? 0,
};
} catch (error) {
this.handleServiceError(error, '获取 Agent 列表');
this.handleServiceError(error, 'Get Agent list');
}
}
@@ -75,7 +75,7 @@ export class AgentService extends BaseService {
* @returns Created Agent info
*/
async createAgent(request: CreateAgentRequest): ServiceResult<AgentDetailResponse> {
this.log('info', '创建智能体', { title: request.title });
this.log('info', 'Create Agent', { title: request.title });
try {
return await this.db.transaction(async (tx) => {
@@ -99,12 +99,12 @@ export class AgentService extends BaseService {
// Insert into database
const [createdAgent] = await tx.insert(agents).values(newAgentData).returning();
this.log('info', 'Agent 创建成功', { id: createdAgent.id, slug: createdAgent.slug });
this.log('info', 'Agent created successfully', { id: createdAgent.id, slug: createdAgent.slug });
return createdAgent;
});
} catch (error) {
this.handleServiceError(error, '创建 Agent');
this.handleServiceError(error, 'Create Agent');
}
}
@@ -114,7 +114,7 @@ export class AgentService extends BaseService {
* @returns Updated Agent info
*/
async updateAgent(request: UpdateAgentRequest): ServiceResult<AgentDetailResponse> {
this.log('info', '更新智能体', { id: request.id, title: request.title });
this.log('info', 'Update Agent', { id: request.id, title: request.title });
try {
// Permission validation
@@ -123,7 +123,7 @@ export class AgentService extends BaseService {
});
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权更新此 Agent');
throw this.createAuthorizationError(permissionResult.message || 'No permission to update this Agent');
}
return await this.db.transaction(async (tx) => {
@@ -139,7 +139,7 @@ export class AgentService extends BaseService {
});
if (!existingAgent) {
throw this.createBusinessError(`Agent ID "${request.id}" 不存在`);
throw this.createBusinessError(`Agent ID "${request.id}" does not exist`);
}
// Only update fields actually provided in the request to avoid overwriting existing values with undefined
@@ -177,11 +177,11 @@ export class AgentService extends BaseService {
.where(and(...whereConditions))
.returning();
this.log('info', 'Agent 更新成功', { id: updatedAgent.id, slug: updatedAgent.slug });
this.log('info', 'Agent updated successfully', { id: updatedAgent.id, slug: updatedAgent.slug });
return updatedAgent;
});
} catch (error) {
this.handleServiceError(error, '更新 Agent');
this.handleServiceError(error, 'Update Agent');
}
}
@@ -190,7 +190,7 @@ export class AgentService extends BaseService {
* @param request Delete request parameters
*/
async deleteAgent(request: AgentDeleteRequest): ServiceResult<void> {
this.log('info', '删除智能体', {
this.log('info', 'Delete Agent', {
agentId: request.agentId,
migrateSessionTo: request.migrateSessionTo,
});
@@ -202,7 +202,7 @@ export class AgentService extends BaseService {
});
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权删除此 Agent');
throw this.createAuthorizationError(permissionResult.message || 'No permission to delete this Agent');
}
// Check if the Agent to be deleted exists
@@ -211,7 +211,7 @@ export class AgentService extends BaseService {
});
if (!targetAgent) {
throw this.createBusinessError(`Agent ID ${request.agentId} 不存在`);
throw this.createBusinessError(`Agent ID ${request.agentId} does not exist`);
}
if (request.migrateSessionTo) {
@@ -221,13 +221,13 @@ export class AgentService extends BaseService {
});
if (!migrateTarget) {
throw this.createBusinessError(`迁移目标 Agent ID ${request.migrateSessionTo} 不存在`);
throw this.createBusinessError(`Migration target Agent ID ${request.migrateSessionTo} does not exist`);
}
// Migrate session associations to the target Agent
await this.migrateAgentSessions(request.agentId, request.migrateSessionTo);
this.log('info', '会话迁移完成', {
this.log('info', 'Session migration completed', {
from: request.agentId,
to: request.migrateSessionTo,
});
@@ -242,9 +242,9 @@ export class AgentService extends BaseService {
await agentModel.delete(request.agentId);
}
this.log('info', 'Agent 删除成功', { agentId: request.agentId });
this.log('info', 'Agent deleted successfully', { agentId: request.agentId });
} catch (error) {
this.handleServiceError(error, '删除 Agent');
this.handleServiceError(error, 'Delete Agent');
}
}
@@ -254,7 +254,7 @@ export class AgentService extends BaseService {
* @returns Agent details
*/
async getAgentById(agentId: string): ServiceResult<AgentDetailResponse | null> {
this.log('info', '根据 ID 获取 Agent 详情', { agentId });
this.log('info', 'Get Agent detail by ID', { agentId });
try {
// Permission validation
@@ -263,11 +263,11 @@ export class AgentService extends BaseService {
});
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权访问此 Agent');
throw this.createAuthorizationError(permissionResult.message || 'No permission to access this Agent');
}
if (!this.userId) {
throw this.createAuthError('未登录,无法获取 Agent 详情');
throw this.createAuthError('Not logged in, unable to get Agent detail');
}
// Reuse AgentModel methods to get the full Agent configuration
@@ -275,13 +275,13 @@ export class AgentService extends BaseService {
const agent = await agentModel.getAgentConfigById(agentId);
if (!agent || !agent.id) {
this.log('warn', 'Agent 不存在', { agentId });
this.log('warn', 'Agent does not exist', { agentId });
return null;
}
return agent as AgentDetailResponse;
} catch (error) {
this.handleServiceError(error, '获取 Agent 详情');
this.handleServiceError(error, 'Get Agent detail');
}
}
@@ -292,7 +292,7 @@ export class AgentService extends BaseService {
* @private
*/
private async migrateAgentSessions(fromAgentId: string, toAgentId: string): Promise<void> {
this.log('info', '开始迁移会话', { fromAgentId, toAgentId });
this.log('info', 'Starting session migration', { fromAgentId, toAgentId });
try {
await this.db.transaction(async (tx) => {
@@ -346,12 +346,12 @@ export class AgentService extends BaseService {
);
}
this.log('info', '迁移会话完成', { count: newSessionIds.length });
this.log('info', 'Session migration completed', { count: newSessionIds.length });
});
this.log('info', '会话迁移成功', { fromAgentId, toAgentId });
this.log('info', 'Session migration succeeded', { fromAgentId, toAgentId });
} catch (error) {
this.handleServiceError(error, '会话迁移');
this.handleServiceError(error, 'Session migration');
}
}
}
@@ -41,7 +41,7 @@ export class KnowledgeBaseService extends BaseService {
const permissionResult = await this.resolveOperationPermission('KNOWLEDGE_BASE_READ');
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权访问知识库列表');
throw this.createAuthorizationError(permissionResult.message || 'No permission to access knowledge base list');
}
this.log('info', 'Getting knowledge base list', request);
@@ -95,7 +95,7 @@ export class KnowledgeBaseService extends BaseService {
total,
};
} catch (error) {
this.handleServiceError(error, '获取知识库列表');
this.handleServiceError(error, 'Get knowledge base list');
}
}
@@ -108,7 +108,7 @@ export class KnowledgeBaseService extends BaseService {
const permissionResult = await this.resolveOperationPermission('KNOWLEDGE_BASE_READ');
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权访问此知识库');
throw this.createAuthorizationError(permissionResult.message || 'No permission to access this knowledge base');
}
this.log('info', 'Getting knowledge base detail', { id });
@@ -126,7 +126,7 @@ export class KnowledgeBaseService extends BaseService {
knowledgeBase,
};
} catch (error) {
this.handleServiceError(error, '获取知识库详情');
this.handleServiceError(error, 'Get knowledge base detail');
}
}
@@ -141,7 +141,7 @@ export class KnowledgeBaseService extends BaseService {
const permissionResult = await this.resolveOperationPermission('KNOWLEDGE_BASE_CREATE');
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权创建知识库');
throw this.createAuthorizationError(permissionResult.message || 'No permission to create knowledge base');
}
this.log('info', 'Creating knowledge base', {
@@ -167,7 +167,7 @@ export class KnowledgeBaseService extends BaseService {
knowledgeBase,
};
} catch (error) {
this.handleServiceError(error, '创建知识库');
this.handleServiceError(error, 'Create knowledge base');
}
}
@@ -183,7 +183,7 @@ export class KnowledgeBaseService extends BaseService {
const permissionResult = await this.resolveOperationPermission('KNOWLEDGE_BASE_UPDATE');
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权更新此知识库');
throw this.createAuthorizationError(permissionResult.message || 'No permission to update this knowledge base');
}
this.log('info', 'Updating knowledge base', { id, request });
@@ -211,7 +211,7 @@ export class KnowledgeBaseService extends BaseService {
knowledgeBase: updatedKb as KnowledgeBaseItem,
};
} catch (error) {
this.handleServiceError(error, '更新知识库');
this.handleServiceError(error, 'Update knowledge base');
}
}
@@ -224,7 +224,7 @@ export class KnowledgeBaseService extends BaseService {
const permissionResult = await this.resolveOperationPermission('KNOWLEDGE_BASE_DELETE');
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权删除此知识库');
throw this.createAuthorizationError(permissionResult.message || 'No permission to delete this knowledge base');
}
this.log('info', 'Deleting knowledge base', { id });
@@ -258,7 +258,7 @@ export class KnowledgeBaseService extends BaseService {
success: true,
};
} catch (error) {
this.handleServiceError(error, '删除知识库');
this.handleServiceError(error, 'Delete knowledge base');
}
}
}
@@ -28,7 +28,7 @@ export class MessageTranslateService extends BaseService {
async getTranslateByMessageId(messageId: string): ServiceResult<MessageTranslateResponse | null> {
// Permission check is already done in the route layer (MESSAGE_READ + TRANSLATION_READ)
this.log('info', '根据消息ID获取翻译信息', { messageId, userId: this.userId });
this.log('info', 'Get translation info by message ID', { messageId, userId: this.userId });
try {
const result = await this.db.query.messageTranslates.findFirst({
@@ -36,7 +36,7 @@ export class MessageTranslateService extends BaseService {
});
if (!result) {
this.log('info', '未找到翻译信息', { messageId });
this.log('info', 'Translation info not found', { messageId });
return null;
}
@@ -49,10 +49,10 @@ export class MessageTranslateService extends BaseService {
userId: result.userId,
};
this.log('info', '获取翻译信息完成', { messageId });
this.log('info', 'Translation info retrieved successfully', { messageId });
return response;
} catch (error) {
this.handleServiceError(error, '根据消息ID获取翻译信息');
this.handleServiceError(error, 'Get translation info by message ID');
}
}
@@ -66,7 +66,7 @@ export class MessageTranslateService extends BaseService {
): ServiceResult<Partial<MessageTranslateItem>> {
// Permission check is already done in the route layer (MESSAGE_READ + TRANSLATION_CREATE)
this.log('info', '开始翻译消息', {
this.log('info', 'Starting message translation', {
...translateData,
userId: this.userId,
});
@@ -78,10 +78,10 @@ export class MessageTranslateService extends BaseService {
});
if (!messageInfo) {
throw this.createCommonError('未找到要翻译的消息');
throw this.createCommonError('Message to translate not found');
}
this.log('info', '原始消息内容', { originalMessage: messageInfo.content });
this.log('info', 'Original message content', { originalMessage: messageInfo.content });
// Use ChatService for translation, passing sessionId to use the correct model configuration
const chatService = new ChatService(this.db, this.userId);
@@ -99,7 +99,7 @@ export class MessageTranslateService extends BaseService {
content: translatedContent,
});
} catch (error) {
this.handleServiceError(error, '翻译消息');
this.handleServiceError(error, 'Translate message');
}
}
@@ -119,7 +119,7 @@ export class MessageTranslateService extends BaseService {
where: eq(messages.id, data.messageId),
});
if (!messageInfo) {
throw this.createCommonError('未找到要更新翻译信息的消息');
throw this.createCommonError('Message to update translation info not found');
}
// Update translation info and content
@@ -141,7 +141,7 @@ export class MessageTranslateService extends BaseService {
target: messageTranslates.id,
});
this.log('info', '更新翻译信息完成', { messageId: data.messageId });
this.log('info', 'Translation info updated successfully', { messageId: data.messageId });
return {
content: data.content,
@@ -151,7 +151,7 @@ export class MessageTranslateService extends BaseService {
userId: this.userId,
};
} catch (error) {
this.handleServiceError(error, '更新翻译信息');
this.handleServiceError(error, 'Update translation info');
}
}
@@ -172,14 +172,14 @@ export class MessageTranslateService extends BaseService {
});
if (!originalTranslation) {
throw this.createNotFoundError('翻译消息不存在');
throw this.createNotFoundError('Translation record does not exist');
}
await this.db.delete(messageTranslates).where(eq(messageTranslates.id, messageId));
return { deleted: true, messageId };
} catch (error) {
this.handleServiceError(error, '删除翻译信息');
this.handleServiceError(error, 'Delete translation info');
}
}
}
+18 -18
View File
@@ -28,7 +28,7 @@ export class ModelService extends BaseService {
* @param request Query request parameters
*/
async getModels(request: ModelsListQuery = {}): ServiceResult<GetModelsResponse> {
this.log('info', '获取模型列表', {
this.log('info', 'Get model list', {
...request,
userId: this.userId,
});
@@ -38,7 +38,7 @@ export class ModelService extends BaseService {
const permissionResult = await this.resolveOperationPermission('AI_MODEL_READ');
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权访问模型列表');
throw this.createAuthorizationError(permissionResult.message || 'No permission to access model list');
}
// Build query conditions
@@ -96,7 +96,7 @@ export class ModelService extends BaseService {
total: totalResult[0]?.count ?? 0,
};
} catch (error) {
this.handleServiceError(error, '获取模型列表失败');
this.handleServiceError(error, 'Failed to get model list');
}
}
@@ -104,7 +104,7 @@ export class ModelService extends BaseService {
* Get model details
*/
async getModelDetail(providerId: string, modelId: string): ServiceResult<ModelDetailResponse> {
this.log('info', '获取模型详情', { modelId, providerId, userId: this.userId });
this.log('info', 'Get model detail', { modelId, providerId, userId: this.userId });
try {
const permissionResult = await this.resolveOperationPermission('AI_MODEL_READ', {
@@ -112,7 +112,7 @@ export class ModelService extends BaseService {
});
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权访问模型详情');
throw this.createAuthorizationError(permissionResult.message || 'No permission to access model detail');
}
const conditions = [eq(aiModels.providerId, providerId), eq(aiModels.id, modelId)];
@@ -124,12 +124,12 @@ export class ModelService extends BaseService {
const model = await this.db.query.aiModels.findFirst({ where: and(...conditions) });
if (!model) {
throw this.createNotFoundError(`模型 ${providerId}/${modelId} 不存在`);
throw this.createNotFoundError(`Model ${providerId}/${modelId} does not exist`);
}
return model;
} catch (error) {
this.handleServiceError(error, '获取模型详情');
this.handleServiceError(error, 'Get model detail');
}
}
@@ -137,16 +137,16 @@ export class ModelService extends BaseService {
* Create a model
*/
async createModel(payload: CreateModelRequest): ServiceResult<ModelDetailResponse> {
this.log('info', '创建模型', { payload, userId: this.userId });
this.log('info', 'Create model', { payload, userId: this.userId });
try {
const permissionResult = await this.resolveOperationPermission('AI_MODEL_CREATE');
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权创建模型');
throw this.createAuthorizationError(permissionResult.message || 'No permission to create model');
}
if (!this.userId) {
throw this.createAuthError('用户未认证');
throw this.createAuthError('User not authenticated');
}
return await this.db.transaction(async (tx) => {
@@ -159,7 +159,7 @@ export class ModelService extends BaseService {
});
if (existingModel) {
throw this.createBusinessError(`模型 ${payload.providerId}/${payload.id} 已存在`);
throw this.createBusinessError(`Model ${payload.providerId}/${payload.id} already exists`);
}
const [created] = await tx
@@ -187,7 +187,7 @@ export class ModelService extends BaseService {
return created;
});
} catch (error) {
this.handleServiceError(error, '创建模型');
this.handleServiceError(error, 'Create model');
}
}
@@ -199,7 +199,7 @@ export class ModelService extends BaseService {
modelId: string,
payload: UpdateModelRequest,
): ServiceResult<ModelDetailResponse> {
this.log('info', '更新模型', { modelId, payload, providerId, userId: this.userId });
this.log('info', 'Update model', { modelId, payload, providerId, userId: this.userId });
try {
const permissionResult = await this.resolveOperationPermission('AI_MODEL_UPDATE', {
@@ -207,7 +207,7 @@ export class ModelService extends BaseService {
});
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权更新模型');
throw this.createAuthorizationError(permissionResult.message || 'No permission to update model');
}
const conditions = [eq(aiModels.providerId, providerId), eq(aiModels.id, modelId)];
@@ -219,7 +219,7 @@ export class ModelService extends BaseService {
const existingModel = await tx.query.aiModels.findFirst({ where: and(...conditions) });
if (!existingModel) {
throw this.createNotFoundError(`模型 ${providerId}/${modelId} 不存在`);
throw this.createNotFoundError(`Model ${providerId}/${modelId} does not exist`);
}
const updateFields = {
@@ -242,7 +242,7 @@ export class ModelService extends BaseService {
} as Record<string, unknown>;
if (Object.keys(updateFields).length === 1) {
throw this.createBusinessError('未提供需要更新的字段');
throw this.createBusinessError('No fields provided for update');
}
const [updated] = await tx
@@ -252,13 +252,13 @@ export class ModelService extends BaseService {
.returning();
if (!updated) {
throw this.createBusinessError('更新模型失败');
throw this.createBusinessError('Failed to update model');
}
return updated;
});
} catch (error) {
this.handleServiceError(error, '更新模型');
this.handleServiceError(error, 'Update model');
}
}
}
@@ -65,7 +65,7 @@ export class PermissionService extends BaseService {
total: totalResult[0]?.count || 0,
};
} catch (error) {
this.handleServiceError(error, '获取权限列表');
this.handleServiceError(error, 'Get permission list');
}
}
@@ -80,7 +80,7 @@ export class PermissionService extends BaseService {
return permission || null;
} catch (error) {
this.handleServiceError(error, '获取权限详情');
this.handleServiceError(error, 'Get permission detail');
}
}
@@ -111,7 +111,7 @@ export class PermissionService extends BaseService {
return created;
} catch (error) {
this.handleServiceError(error, '创建权限');
this.handleServiceError(error, 'Create permission');
}
}
@@ -162,7 +162,7 @@ export class PermissionService extends BaseService {
return updated;
} catch (error) {
this.handleServiceError(error, '更新权限');
this.handleServiceError(error, 'Update permission');
}
}
@@ -199,7 +199,7 @@ export class PermissionService extends BaseService {
return deleted;
} catch (error) {
this.handleServiceError(error, '删除权限');
this.handleServiceError(error, 'Delete permission');
}
}
}
@@ -64,7 +64,7 @@ export class ProviderService extends BaseService {
return undefined;
} catch (error) {
this.log('warn', '解密 Provider KeyVaults 失败', {
this.log('warn', 'Failed to decrypt Provider KeyVaults', {
error,
});
return undefined;
@@ -84,7 +84,7 @@ export class ProviderService extends BaseService {
}
async getProviders(request: ProviderListQuery = {}): ServiceResult<GetProvidersResponse> {
this.log('info', '获取 Provider 列表', {
this.log('info', 'Get Provider list', {
request,
userId: this.userId,
});
@@ -93,7 +93,7 @@ export class ProviderService extends BaseService {
const permissionResult = await this.resolveOperationPermission('AI_PROVIDER_READ');
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权访问 Provider 列表');
throw this.createAuthorizationError(permissionResult.message || 'No permission to access Provider list');
}
const conditions = [] as any[];
@@ -140,14 +140,14 @@ export class ProviderService extends BaseService {
total: totalResult[0]?.count ?? 0,
};
} catch (error) {
this.handleServiceError(error, '获取 Provider 列表');
this.handleServiceError(error, 'Get Provider list');
}
}
async getProviderDetail(
request: GetProviderDetailRequest,
): ServiceResult<ProviderDetailResponse> {
this.log('info', '获取 Provider 详情', {
this.log('info', 'Get Provider detail', {
id: request.id,
userId: this.userId,
});
@@ -158,7 +158,7 @@ export class ProviderService extends BaseService {
});
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权访问 Provider 详情');
throw this.createAuthorizationError(permissionResult.message || 'No permission to access Provider detail');
}
const whereConditions = [eq(aiProviders.id, request.id)];
@@ -175,17 +175,17 @@ export class ProviderService extends BaseService {
});
if (!provider) {
throw this.createNotFoundError(`未找到 Provider: ${request.id}`);
throw this.createNotFoundError(`Provider not found: ${request.id}`);
}
return await this.transformProviderRecord(provider);
} catch (error) {
this.handleServiceError(error, '获取 Provider 详情');
this.handleServiceError(error, 'Get Provider detail');
}
}
async createProvider(request: CreateProviderRequest): ServiceResult<ProviderDetailResponse> {
this.log('info', '创建 Provider', {
this.log('info', 'Create Provider', {
id: request.id,
userId: this.userId,
});
@@ -194,7 +194,7 @@ export class ProviderService extends BaseService {
const permissionResult = await this.resolveOperationPermission('AI_PROVIDER_CREATE');
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权创建 Provider');
throw this.createAuthorizationError(permissionResult.message || 'No permission to create Provider');
}
const ownerId = permissionResult.condition?.userId ?? this.userId;
@@ -204,7 +204,7 @@ export class ProviderService extends BaseService {
});
if (existed) {
throw this.createBusinessError(`Provider "${request.id}" 已存在`);
throw this.createBusinessError(`Provider "${request.id}" already exists`);
}
const encryptedKeyVaults = await this.encryptKeyVaults(request.keyVaults);
@@ -233,12 +233,12 @@ export class ProviderService extends BaseService {
return await this.transformProviderRecord(createdProvider);
} catch (error) {
this.handleServiceError(error, '创建 Provider');
this.handleServiceError(error, 'Create Provider');
}
}
async updateProvider(request: UpdateProviderRequest): ServiceResult<ProviderDetailResponse> {
this.log('info', '更新 Provider', {
this.log('info', 'Update Provider', {
id: request.id,
userId: this.userId,
});
@@ -249,7 +249,7 @@ export class ProviderService extends BaseService {
});
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权更新 Provider');
throw this.createAuthorizationError(permissionResult.message || 'No permission to update Provider');
}
const whereConditions = [eq(aiProviders.id, request.id)];
@@ -266,7 +266,7 @@ export class ProviderService extends BaseService {
});
if (!existing) {
throw this.createNotFoundError(`未找到 Provider: ${request.id}`);
throw this.createNotFoundError(`Provider not found: ${request.id}`);
}
const { id: _id, keyVaults, ...rest } = request;
@@ -295,17 +295,17 @@ export class ProviderService extends BaseService {
.returning();
if (!updatedProvider) {
throw this.createBusinessError('更新 Provider 失败');
throw this.createBusinessError('Failed to update Provider');
}
return await this.transformProviderRecord(updatedProvider);
} catch (error) {
this.handleServiceError(error, '更新 Provider');
this.handleServiceError(error, 'Update Provider');
}
}
async deleteProvider(request: DeleteProviderRequest): ServiceResult<{ id: string }> {
this.log('info', '删除 Provider', {
this.log('info', 'Delete Provider', {
id: request.id,
userId: this.userId,
});
@@ -316,7 +316,7 @@ export class ProviderService extends BaseService {
});
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权删除 Provider');
throw this.createAuthorizationError(permissionResult.message || 'No permission to delete Provider');
}
const whereConditions = [eq(aiProviders.id, request.id)];
@@ -333,7 +333,7 @@ export class ProviderService extends BaseService {
});
if (!provider) {
throw this.createNotFoundError(`未找到 Provider: ${request.id}`);
throw this.createNotFoundError(`Provider not found: ${request.id}`);
}
await this.db.transaction(async (tx) => {
@@ -350,13 +350,13 @@ export class ProviderService extends BaseService {
await tx.delete(aiProviders).where(providerWhere);
});
this.log('info', 'Provider 删除成功', {
this.log('info', 'Provider deleted successfully', {
id: request.id,
});
return { id: request.id };
} catch (error) {
this.handleServiceError(error, '删除 Provider');
this.handleServiceError(error, 'Delete Provider');
}
}
}
+13 -13
View File
@@ -30,7 +30,7 @@ export class TopicService extends BaseService {
const permissionResult = await this.resolveOperationPermission('TOPIC_READ');
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '没有权限访问话题列表');
throw this.createAuthorizationError(permissionResult.message || 'No permission to access topic list');
}
// Build query conditions
@@ -112,7 +112,7 @@ export class TopicService extends BaseService {
total: countResult.count,
};
} catch (error) {
this.handleServiceError(error, '获取话题列表');
this.handleServiceError(error, 'Get topic list');
}
}
@@ -124,7 +124,7 @@ export class TopicService extends BaseService {
});
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '没有权限访问该话题');
throw this.createAuthorizationError(permissionResult.message || 'No permission to access this topic');
}
// Build query conditions
@@ -149,7 +149,7 @@ export class TopicService extends BaseService {
.limit(1);
if (!result) {
throw this.createNotFoundError('话题不存在');
throw this.createNotFoundError('Topic does not exist');
}
return {
@@ -158,7 +158,7 @@ export class TopicService extends BaseService {
user: result.user,
};
} catch (error) {
return this.handleServiceError(error, '获取话题');
return this.handleServiceError(error, 'Get topic');
}
}
@@ -190,7 +190,7 @@ export class TopicService extends BaseService {
);
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '无权创建话题');
throw this.createAuthorizationError(permissionResult.message || 'No permission to create topic');
}
const [newTopic] = await this.db
@@ -209,7 +209,7 @@ export class TopicService extends BaseService {
return this.getTopicById(newTopic.id);
} catch (error) {
this.handleServiceError(error, '创建话题');
this.handleServiceError(error, 'Create topic');
}
}
@@ -227,7 +227,7 @@ export class TopicService extends BaseService {
});
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '没有权限更新该话题');
throw this.createAuthorizationError(permissionResult.message || 'No permission to update this topic');
}
// Build query conditions to check if topic exists
@@ -245,12 +245,12 @@ export class TopicService extends BaseService {
.returning();
if (!updatedTopic) {
throw this.createNotFoundError('话题不存在');
throw this.createNotFoundError('Topic does not exist');
}
return this.getTopicById(updatedTopic.id);
} catch (error) {
return this.handleServiceError(error, '更新话题');
return this.handleServiceError(error, 'Update topic');
}
}
@@ -266,7 +266,7 @@ export class TopicService extends BaseService {
});
if (!permissionResult.isPermitted) {
throw this.createAuthorizationError(permissionResult.message || '没有权限删除该话题');
throw this.createAuthorizationError(permissionResult.message || 'No permission to delete this topic');
}
// Build query conditions to check if topic exists
@@ -283,12 +283,12 @@ export class TopicService extends BaseService {
.returning();
if (!existingTopic) {
throw this.createNotFoundError('话题不存在');
throw this.createNotFoundError('Topic does not exist');
}
this.log('info', 'Topic deleted successfully', { topicId });
} catch (error) {
return this.handleServiceError(error, '删除话题');
return this.handleServiceError(error, 'Delete topic');
}
}
}