🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🌐 chore: translate non-English comments to English in src/libs (#12353)
LobeHub Bota0c4baf1aa17
diff --git a/packages/database/src/server/models/__tests__/adapter.test.ts b/packages/database/src/server/models/__tests__/adapter.test.tsindex a3e4b4f91b8..4fcb29af8a3 100644--- a/packages/database/src/server/models/__tests__/adapter.test.ts+++ b/packages/database/src/server/models/__tests__/adapter.test.ts@@ -510,18 +510,20 @@ describe('DrizzleAdapter', () => {it('should throw error when using unsupported model name', async () => {const invalidAdapter = new DrizzleAdapter('InvalidModelName', serverDB);// Call a method that triggers getTable- await expect(invalidAdapter.find('any-id')).rejects.toThrow('不支持的模型: InvalidModelName');+ await expect(invalidAdapter.find('any-id')).rejects.toThrow(+ 'Unsupported model: InvalidModelName',+ );await expect(invalidAdapter.upsert('any-id', {}, 3600)).rejects.toThrow(- '不支持的模型: InvalidModelName',+ 'Unsupported model: InvalidModelName',);await expect(invalidAdapter.destroy('any-id')).rejects.toThrow(- '不支持的模型: InvalidModelName',+ 'Unsupported model: InvalidModelName',);await expect(invalidAdapter.consume('any-id')).rejects.toThrow(- '不支持的模型: InvalidModelName',+ 'Unsupported model: InvalidModelName',);await expect(invalidAdapter.revokeByGrantId('any-grant-id')).rejects.toThrow(- '不支持的模型: InvalidModelName',+ 'Unsupported model: InvalidModelName',);});});diff --git a/src/libs/langchain/loaders/epub/index.ts b/src/libs/langchain/loaders/epub/index.tsindex e416c7b6ae3..e4a9ac12b7d 100644--- a/src/libs/langchain/loaders/epub/index.ts+++ b/src/libs/langchain/loaders/epub/index.ts@@ -19,6 +19,6 @@ export const EPubLoader = async (content: Uint8Array) => {} catch (e) {throw new Error(`EPubLoader error: ${(e as Error).message}`);} finally {- tempManager.cleanup(); // 确保清理+ tempManager.cleanup(); // Ensure cleanup}};diff --git a/src/libs/mcp/types.ts b/src/libs/mcp/types.tsindex 2a0b07dbda6..715e0e70528 100644--- a/src/libs/mcp/types.ts+++ b/src/libs/mcp/types.ts@@ -102,23 +102,23 @@ export interface MCPToolCallResult {}/**- * MCP 认证配置接口- * 支持第一阶段的手动配置和未来的 OAuth 2.1 自动化流程+ * MCP authentication configuration interface+ * Supports manual configuration in the first stage and future OAuth 2.1 automated flow*/export interface AuthConfig {- // C. 用户授权后获取的【用户令牌】+ // C. User token obtained after user authorizationaccessToken?: string;- // 用户手动粘贴的 Bearer Token- // --- Stage 2 & 3: OAuth 2.1 自动化流程 ---- // A. 静态配置 或 动态注册获取的【客户端凭证】+ // Bearer Token manually pasted by user+ // --- Stage 2 & 3: OAuth 2.1 automated flow ---+ // A. Client credentials obtained through static configuration or dynamic registrationclientId?: string;clientSecret?: string;- refreshToken?: string; // 如果是机密客户端- scope?: string; // 想要申请的权限范围, e.g., "repo user:email"+ refreshToken?: string; // For confidential clients+ scope?: string; // Requested permission scope, e.g., "repo user:email"- // B. 服务器发现机制获取的【授权服务器元数据】+ // B. Authorization server metadata obtained through server discovery mechanismserverMetadata?: {authorization_endpoint?: string;registration_endpoint?: string;@@ -126,11 +126,11 @@ export interface AuthConfig {// ... and other RFC8414 fields};- // --- Stage 1: 手动配置 ---+ // --- Stage 1: Manual configuration ---token?: string;tokenExpiresAt?: number;- // 认证类型- type: 'none' | 'bearer' | 'oauth2'; // accessToken 的过期时间戳+ // Authentication type+ type: 'none' | 'bearer' | 'oauth2'; // Expiration timestamp of accessToken}interface HttpMCPClientParams {@@ -169,17 +169,17 @@ export type MCPErrorType =export interface MCPErrorData {message: string;/**- * 结构化的错误元数据+ * Structured error metadata*/metadata?: {errorLog?: string;/**- * 原始错误信息+ * Original error message*/originalError?: string;/**- * MCP 连接参数+ * MCP connection parameters*/params?: {args?: string[];@@ -188,7 +188,7 @@ export interface MCPErrorData {};/**- * 进程相关信息+ * Process related information*/process?: {exitCode?: number;@@ -196,31 +196,31 @@ export interface MCPErrorData {};/**- * 错误发生的步骤+ * Step where the error occurred*/step?: string;/**- * 时间戳+ * Timestamp*/timestamp?: number;};/**- * 错误类型+ * Error type*/type: MCPErrorType;}/**- * 结构化的 MCP 错误信息+ * Structured MCP error information*/export interface MCPError extends Error {data: MCPErrorData;}/**- * 创建结构化的 MCP 错误+ * Create a structured MCP error*/export function createMCPError(type: MCPErrorData['type'],diff --git a/src/libs/oidc-provider/adapter.ts b/src/libs/oidc-provider/adapter.tsindex 4e5a604b3b1..c09f0d9ea12 100644--- a/src/libs/oidc-provider/adapter.ts+++ b/src/libs/oidc-provider/adapter.ts@@ -12,7 +12,7 @@ import {import debug from 'debug';import { eq, sql } from 'drizzle-orm';-// 创建 adapter 日志命名空间+// Create adapter logging namespaceconst log = debug('lobe-oidc:adapter');/**@@ -41,7 +41,7 @@ class OIDCAdapter {}/**- * 根据模型名称获取对应的数据库表+ * Get the corresponding database table based on model name*/private getTable() {log('Getting table for model: %s', this.name);@@ -60,26 +60,26 @@ class OIDCAdapter {}case 'ClientCredentials': {return oidcAccessTokens;- } // 使用相同的表+ } // Use the same tablecase 'Client': {return oidcClients;}case 'InitialAccessToken': {return oidcAccessTokens;- } // 使用相同的表+ } // Use the same tablecase 'RegistrationAccessToken': {return oidcAccessTokens;- } // 使用相同的表+ } // Use the same tablecase 'Interaction': {return oidcInteractions;}case 'ReplayDetection': {log('ReplayDetection - no persistent storage needed');return null;- } // 不需要持久化+ } // No persistent storage neededcase 'PushedAuthorizationRequest': {return oidcAuthorizationCodes;- } // 使用相同的表+ } // Use the same tablecase 'Grant': {return oidcGrants;}@@ -87,7 +87,7 @@ class OIDCAdapter {return oidcSessions;}default: {- const error = `不支持的模型: ${this.name}`;+ const error = `Unsupported model: ${this.name}`;log('ERROR: %s', error);throw new Error(error);}@@ -95,7 +95,7 @@ class OIDCAdapter {}/**- * 创建模型实例+ * Create or update model instance*/async upsert(id: string, payload: any, expiresIn: number): Promise<void> {log('[%s] upsert called - id: %s, expiresIn: %d', this.name, id, `${expiresIn}s`);@@ -108,7 +108,7 @@ class OIDCAdapter {}if (this.name === 'Client') {- // 客户端模型特殊处理,直接使用传入的数据+ // Special handling for client model, directly use the passed datalog('[Client] Upserting client record');try {await this.db@@ -161,7 +161,7 @@ class OIDCAdapter {return;}- // 对其他模型,保存完整数据和元数据+ // For other models, save complete data and metadataconst expiresAt = expiresIn ? new Date(Date.now() + expiresIn * 1000) : undefined;log('[%s] expiresAt set to: %s', this.name, expiresAt ? expiresAt.toISOString() : 'undefined');@@ -171,7 +171,7 @@ class OIDCAdapter {id,};- // 添加特定字段+ // Add specific fieldsif (payload.accountId) {record.userId = payload.accountId;log('[%s] Setting userId: %s', this.name, payload.accountId);@@ -187,11 +187,11 @@ class OIDCAdapter {}} catch (authError) {log('[%s] Error getting userId from auth context: %O', this.name, authError);- // 如果获取 userId 失败,继续处理而不抛出错误+ // If getting userId fails, continue processing without throwing error}} catch (importError) {log('[%s] Error importing auth module: %O', this.name, importError);- // 如果导入模块失败,继续处理而不抛出错误+ // If importing module fails, continue processing without throwing error}}@@ -238,7 +238,7 @@ class OIDCAdapter {}/**- * 查找模型实例+ * Find model instance*/async find(id: string): Promise<any> {log('[%s] find called - id: %s', this.name, id);@@ -266,7 +266,7 @@ class OIDCAdapter {const model = result[0] as any;- // 客户端模型特殊处理+ // Special handling for client modelif (this.name === 'Client') {log('[Client] Converting client record to expected format');return {@@ -286,13 +286,13 @@ class OIDCAdapter {};}- // 如果记录已过期,返回 undefined+ // If record has expired, return undefinedif (model.expiresAt && new Date() > new Date(model.expiresAt)) {log('[%s] Record expired (expiresAt: %s), returning undefined', this.name, model.expiresAt);return undefined;}- // 如果记录已被消费,检查是否在宽限期内+ // If record has been consumed, check if within grace periodif (model.consumedAt) {// For RefreshToken, allow reuse within grace periodif (this.name === 'RefreshToken') {@@ -339,13 +339,13 @@ class OIDCAdapter {}/**- * 查找模型实例 by userCode (仅用于设备流程)+ * Find model instance by userCode (only for device flow)*/async findByUserCode(userCode: string): Promise<any> {log('[DeviceCode] findByUserCode called - userCode: %s', userCode);if (this.name !== 'DeviceCode') {- const error = 'findByUserCode 只能用于 DeviceCode 模型';+ const error = 'findByUserCode can only be used for DeviceCode model';log('ERROR: %s', error);throw new Error(error);}@@ -367,7 +367,7 @@ class OIDCAdapter {const model = result[0];- // 如果记录已过期或已被消费,返回 undefined+ // If record has expired or been consumed, return undefinedif (model.expiresAt && new Date() > new Date(model.expiresAt)) {log('[DeviceCode] Record expired (expiresAt: %s), returning undefined', model.expiresAt);return undefined;@@ -391,7 +391,7 @@ class OIDCAdapter {}/**- * 查找交互实例 by uid+ * Find interaction instance by uid*/async findByUid(uid: string): Promise<any> {log('[Interaction] findByUid called - uid: %s', uid);@@ -409,10 +409,10 @@ class OIDCAdapter {}const model = results[0] as any;- // 检查过期+ // Check expirationif (model.expiresAt && model.expiresAt < new Date()) {log('[Session] Record found by data.uid but expired: %s', uid);- await this.destroy(model.id); // 仍然使用主键 id 删除+ await this.destroy(model.id); // Still use primary key id for deletionreturn undefined;}@@ -423,14 +423,14 @@ class OIDCAdapter {console.error(`[OIDC Adapter] Error finding Session by uid:`, error);}}- // 复用 find 方法实现+ // Reuse find method implementationlog('[Interaction] Delegating to find() method');return this.find(uid);}/**- * 根据用户 ID 查找会话- * 用于会话预同步+ * Find session by user ID+ * Used for session pre-synchronization*/async findSessionByUserId(userId: string): Promise<any> {log('[%s] findSessionByUserId called - userId: %s', this.name, userId);@@ -470,7 +470,7 @@ class OIDCAdapter {}/**- * 销毁模型实例+ * Destroy model instance*/async destroy(id: string): Promise<void> {log('[%s] destroy called - id: %s', this.name, id);@@ -493,7 +493,7 @@ class OIDCAdapter {}/**- * 标记模型实例为已消费+ * Mark model instance as consumed*/async consume(id: string): Promise<void> {log('[%s] consume called - id: %s', this.name, id);@@ -520,26 +520,26 @@ class OIDCAdapter {}/**- * 根据 grantId 撤销所有相关模型实例+ * Revoke all related model instances by grantId*/async revokeByGrantId(grantId: string): Promise<void> {log('[%s] revokeByGrantId called - grantId: %s', this.name, grantId);- // Grants 本身不需要通过 grantId 来撤销+ // Grants themselves don't need to be revoked by grantIdif (this.name === 'Grant') {log('[Grant] revokeByGrantId skipped for Grant model, as it is the grant itself');return;}- // 提前检查模型名称是否有效,即使后续不直接使用 table+ // Pre-check if model name is valid, even if table is not directly used laterthis.getTable();try {log('[%s] Starting transaction for revokeByGrantId operations', this.name);- // 使用事务删除所有包含grantId的记录,确保原子性+ // Use transaction to delete all records containing grantId, ensuring atomicityawait this.db.transaction(async (tx) => {- // 所有可能包含grantId的表+ // All tables that may contain grantIdconst tables = [oidcAccessTokens,oidcAuthorizationCodes,@@ -568,7 +568,7 @@ class OIDCAdapter {}/**- * 创建适配器工厂+ * Create adapter factory*/static createAdapterFactory = (db: LobeChatDatabase) => {log('Creating adapter factory with database instance');diff --git a/src/libs/oidc-provider/config.ts b/src/libs/oidc-provider/config.tsindex ddee4529628..5e6d8590c42 100644--- a/src/libs/oidc-provider/config.ts+++ b/src/libs/oidc-provider/config.ts@@ -6,51 +6,51 @@ import { appEnv } from '@/envs/app';const marketBaseUrl = new URL(appEnv.MARKET_BASE_URL ?? 'https://market.lobehub.com').origin;/**- * 默认 OIDC 客户端配置+ * Default OIDC client configuration*/export const defaultClients: ClientMetadata[] = [{application_type: 'web',client_id: 'lobehub-desktop',client_name: 'LobeHub Desktop',- // 仅支持授权码流程+ // Only supports authorization code flowgrant_types: ['authorization_code', 'refresh_token'],logo_uri: 'https://hub-apac-1.lobeobjects.space/lobehub-desktop-icon.png',post_logout_redirect_uris: [- // 动态构建 Web 页面回调 URL+ // Dynamically construct web page callback URLurlJoin(appEnv.APP_URL!, '/oauth/logout'),'http://localhost:3210/oauth/logout',],- // 桌面端授权回调 - 改为 Web 页面路径+ // Desktop authorization callback - changed to web page pathredirect_uris: [- // 动态构建 Web 页面回调 URL+ // Dynamically construct web page callback URLurlJoin(appEnv.APP_URL!, '/oidc/callback/desktop'),'http://localhost:3210/oidc/callback/desktop',],- // 支持授权码获取令牌和刷新令牌+ // Supports authorization code for obtaining tokens and refresh tokensresponse_types: ['code'],- // 标记为公共客户端客户端,无密钥+ // Marked as public client with no secrettoken_endpoint_auth_method: 'none',},{- application_type: 'native', // 移动端使用 native 类型+ application_type: 'native', // Mobile uses native typeclient_id: 'lobehub-mobile',client_name: 'LobeHub Mobile',- // 支持授权码流程和刷新令牌+ // Supports authorization code flow and refresh tokengrant_types: ['authorization_code', 'refresh_token'],logo_uri: 'https://hub-apac-1.lobeobjects.space/docs/73f69adfa1b802a0e250f6ff9d62f70b.png',- // 移动端不需要 post_logout_redirect_uris,因为注销通常在应用内处理+ // Mobile does not need post_logout_redirect_uris as logout is typically handled within the apppost_logout_redirect_uris: [],- // 移动端使用自定义 URL Scheme+ // Mobile uses custom URL Schemeredirect_uris: ['com.lobehub.app://auth/callback'],response_types: ['code'],- // 公共客户端,无密钥+ // Public client with no secrettoken_endpoint_auth_method: 'none',},@@ -74,21 +74,21 @@ export const defaultClients: ClientMetadata[] = [];/**- * OIDC Scopes 定义+ * OIDC Scopes definition*/export const defaultScopes = ['openid','profile','email',- 'offline_access', // 允许获取 refresh_token+ 'offline_access', // Allows obtaining refresh_token];/**- * OIDC Claims 定义+ * OIDC Claims definition*/export const defaultClaims = {email: ['email', 'email_verified'],openid: ['sub'],- // subject (用户唯一标识)+ // subject (unique user identifier)profile: ['name', 'picture'],};diff --git a/src/libs/trpc/lambda/middleware/oidcAuth.ts b/src/libs/trpc/lambda/middleware/oidcAuth.tsindex 3e5241b82bf..3fa1259cb7e 100644--- a/src/libs/trpc/lambda/middleware/oidcAuth.ts+++ b/src/libs/trpc/lambda/middleware/oidcAuth.ts@@ -3,7 +3,7 @@ import { trpc } from '../init';export const oidcAuth = trpc.middleware(async (opts) => {const { ctx, next } = opts;- // 检查 OIDC 认证+ // Check OIDC authenticationif (ctx.oidcAuth) {return next({ctx: { oidcAuth: ctx.oidcAuth, userId: ctx.oidcAuth.sub },