Skip to content

🀯 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.

:bug: fix: forward gateway approval mode to server runtime (#16422)

Rylan Caia40ceb4d0e95
diff --git a/src/services/aiAgent.ts b/src/services/aiAgent.ts
index ae0cd618ff3..8e1073dbbef 100644
--- a/src/services/aiAgent.ts
+++ b/src/services/aiAgent.ts
@@ -1,4 +1,4 @@
-import type { ExecAgentAppContext, ExecAgentResult } from '@lobechat/types';
+import type { ExecAgentAppContext, ExecAgentResult, UserInterventionConfig } from '@lobechat/types';
import { lambdaClient } from '@/libs/trpc/client';
@@ -44,6 +44,7 @@ export interface ExecAgentTaskParams {
* `agent_operations.trigger` column reflects the real source.
*/
trigger?: string;
+ userInterventionConfig?: UserInterventionConfig;
}
/**
diff --git a/src/store/chat/slices/agentRun/actions/__tests__/gateway.test.ts b/src/store/chat/slices/agentRun/actions/__tests__/gateway.test.ts
index faf2f1286fb..3fd4b8b52af 100644
--- a/src/store/chat/slices/agentRun/actions/__tests__/gateway.test.ts
+++ b/src/store/chat/slices/agentRun/actions/__tests__/gateway.test.ts
@@ -32,6 +32,10 @@ vi.mock('@/services/topic', () => ({
const mockUserDefaultConfig = vi.hoisted(() => ({
disableGatewayMode: undefined as boolean | undefined,
}));
+const mockToolInterventionConfig = vi.hoisted(() => ({
+ allowList: [] as string[],
+ approvalMode: 'manual' as 'allow-list' | 'auto-run' | 'manual',
+}));
vi.mock('@/store/user', () => ({
useUserStore: {
@@ -45,6 +49,10 @@ vi.mock('@/store/user/selectors', () => ({
chatConfig: { disableGatewayMode: mockUserDefaultConfig.disableGatewayMode },
}),
},
+ toolInterventionSelectors: {
+ allowList: () => mockToolInterventionConfig.allowList,
+ approvalMode: () => mockToolInterventionConfig.approvalMode,
+ },
}));
// ─── Local-device activation (本机) test seams ───
@@ -141,6 +149,8 @@ describe('GatewayActionImpl', () => {
beforeEach(() => {
mockAgentStore.state = { activeAgentId: undefined, agentMap: {} };
mockUserDefaultConfig.disableGatewayMode = undefined;
+ mockToolInterventionConfig.approvalMode = 'manual';
+ mockToolInterventionConfig.allowList = [];
});
afterEach(() => {
@@ -636,6 +646,43 @@ describe('GatewayActionImpl', () => {
);
});
+ it('should forward current user intervention config to execAgentTask', async () => {
+ const { action } = createExecuteTestAction();
+ mockToolInterventionConfig.approvalMode = 'allow-list';
+ mockToolInterventionConfig.allowList = ['lobe-user-interaction/askUserQuestion'];
+
+ vi.mocked(aiAgentService.execAgentTask).mockResolvedValue({
+ agentId: 'agent-1',
+ assistantMessageId: 'ast-1',
+ autoStarted: true,
+ createdAt: new Date().toISOString(),
+ message: 'ok',
+ operationId: 'server-op-1',
+ status: 'created',
+ success: true,
+ timestamp: new Date().toISOString(),
+ token: 'test-token',
+ topicId: 'topic-1',
+ userMessageId: 'usr-1',
+ });
+
+ await action.executeGatewayAgent({
+ context: { agentId: 'agent-1', topicId: 'topic-1', threadId: null, scope: 'main' },
+ message: 'Hello',
+ });
+
+ expect(aiAgentService.execAgentTask).toHaveBeenCalledWith(
+ expect.objectContaining({
+ prompt: 'Hello',
+ userInterventionConfig: {
+ allowList: ['lobe-user-interaction/askUserQuestion'],
+ approvalMode: 'allow-list',
+ },
+ }),
+ expect.anything(),
+ );
+ });
+
it('should forward task manager default assignee and current task context', async () => {
const { action } = createExecuteTestAction();
@@ -1109,7 +1156,9 @@ describe('GatewayActionImpl', () => {
topicId: 'topic-1',
});
- vi.mocked(topicService.updateTopicMetadata).mockClear().mockResolvedValue(undefined as never);
+ vi.mocked(topicService.updateTopicMetadata)
+ .mockClear()
+ .mockResolvedValue(undefined as never);
captured.onSessionComplete!({ authFailed: false, succeeded: false, terminalReceived: false });
expect(completeOperation).toHaveBeenCalledWith('gw-op-reconnect');
@@ -1128,7 +1177,9 @@ describe('GatewayActionImpl', () => {
topicId: 'topic-1',
});
- vi.mocked(topicService.updateTopicMetadata).mockClear().mockResolvedValue(undefined as never);
+ vi.mocked(topicService.updateTopicMetadata)
+ .mockClear()
+ .mockResolvedValue(undefined as never);
captured.onSessionComplete!({ authFailed: false, succeeded: true, terminalReceived: true });
// The run lifecycle owns completion when a terminal event arrives, so the
@@ -1152,7 +1203,9 @@ describe('GatewayActionImpl', () => {
topicId: 'topic-1',
});
- vi.mocked(topicService.updateTopicMetadata).mockClear().mockResolvedValue(undefined as never);
+ vi.mocked(topicService.updateTopicMetadata)
+ .mockClear()
+ .mockResolvedValue(undefined as never);
captured.onSessionComplete!({ authFailed: true, succeeded: false, terminalReceived: false });
expect(completeOperation).toHaveBeenCalledWith('gw-op-reconnect');
diff --git a/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts b/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts
index 70167cdcbf7..97f75c91fd9 100644
--- a/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts
+++ b/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts
@@ -18,7 +18,7 @@ import { topicSelectors } from '@/store/chat/selectors';
import type { ChatStore } from '@/store/chat/store';
import type { StoreSetter } from '@/store/types';
import { useUserStore } from '@/store/user';
-import { settingsSelectors } from '@/store/user/selectors';
+import { settingsSelectors, toolInterventionSelectors } from '@/store/user/selectors';
import { buildRunLifecycle } from '../../lifecycle/buildRunLifecycle';
import type { RunScope } from '../../lifecycle/types';
@@ -432,6 +432,10 @@ export class GatewayActionImpl {
: undefined;
const localDeviceId = await resolveLocalDeviceId(context.agentId);
+ const userInterventionConfig = {
+ approvalMode: toolInterventionSelectors.approvalMode(useUserStore.getState()),
+ allowList: toolInterventionSelectors.allowList(useUserStore.getState()),
+ };
const result = await aiAgentService.execAgentTask(
{
@@ -465,6 +469,7 @@ export class GatewayActionImpl {
prompt: message,
resumeApproval,
trigger: metadata?.trigger,
+ userInterventionConfig,
},
{ signal: abortSignal },
);