@lobehub/lobehub 2.0.0-next.312 → 2.0.0-next.313

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/apps/desktop/src/main/controllers/AuthCtr.ts +75 -7
  3. package/changelog/v1.json +9 -0
  4. package/docs/usage/providers/internlm.mdx +2 -2
  5. package/docs/usage/providers/internlm.zh-CN.mdx +3 -3
  6. package/locales/en-US/error.json +10 -1
  7. package/locales/en-US/subscription.json +1 -1
  8. package/locales/zh-CN/desktop-onboarding.json +5 -0
  9. package/locales/zh-CN/error.json +10 -1
  10. package/locales/zh-CN/subscription.json +1 -1
  11. package/package.json +1 -1
  12. package/packages/agent-runtime/src/agents/GeneralChatAgent.ts +14 -2
  13. package/packages/agent-runtime/src/agents/__tests__/GeneralChatAgent.test.ts +275 -1
  14. package/packages/builtin-tool-cloud-sandbox/package.json +1 -0
  15. package/packages/builtin-tool-cloud-sandbox/src/ExecutionRuntime/index.ts +105 -134
  16. package/packages/builtin-tool-cloud-sandbox/src/executor/index.ts +254 -0
  17. package/packages/builtin-tool-cloud-sandbox/src/index.ts +1 -0
  18. package/packages/builtin-tool-cloud-sandbox/src/types/api.ts +22 -0
  19. package/packages/builtin-tool-cloud-sandbox/src/types/index.ts +4 -0
  20. package/packages/builtin-tool-cloud-sandbox/src/types/params.ts +85 -0
  21. package/packages/builtin-tool-cloud-sandbox/src/types/service.ts +48 -0
  22. package/packages/builtin-tool-cloud-sandbox/src/{types.ts → types/state.ts} +0 -23
  23. package/packages/builtin-tool-memory/src/manifest.ts +5 -5
  24. package/packages/editor-runtime/src/__tests__/EditorRuntime.real.test.ts +1 -1
  25. package/packages/editor-runtime/src/__tests__/EditorRuntime.test.ts +1 -1
  26. package/packages/electron-client-ipc/src/events/index.ts +5 -1
  27. package/packages/electron-client-ipc/src/events/remoteServer.ts +23 -0
  28. package/packages/memory-user-memory/src/schemas/index.ts +0 -1
  29. package/packages/model-bank/src/modelProviders/internlm.ts +1 -1
  30. package/packages/model-runtime/src/core/RouterRuntime/createRuntime.ts +5 -15
  31. package/packages/model-runtime/src/providers/internlm/index.test.ts +15 -15
  32. package/packages/model-runtime/src/providers/internlm/index.ts +1 -1
  33. package/packages/types/src/tool/intervention.ts +4 -2
  34. package/packages/types/src/user/preference.ts +1 -0
  35. package/src/app/[variants]/(desktop)/desktop-onboarding/features/LoginStep.tsx +84 -26
  36. package/src/app/[variants]/(main)/_layout/DesktopAutoOidcOnFirstOpen.tsx +4 -0
  37. package/src/business/server/user.ts +4 -0
  38. package/src/features/Conversation/Messages/Task/Actions/index.tsx +0 -2
  39. package/src/features/Conversation/Messages/Task/index.tsx +1 -1
  40. package/src/features/Conversation/Messages/Tasks/shared/ProcessingState.tsx +0 -2
  41. package/src/features/NavPanel/components/NavPanelDraggable.tsx +0 -14
  42. package/src/features/ResourceManager/components/Explorer/ItemDropdown/useFileItemDropdown.tsx +4 -3
  43. package/src/features/SharePopover/index.tsx +5 -3
  44. package/src/hooks/useAppOrigin.ts +16 -0
  45. package/src/layout/GlobalProvider/useUserStateRedirect.ts +37 -24
  46. package/src/libs/trusted-client/index.ts +2 -5
  47. package/src/locales/default/desktop-onboarding.ts +5 -0
  48. package/src/locales/default/error.ts +11 -0
  49. package/src/locales/default/subscription.ts +1 -1
  50. package/src/server/modules/AgentRuntime/RuntimeExecutors.ts +2 -0
  51. package/src/server/routers/lambda/user.ts +24 -10
  52. package/src/server/services/agentRuntime/AgentRuntimeService.test.ts +3 -0
  53. package/src/server/services/agentRuntime/AgentRuntimeService.ts +8 -5
  54. package/src/server/services/agentRuntime/types.ts +7 -0
  55. package/src/server/services/aiAgent/__tests__/execGroupSubAgentTask.test.ts +3 -0
  56. package/src/server/services/aiAgent/index.ts +10 -4
  57. package/src/server/services/market/index.ts +7 -0
  58. package/src/server/services/sandbox/index.ts +120 -0
  59. package/src/server/services/toolExecution/builtin.ts +12 -18
  60. package/src/server/services/toolExecution/index.ts +1 -1
  61. package/src/server/services/toolExecution/serverRuntimes/cloudSandbox.ts +31 -0
  62. package/src/server/services/toolExecution/serverRuntimes/index.ts +55 -0
  63. package/src/server/services/toolExecution/serverRuntimes/types.ts +14 -0
  64. package/src/server/services/toolExecution/serverRuntimes/webBrowsing.ts +20 -0
  65. package/src/server/services/toolExecution/types.ts +2 -0
  66. package/src/services/{codeInterpreter.ts → cloudSandbox.ts} +3 -3
  67. package/src/services/electron/remoteServer.ts +8 -0
  68. package/src/store/chat/agents/GroupOrchestration/__tests__/batch-exec-async-tasks.test.ts +626 -0
  69. package/src/store/chat/agents/GroupOrchestration/createGroupOrchestrationExecutors.ts +294 -0
  70. package/src/store/chat/slices/plugin/action.test.ts +0 -48
  71. package/src/store/chat/slices/plugin/actions/pluginTypes.ts +0 -131
  72. package/src/store/tool/slices/builtin/executors/index.ts +2 -0
  73. package/src/store/user/slices/settings/selectors/toolIntervention.test.ts +143 -0
  74. package/src/store/user/slices/settings/selectors/toolIntervention.ts +11 -2
  75. package/packages/memory-user-memory/src/schemas/jsonSchemas.ts +0 -37
