π€― 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
π fix: enable executor=client tools for desktop Electron callers (#13790)
Arvin Xuf0a811ef835f
diff --git a/packages/types/src/agentExecution/index.ts b/packages/types/src/agentExecution/index.tsindex 661092b246e..8e518b4679d 100644--- a/packages/types/src/agentExecution/index.ts+++ b/packages/types/src/agentExecution/index.ts@@ -28,6 +28,13 @@ export interface ExecAgentParams {appContext?: ExecAgentAppContext;/** Whether to auto-start execution after creating operation (default: true) */autoStart?: boolean;+ /**+ * Runtime of the client initiating this request. Used by the server to+ * enable `executor: 'client'` tools (e.g. local-system) when the caller+ * is a desktop Electron client that will receive `tool_execute` events+ * over the same Agent Gateway WebSocket.+ */+ clientRuntime?: 'desktop' | 'web';/** Explicit device ID to bind to the topic and activate for this run */deviceId?: string;/** Optional existing message IDs to include in context */diff --git a/src/server/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts b/src/server/modules/Mecha/AgentToolsEngine/__tests__/index.test.tsindex 3eed3dbcddd..7e11d97d4df 100644--- a/src/server/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts+++ b/src/server/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts@@ -520,4 +520,71 @@ describe('createServerAgentToolsEngine', () => {expect(result.enabledToolIds).not.toContain(RemoteDeviceManifest.identifier);});});++ describe('clientRuntime === "desktop" (Phase 6.4)', () => {+ it('enables LocalSystem when caller is desktop, regardless of device-proxy config', () => {+ // The Agent Gateway WS used to push `tool_execute` is orthogonal to+ // the legacy device-proxy. A desktop Electron caller is already the+ // execution target β no device-proxy prerequisite required.+ const context = createMockContext();+ const engine = createServerAgentToolsEngine(context, {+ agentConfig: { plugins: [LocalSystemManifest.identifier] },+ clientRuntime: 'desktop',+ model: 'gpt-4',+ provider: 'openai',+ });++ const result = engine.generateToolsDetailed({+ toolIds: [LocalSystemManifest.identifier],+ model: 'gpt-4',+ provider: 'openai',+ });++ expect(result.enabledToolIds).toContain(LocalSystemManifest.identifier);+ });++ it('respects agent-level runtimeMode opt-out for desktop callers', () => {+ // User has configured the agent to NOT use local runtime on desktop.+ // Even though the caller is a desktop client, local-system stays off.+ const context = createMockContext();+ const engine = createServerAgentToolsEngine(context, {+ agentConfig: {+ chatConfig: {+ runtimeEnv: { runtimeMode: { desktop: 'none' } },+ },+ plugins: [LocalSystemManifest.identifier],+ },+ clientRuntime: 'desktop',+ model: 'gpt-4',+ provider: 'openai',+ });++ const result = engine.generateToolsDetailed({+ toolIds: [LocalSystemManifest.identifier],+ model: 'gpt-4',+ provider: 'openai',+ });++ expect(result.enabledToolIds).not.toContain(LocalSystemManifest.identifier);+ });++ it('does not enable LocalSystem for web callers even when gateway is configured', () => {+ const context = createMockContext();+ const engine = createServerAgentToolsEngine(context, {+ agentConfig: { plugins: [LocalSystemManifest.identifier] },+ clientRuntime: 'web',+ deviceContext: { gatewayConfigured: true },+ model: 'gpt-4',+ provider: 'openai',+ });++ const result = engine.generateToolsDetailed({+ toolIds: [LocalSystemManifest.identifier],+ model: 'gpt-4',+ provider: 'openai',+ });++ expect(result.enabledToolIds).not.toContain(LocalSystemManifest.identifier);+ });+ });});diff --git a/src/server/modules/Mecha/AgentToolsEngine/index.ts b/src/server/modules/Mecha/AgentToolsEngine/index.tsindex 05ff9d983b9..2738dd2c0dd 100644--- a/src/server/modules/Mecha/AgentToolsEngine/index.ts+++ b/src/server/modules/Mecha/AgentToolsEngine/index.ts@@ -20,6 +20,7 @@ import { WebBrowsingManifest } from '@lobechat/builtin-tool-web-browsing';import { alwaysOnToolIds, builtinTools, defaultToolIds } from '@lobechat/builtin-tools';import { createEnableChecker, type LobeToolManifest } from '@lobechat/context-engine';import { ToolsEngine } from '@lobechat/context-engine';+import { type RuntimeEnvMode, type RuntimePlatform } from '@lobechat/types';import debug from 'debug';import {@@ -94,6 +95,7 @@ export const createServerAgentToolsEngine = (const {additionalManifests,agentConfig,+ clientRuntime,deviceContext,globalMemoryEnabled = false,hasAgentDocuments = false,@@ -102,24 +104,49 @@ export const createServerAgentToolsEngine = (model,provider,} = params;- const searchMode = agentConfig.chatConfig?.searchMode ?? 'auto';- const isSearchEnabled = searchMode !== 'off';- // Determine runtime mode based on platform- const isDesktopClient = !!deviceContext?.gatewayConfigured;- const platform = isDesktopClient ? 'desktop' : 'web';- const runtimeMode =+ // βββ Tool-dispatch capability flags βββ+ //+ // Two orthogonal signals control whether client-side tools can run.+ //+ // 1. `hasClientExecutor` β the caller itself is an Electron desktop+ // client and can receive `tool_execute` events over the Agent+ // Gateway WebSocket (Phase 6.4).+ // 2. `hasDeviceProxy` β the server has a device-proxy configured that+ // can tunnel commands to a *separately registered* desktop device+ // (legacy Remote Device flow).+ //+ // Either, both, or neither can be true independently.+ const hasClientExecutor = clientRuntime === 'desktop';+ const hasDeviceProxy = !!deviceContext?.gatewayConfigured;++ // βββ Platform / runtime mode βββ+ //+ // `platform` is a property of the caller, not of the server. Prefer the+ // explicit `clientRuntime` signal; fall back to treating a server with+ // a configured device-proxy as desktop for callers that don't yet send+ // `clientRuntime` (backwards compat).+ const platform: RuntimePlatform = clientRuntime ?? (hasDeviceProxy ? 'desktop' : 'web');++ // User-configured runtime mode for the current platform, with a+ // platform-appropriate default when unset.+ const runtimeMode: RuntimeEnvMode =agentConfig.chatConfig?.runtimeEnv?.runtimeMode?.[platform] ??- (isDesktopClient ? 'local' : 'none');+ (platform === 'desktop' ? 'local' : 'none');++ const searchMode = agentConfig.chatConfig?.searchMode ?? 'auto';+ const isSearchEnabled = searchMode !== 'off';log(- 'Creating agent tools engine for model=%s, provider=%s, searchMode=%s, runtimeMode=%s, additionalManifests=%d, deviceGateway=%s',+ 'Creating agent tools engine model=%s provider=%s searchMode=%s platform=%s runtimeMode=%s additionalManifests=%d hasClientExecutor=%s hasDeviceProxy=%s',model,provider,searchMode,+ platform,runtimeMode,additionalManifests?.length ?? 0,- !!deviceContext?.gatewayConfigured,+ hasClientExecutor,+ hasDeviceProxy,);return createServerToolsEngine(context, {@@ -138,16 +165,23 @@ export const createServerAgentToolsEngine = (// System-level rules (may override user selection for specific tools)[CloudSandboxManifest.identifier]: runtimeMode === 'cloud',[KnowledgeBaseManifest.identifier]: hasEnabledKnowledgeBases,+ // Local-system: user must have opted into local runtime on this+ // platform (`runtimeMode === 'local'`), AND one execution channel+ // must exist:+ // - `hasClientExecutor` β Phase 6.4 dispatch over the Agent Gateway+ // WS that this request is already riding on; no extra server-side+ // prerequisite needed;+ // - legacy device-proxy with an online & auto-activated device.[LocalSystemManifest.identifier]:runtimeMode === 'local' &&- !!deviceContext?.gatewayConfigured &&- !!deviceContext?.deviceOnline &&- !!deviceContext?.autoActivated,+ (hasClientExecutor ||+ (hasDeviceProxy && !!deviceContext?.deviceOnline && !!deviceContext?.autoActivated)),[MemoryManifest.identifier]: globalMemoryEnabled,// Only auto-enable in bot conversations; otherwise let user's plugin selection take effect...(isBotConversation && { [MessageManifest.identifier]: true }),- [RemoteDeviceManifest.identifier]:- !!deviceContext?.gatewayConfigured && !deviceContext?.autoActivated,+ // Remote-device proxy: shown only when the server has a proxy but+ // no specific device is auto-activated yet (user must pick).+ [RemoteDeviceManifest.identifier]: hasDeviceProxy && !deviceContext?.autoActivated,[AgentDocumentsManifest.identifier]: hasAgentDocuments,[WebBrowsingManifest.identifier]: isSearchEnabled,},diff --git a/src/server/modules/Mecha/AgentToolsEngine/types.ts b/src/server/modules/Mecha/AgentToolsEngine/types.tsindex c9afb29c358..44843c90a8c 100644--- a/src/server/modules/Mecha/AgentToolsEngine/types.ts+++ b/src/server/modules/Mecha/AgentToolsEngine/types.ts@@ -44,6 +44,13 @@ export interface ServerCreateAgentToolsEngineParams {/** Plugin IDs enabled for this agent */plugins?: string[];};+ /**+ * Runtime of the client initiating this request. When `'desktop'`, the+ * caller itself is an Electron client connected via the Agent Gateway WS,+ * so tools with `executor: 'client'` (e.g. local-system, stdio MCP) can be+ * dispatched back to it via `tool_execute` β no remote-device proxy needed.+ */+ clientRuntime?: 'desktop' | 'web';/** Device gateway context for remote tool calling */deviceContext?: {/** When true, a device has been auto-activated β Remote Device tool is unnecessary */diff --git a/src/server/routers/lambda/aiAgent.ts b/src/server/routers/lambda/aiAgent.tsindex 9b89b5478eb..c815acee087 100644--- a/src/server/routers/lambda/aiAgent.ts+++ b/src/server/routers/lambda/aiAgent.ts@@ -91,6 +91,12 @@ const ExecAgentSchema = z.optional(),/** Whether to auto-start execution after creating operation */autoStart: z.boolean().optional().default(true),+ /**+ * Runtime of the client initiating this request.+ * 'desktop' enables `executor: 'client'` tools (local-system, stdio MCP)+ * to be dispatched over the Agent Gateway WS.+ */+ clientRuntime: z.enum(['desktop', 'web']).optional(),/** Explicit device ID to bind to the topic and activate for this run */deviceId: z.string().optional(),/** Optional existing message IDs to include in context */@@ -530,6 +536,7 @@ export const aiAgentRouter = router({prompt,appContext,autoStart = true,+ clientRuntime,deviceId,existingMessageIds = [],fileIds,@@ -543,6 +550,7 @@ export const aiAgentRouter = router({agentId,appContext,autoStart,+ clientRuntime,deviceId,existingMessageIds,fileIds,diff --git a/src/server/services/aiAgent/__tests__/execAgent.deviceToolPipeline.test.ts b/src/server/services/aiAgent/__tests__/execAgent.deviceToolPipeline.test.tsindex d1f429cb7ea..5f2733f0f17 100644--- a/src/server/services/aiAgent/__tests__/execAgent.deviceToolPipeline.test.ts+++ b/src/server/services/aiAgent/__tests__/execAgent.deviceToolPipeline.test.ts@@ -228,6 +228,44 @@ describe('AiAgentService.execAgent - device tool pipeline (LOBE-5636)', () => {});});+ describe('clientRuntime forwarded to createServerAgentToolsEngine', () => {+ it('forwards clientRuntime="desktop" so the engine enables local-system for Electron callers', async () => {+ mockGetAgentConfig.mockResolvedValue(createBaseAgentConfig());++ await service.execAgent({+ agentId: 'agent-1',+ clientRuntime: 'desktop',+ prompt: 'Hello',+ });++ expect(mockCreateServerAgentToolsEngine).toHaveBeenCalledTimes(1);+ const params = mockCreateServerAgentToolsEngine.mock.calls[0][1];+ expect(params.clientRuntime).toBe('desktop');+ });++ it('forwards clientRuntime="web" verbatim', async () => {+ mockGetAgentConfig.mockResolvedValue(createBaseAgentConfig());++ await service.execAgent({+ agentId: 'agent-1',+ clientRuntime: 'web',+ prompt: 'Hello',+ });++ const params = mockCreateServerAgentToolsEngine.mock.calls[0][1];+ expect(params.clientRuntime).toBe('web');+ });++ it('omits clientRuntime when the caller does not specify one', async () => {+ mockGetAgentConfig.mockResolvedValue(createBaseAgentConfig());++ await service.execAgent({ agentId: 'agent-1', prompt: 'Hello' });++ const params = mockCreateServerAgentToolsEngine.mock.calls[0][1];+ expect(params.clientRuntime).toBeUndefined();+ });+ });+describe('RemoteDevice systemRole override', () => {it('should override RemoteDevice systemRole with dynamic prompt when enabled by ToolsEngine', async () => {const { deviceProxy } = await import('@/server/services/toolExecution/deviceProxy');diff --git a/src/server/services/aiAgent/index.ts b/src/server/services/aiAgent/index.tsindex 199b62a2dee..267d90f4a53 100644--- a/src/server/services/aiAgent/index.ts+++ b/src/server/services/aiAgent/index.ts@@ -223,6 +223,7 @@ export class AiAgentService {appContext,autoStart = true,botContext,+ clientRuntime,deviceId: requestedDeviceId,botPlatformContext,discordContext,@@ -565,6 +566,7 @@ export class AiAgentService {chatConfig: agentConfig.chatConfig ?? undefined,plugins: agentPlugins,},+ clientRuntime,deviceContext: gatewayConfigured? {autoActivated: activeDeviceId ? true : undefined,