@@ -0,0 +1,120 @@
1
+ import { type CodeInterpreterToolName } from '@lobehub/market-sdk';
2
+ import {
3
+ type ISandboxService,
4
+ type SandboxCallToolResult,
5
+ type SandboxExportFileResult,
6
+ } from '@lobechat/builtin-tool-cloud-sandbox';
7
+ import debug from 'debug';
8
+
9
+ import { MarketService } from '@/server/services/market';
10
+
11
+ const log = debug('lobe-server:sandbox-service');
12
+
13
+ export interface ServerSandboxServiceOptions {
14
+ marketService: MarketService;
15
+ topicId: string;
16
+ userId: string;
17
+ }
18
+
19
+ /**
20
+ * Server-side Sandbox Service
21
+ *
22
+ * This service implements ISandboxService for server-side execution.
23
+ * Context (topicId, userId) is bound at construction time.
24
+ * It uses MarketService to call sandbox tools.
25
+ *
26
+ * Usage:
27
+ * - Used by BuiltinToolsExecutor when executing CloudSandbox tools on server
28
+ * - MarketService handles authentication via trustedClientToken
29
+ */
30
+ export class ServerSandboxService implements ISandboxService {
31
+ private marketService: MarketService;
32
+ private topicId: string;
33
+ private userId: string;
34
+
35
+ constructor(options: ServerSandboxServiceOptions) {
36
+ this.marketService = options.marketService;
37
+ this.topicId = options.topicId;
38
+ this.userId = options.userId;
39
+ }
40
+
41
+ /**
42
+ * Call a sandbox tool via MarketService
43
+ */
44
+ async callTool(toolName: string, params: Record<string, any>): Promise<SandboxCallToolResult> {
45
+ log('Calling sandbox tool: %s with params: %O, topicId: %s', toolName, params, this.topicId);
46
+
47
+ try {
48
+ const response = await this.marketService.getSDK().plugins.runBuildInTool(
49
+ toolName as CodeInterpreterToolName,
50
+ params as any,
51
+ { topicId: this.topicId, userId: this.userId },
52
+ );
53
+
54
+ log('Sandbox tool %s response: %O', toolName, response);
55
+
56
+ if (!response.success) {
57
+ return {
58
+ error: {
59
+ message: response.error?.message || 'Unknown error',
60
+ name: response.error?.code,
61
+ },
62
+ result: null,
63
+ sessionExpiredAndRecreated: false,
64
+ success: false,
65
+ };
66
+ }
67
+
68
+ return {
69
+ result: response.data?.result,
70
+ sessionExpiredAndRecreated: response.data?.sessionExpiredAndRecreated || false,
71
+ success: true,
72
+ };
73
+ } catch (error) {
74
+ log('Error calling sandbox tool %s: %O', toolName, error);
75
+
76
+ return {
77
+ error: {
78
+ message: (error as Error).message,
79
+ name: (error as Error).name,
80
+ },
81
+ result: null,
82
+ sessionExpiredAndRecreated: false,
83
+ success: false,
84
+ };
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Export and upload a file from sandbox
90
+ *
91
+ * Note: This is a simplified version for server-side use.
92
+ * The full implementation with S3 upload is in the tRPC router.
93
+ */
94
+ async exportAndUploadFile(path: string, filename: string): Promise<SandboxExportFileResult> {
95
+ log('Exporting file: %s from path: %s, topicId: %s', filename, path, this.topicId);
96
+
97
+ // For server-side, we need to call the exportFile tool
98
+ // The full S3 upload logic should be handled separately
99
+ // This is a basic implementation that can be extended
100
+
101
+ try {
102
+ return {
103
+ error: {
104
+ message:
105
+ 'Server-side file export not fully implemented. Use tRPC endpoint for file exports.',
106
+ },
107
+ filename,
108
+ success: false,
109
+ };
110
+ } catch (error) {
111
+ log('Error exporting file: %O', error);
112
+
113
+ return {
114
+ error: { message: (error as Error).message },
115
+ filename,
116
+ success: false,
117
+ };
118
+ }
119
+ }
120
+ }
@@ -1,28 +1,26 @@
1
- import { WebBrowsingManifest } from '@lobechat/builtin-tool-web-browsing';
2
- import { WebBrowsingExecutionRuntime } from '@lobechat/builtin-tool-web-browsing/executionRuntime';
3
1
  import { type LobeChatDatabase } from '@lobechat/database';
4
2
  import { type ChatToolPayload } from '@lobechat/types';
5
3
  import { safeParseJSON } from '@lobechat/utils';
6
4
  import debug from 'debug';
7
5
 
8
6
  import { MarketService } from '@/server/services/market';
9
- import { SearchService } from '@/server/services/search';
10
7
 
11
- import { type IToolExecutor, type ToolExecutionResult } from './types';
8
+ import { getServerRuntime, hasServerRuntime } from './serverRuntimes';
9
+ import { type IToolExecutor, type ToolExecutionContext, type ToolExecutionResult } from './types';
12
10
 
13
11
  const log = debug('lobe-server:builtin-tools-executor');
14
12
 
15
- const BuiltinToolServerRuntimes: Record<string, any> = {
16
- [WebBrowsingManifest.identifier]: WebBrowsingExecutionRuntime,
17
- };
18
-
19
13
  export class BuiltinToolsExecutor implements IToolExecutor {
20
14
  private marketService: MarketService;
21
15
 
22
16
  constructor(db: LobeChatDatabase, userId: string) {
23
17
  this.marketService = new MarketService({ userInfo: { userId } });
24
18
  }
25
- async execute(payload: ChatToolPayload): Promise<ToolExecutionResult> {
19
+
20
+ async execute(
21
+ payload: ChatToolPayload,
22
+ context: ToolExecutionContext,
23
+ ): Promise<ToolExecutionResult> {
26
24
  const { identifier, apiName, arguments: argsStr, source } = payload;
27
25
  const args = safeParseJSON(argsStr) || {};
28
26
 
@@ -43,19 +41,15 @@ export class BuiltinToolsExecutor implements IToolExecutor {
43
41
  });
44
42
  }
45
43
 
46
- // Default: original builtin runtime logic
47
- const ServerRuntime = BuiltinToolServerRuntimes[identifier];
48
-
49
- if (!ServerRuntime) {
44
+ // Use server runtime registry (handles both pre-instantiated and per-request runtimes)
45
+ if (!hasServerRuntime(identifier)) {
50
46
  throw new Error(`Builtin tool "${identifier}" is not implemented`);
51
47
  }
52
48
 
53
- const runtime = new ServerRuntime({
54
- searchService: new SearchService(),
55
- });
49
+ const runtime = getServerRuntime(identifier, context);
56
50
 
57
51
  if (!runtime[apiName]) {
58
- throw new Error(`Builtin tool ${identifier} 's ${apiName} is not implemented`);
52
+ throw new Error(`Builtin tool ${identifier}'s ${apiName} is not implemented`);
59
53
  }
60
54
 
61
55
  try {
@@ -64,7 +58,7 @@ export class BuiltinToolsExecutor implements IToolExecutor {
64
58
  const error = e as Error;
65
59
  console.error('Error executing builtin tool %s:%s: %O', identifier, apiName, error);
66
60
 
67
- return { content: error.message, error: error, success: false };
61
+ return { content: error.message, error, success: false };
68
62
  }
69
63
  }
70
64
  }
@@ -47,7 +47,7 @@ export class ToolExecutionService {
47
47
  let data: ToolExecutionResult;
48
48
  switch (typeStr) {
49
49
  case 'builtin': {
50
- data = await this.builtinToolsExecutor.execute(payload);
50
+ data = await this.builtinToolsExecutor.execute(payload, context);
51
51
  break;
52
52
  }
53
53
 
@@ -0,0 +1,31 @@
1
+ import {
2
+ CloudSandboxExecutionRuntime,
3
+ CloudSandboxIdentifier,
4
+ } from '@lobechat/builtin-tool-cloud-sandbox';
5
+
6
+ import { MarketService } from '@/server/services/market';
7
+ import { ServerSandboxService } from '@/server/services/sandbox';
8
+
9
+ import { type ServerRuntimeRegistration } from './types';
10
+
11
+ /**
12
+ * CloudSandbox Server Runtime
13
+ * Per-request runtime (needs topicId, userId)
14
+ */
15
+ export const cloudSandboxRuntime: ServerRuntimeRegistration = {
16
+ factory: (context) => {
17
+ if (!context.userId || !context.topicId) {
18
+ throw new Error('userId and topicId are required for Cloud Sandbox execution');
19
+ }
20
+
21
+ const marketService = new MarketService({ userInfo: { userId: context.userId } });
22
+ const sandboxService = new ServerSandboxService({
23
+ marketService,
24
+ topicId: context.topicId,
25
+ userId: context.userId,
26
+ });
27
+
28
+ return new CloudSandboxExecutionRuntime(sandboxService);
29
+ },
30
+ identifier: CloudSandboxIdentifier,
31
+ };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Server Runtime Registry
3
+ *
4
+ * Central registry for all builtin tool server runtimes.
5
+ * Uses factory functions to support both:
6
+ * - Pre-instantiated runtimes (e.g., WebBrowsing - no per-request context needed)
7
+ * - Per-request runtimes (e.g., CloudSandbox - needs topicId, userId)
8
+ */
9
+ import { type ToolExecutionContext } from '../types';
10
+ import { cloudSandboxRuntime } from './cloudSandbox';
11
+ import { type ServerRuntimeFactory, type ServerRuntimeRegistration } from './types';
12
+ import { webBrowsingRuntime } from './webBrowsing';
13
+
14
+ /**
15
+ * Registry of server runtime factories by identifier
16
+ */
17
+ const serverRuntimeFactories = new Map<string, ServerRuntimeFactory>();
18
+
19
+ /**
20
+ * Register server runtimes
21
+ */
22
+ const registerRuntimes = (runtimes: ServerRuntimeRegistration[]) => {
23
+ for (const runtime of runtimes) {
24
+ serverRuntimeFactories.set(runtime.identifier, runtime.factory);
25
+ }
26
+ };
27
+
28
+ // Register all server runtimes
29
+ registerRuntimes([webBrowsingRuntime, cloudSandboxRuntime]);
30
+
31
+ // ==================== Registry API ====================
32
+
33
+ /**
34
+ * Get a server runtime by identifier
35
+ * @param identifier - The tool identifier
36
+ * @param context - Execution context (required for per-request runtimes)
37
+ */
38
+ export const getServerRuntime = (identifier: string, context: ToolExecutionContext): any => {
39
+ const factory = serverRuntimeFactories.get(identifier);
40
+ return factory?.(context);
41
+ };
42
+
43
+ /**
44
+ * Check if a server runtime exists for the given identifier
45
+ */
46
+ export const hasServerRuntime = (identifier: string): boolean => {
47
+ return serverRuntimeFactories.has(identifier);
48
+ };
49
+
50
+ /**
51
+ * Get all registered server runtime identifiers
52
+ */
53
+ export const getServerRuntimeIdentifiers = (): string[] => {
54
+ return Array.from(serverRuntimeFactories.keys());
55
+ };
@@ -0,0 +1,14 @@
1
+ import { type ToolExecutionContext } from '../types';
2
+
3
+ /**
4
+ * Factory function type for creating server runtimes
5
+ */
6
+ export type ServerRuntimeFactory = (context: ToolExecutionContext) => any;
7
+
8
+ /**
9
+ * Server runtime registration object
10
+ */
11
+ export interface ServerRuntimeRegistration {
12
+ factory: ServerRuntimeFactory;
13
+ identifier: string;
14
+ }
@@ -0,0 +1,20 @@
1
+ import { WebBrowsingManifest } from '@lobechat/builtin-tool-web-browsing';
2
+ import { WebBrowsingExecutionRuntime } from '@lobechat/builtin-tool-web-browsing/executionRuntime';
3
+
4
+ import { SearchService } from '@/server/services/search';
5
+
6
+ import { type ServerRuntimeRegistration } from './types';
7
+
8
+ // Pre-instantiated (no per-request context needed)
9
+ const runtime = new WebBrowsingExecutionRuntime({
10
+ searchService: new SearchService(),
11
+ });
12
+
13
+ /**
14
+ * WebBrowsing Server Runtime
15
+ * Pre-instantiated runtime (no per-request context needed)
16
+ */
17
+ export const webBrowsingRuntime: ServerRuntimeRegistration = {
18
+ factory: () => runtime,
19
+ identifier: WebBrowsingManifest.identifier,
20
+ };
@@ -6,6 +6,8 @@ export interface ToolExecutionContext {
6
6
  /** Server database for LobeHub Skills execution */
7
7
  serverDB?: LobeChatDatabase;
8
8
  toolManifestMap: Record<string, LobeToolManifest>;
9
+ /** Topic ID for sandbox session management */
10
+ topicId?: string;
9
11
  userId?: string;
10
12
  }
11
13
 
@@ -6,9 +6,9 @@ import type {
6
6
  ExportAndUploadFileResult,
7
7
  } from '@/server/routers/tools/market';
8
8
 
9
- class CodeInterpreterService {
9
+ class CloudSandboxService {
10
10
  /**
11
- * Call a cloud code interpreter tool
11
+ * Call a cloud sandbox tool
12
12
  * @param toolName - The name of the tool to call (e.g., 'runCommand', 'writeLocalFile')
13
13
  * @param params - The parameters for the tool
14
14
  * @param context - Session context containing userId and topicId for isolation
@@ -51,4 +51,4 @@ class CodeInterpreterService {
51
51
  }
52
52
  }
53
53
 
54
- export const codeInterpreterService = new CodeInterpreterService();
54
+ export const cloudSandboxService = new CloudSandboxService();
@@ -1,4 +1,5 @@
1
1
  import { type DataSyncConfig, type MarketAuthorizationParams } from '@lobechat/electron-client-ipc';
2
+
2
3
  import { ensureElectronIpc } from '@/utils/electron/ipc';
3
4
 
4
5
  class RemoteServerService {
@@ -36,6 +37,13 @@ class RemoteServerService {
36
37
  requestMarketAuthorization = async (params: MarketAuthorizationParams) => {
37
38
  return ensureElectronIpc().auth.requestMarketAuthorization(params);
38
39
  };
40
+
41
+ /**
42
+ * Cancel authorization
43
+ */
44
+ cancelAuthorization = async () => {
45
+ return ensureElectronIpc().auth.cancelAuthorization();
46
+ };
39
47
  }
40
48
 
41
49
  export const remoteServerService = new RemoteServerService();