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: fix supervisor flag

arvinxxfc20dbca365b
diff --git a/packages/builtin-tool-gtd/package.json b/packages/builtin-tool-gtd/package.json
index 70ff28b08cf..2120b257165 100644
--- a/packages/builtin-tool-gtd/package.json
+++ b/packages/builtin-tool-gtd/package.json
@@ -13,7 +13,6 @@
},
"devDependencies": {
"@lobechat/types": "workspace:*",
- "@lobehub/editor": "^3",
"@lobehub/ui": "^4.3.1"
},
"peerDependencies": {
diff --git a/packages/editor-runtime/package.json b/packages/editor-runtime/package.json
index 213208a8114..e95884929cf 100644
--- a/packages/editor-runtime/package.json
+++ b/packages/editor-runtime/package.json
@@ -10,7 +10,6 @@
"@lobechat/prompts": "workspace:*"
},
"devDependencies": {
- "@lobehub/editor": "^3",
"lexical": "^0.39.0"
},
"peerDependencies": {
diff --git a/src/features/Conversation/Messages/Supervisor/components/ContentBlock.tsx b/src/features/Conversation/Messages/Supervisor/components/ContentBlock.tsx
index 9ae95a1aca1..3df8770a1a7 100644
--- a/src/features/Conversation/Messages/Supervisor/components/ContentBlock.tsx
+++ b/src/features/Conversation/Messages/Supervisor/components/ContentBlock.tsx
@@ -33,7 +33,7 @@ const ContentBlock = memo<AssistantContentBlock>(({ id, tools, content, reasonin
{showReasoning && <Reasoning {...reasoning} id={id} />}
{/* Content - markdown text */}
- <MessageContent content={content} id={id} />
+ <MessageContent content={content} hasTools={hasTools} id={id} />
{/* Tools */}
{hasTools && <Tools messageId={id} tools={tools} />}
diff --git a/src/features/Conversation/Messages/Supervisor/components/MessageContent.tsx b/src/features/Conversation/Messages/Supervisor/components/MessageContent.tsx
index d937abb5387..1c364bb80e7 100644
--- a/src/features/Conversation/Messages/Supervisor/components/MessageContent.tsx
+++ b/src/features/Conversation/Messages/Supervisor/components/MessageContent.tsx
@@ -9,14 +9,19 @@ import { useMarkdown } from '../../AssistantGroup/useMarkdown';
interface ContentBlockProps {
content: string;
+ hasTools?: boolean;
id: string;
}
-const MessageContent = memo<ContentBlockProps>(({ content, id }) => {
+const MessageContent = memo<ContentBlockProps>(({ content, id, hasTools }) => {
const message = normalizeThinkTags(processWithArtifact(content));
const markdownProps = useMarkdown(id);
- if (!content || content === LOADING_FLAT) return <BubblesLoading />;
+ if (!content || content === LOADING_FLAT) {
+ if (hasTools) return null;
+
+ return <BubblesLoading />;
+ }
return content && <MarkdownMessage {...markdownProps}>{message}</MarkdownMessage>;
});
diff --git a/src/features/Conversation/Messages/Supervisor/index.tsx b/src/features/Conversation/Messages/Supervisor/index.tsx
index 86bcea477e9..960626973c2 100644
--- a/src/features/Conversation/Messages/Supervisor/index.tsx
+++ b/src/features/Conversation/Messages/Supervisor/index.tsx
@@ -78,23 +78,18 @@ const GroupMessage = memo<GroupMessageProps>(({ id, index, disableEditing, isLat
return (
<ChatItem
actions={
- !disableEditing && (
- <>
- {branch && (
- <MessageBranch
- activeBranchIndex={branch.activeBranchIndex}
- count={branch.count}
- messageId={id}
- />
- )}
- {actionBarHolder}
- </>
- )
+ <>
+ {branch && (
+ <MessageBranch
+ activeBranchIndex={branch.activeBranchIndex}
+ count={branch.count}
+ messageId={id}
+ />
+ )}
+ {actionBarHolder}
+ </>
}
- avatar={{
- ...avatar,
- title: groupMeta.title,
- }}
+ avatar={{ ...avatar, title: groupMeta.title }}
customAvatarRender={() => <GroupAvatar avatars={memberAvatars} />}
newScreen={newScreen}
onMouseEnter={onMouseEnter}
diff --git a/src/store/chat/slices/aiAgent/actions/__tests__/groupOrchestration.test.ts b/src/store/chat/slices/aiAgent/actions/__tests__/groupOrchestration.test.ts
new file mode 100644
index 00000000000..262dda7d736
--- /dev/null
+++ b/src/store/chat/slices/aiAgent/actions/__tests__/groupOrchestration.test.ts
@@ -0,0 +1,223 @@
+import { act, renderHook } from '@testing-library/react';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { useChatStore } from '@/store/chat/store';
+
+// Keep zustand mock as it's needed globally
+vi.mock('zustand/traditional');
+
+// Test Constants
+const TEST_IDS = {
+ GROUP_ID: 'test-group-id',
+ SUPERVISOR_AGENT_ID: 'test-supervisor-agent-id',
+ TOPIC_ID: 'test-topic-id',
+ OPERATION_ID: 'test-operation-id',
+} as const;
+
+// Helper to reset test environment
+const resetTestEnvironment = () => {
+ vi.clearAllMocks();
+ useChatStore.setState(
+ {
+ activeAgentId: TEST_IDS.SUPERVISOR_AGENT_ID,
+ activeGroupId: TEST_IDS.GROUP_ID,
+ activeTopicId: TEST_IDS.TOPIC_ID,
+ messagesMap: {},
+ dbMessagesMap: {},
+ operations: {},
+ messageOperationMap: {},
+ },
+ false,
+ );
+};
+
+describe('groupOrchestration actions', () => {
+ beforeEach(() => {
+ resetTestEnvironment();
+
+ // Setup default mocks for store methods
+ act(() => {
+ useChatStore.setState({
+ startOperation: vi.fn().mockReturnValue({
+ operationId: TEST_IDS.OPERATION_ID,
+ abortController: new AbortController(),
+ }),
+ completeOperation: vi.fn(),
+ failOperation: vi.fn(),
+ });
+ });
+ });
+
+ afterEach(() => {
+ vi.restoreAllMocks();
+ });
+
+ describe('internal_execGroupOrchestration', () => {
+ it('should create operation with scope: group in context', async () => {
+ const { result } = renderHook(() => useChatStore());
+
+ // Spy on startOperation to verify it's called with correct context
+ const startOperationSpy = vi.spyOn(result.current, 'startOperation');
+
+ // Call internal_execGroupOrchestration - it will fail after startOperation
+ // because the runtime needs more setup, but we only care about the startOperation call
+ try {
+ await act(async () => {
+ await result.current.internal_execGroupOrchestration({
+ groupId: TEST_IDS.GROUP_ID,
+ supervisorAgentId: TEST_IDS.SUPERVISOR_AGENT_ID,
+ topicId: TEST_IDS.TOPIC_ID,
+ initialResult: {
+ type: 'supervisor_decided',
+ payload: {
+ decision: 'finish',
+ params: {},
+ skipCallSupervisor: true,
+ },
+ },
+ });
+ });
+ } catch {
+ // Expected to fail after startOperation due to runtime dependencies
+ }
+
+ // Verify startOperation was called with scope: 'group' in context
+ // This is the key assertion - ensures supervisor messages have correct scope
+ // after broadcast completes and call_supervisor is invoked
+ expect(startOperationSpy).toHaveBeenCalledWith(
+ expect.objectContaining({
+ type: 'execAgentRuntime',
+ context: expect.objectContaining({
+ groupId: TEST_IDS.GROUP_ID,
+ topicId: TEST_IDS.TOPIC_ID,
+ agentId: TEST_IDS.SUPERVISOR_AGENT_ID,
+ scope: 'group',
+ }),
+ label: expect.stringContaining('Group Orchestration'),
+ }),
+ );
+ });
+ });
+
+ describe('triggerBroadcast', () => {
+ it('should call internal_execGroupOrchestration with broadcast decision', async () => {
+ const { result } = renderHook(() => useChatStore());
+
+ const internal_execGroupOrchestrationSpy = vi.fn().mockResolvedValue({ status: 'done' });
+ act(() => {
+ useChatStore.setState({
+ internal_execGroupOrchestration: internal_execGroupOrchestrationSpy,
+ });
+ });
+
+ await act(async () => {
+ await result.current.triggerBroadcast({
+ supervisorAgentId: TEST_IDS.SUPERVISOR_AGENT_ID,
+ agentIds: ['agent-1', 'agent-2'],
+ instruction: 'Test instruction',
+ skipCallSupervisor: false,
+ toolMessageId: 'tool-msg-id',
+ });
+ });
+
+ expect(internal_execGroupOrchestrationSpy).toHaveBeenCalledWith(
+ expect.objectContaining({
+ groupId: TEST_IDS.GROUP_ID,
+ supervisorAgentId: TEST_IDS.SUPERVISOR_AGENT_ID,
+ topicId: TEST_IDS.TOPIC_ID,
+ initialResult: expect.objectContaining({
+ type: 'supervisor_decided',
+ payload: expect.objectContaining({
+ decision: 'broadcast',
+ params: expect.objectContaining({
+ agentIds: ['agent-1', 'agent-2'],
+ instruction: 'Test instruction',
+ toolMessageId: 'tool-msg-id',
+ }),
+ skipCallSupervisor: false,
+ }),
+ }),
+ }),
+ );
+ });
+ });
+
+ describe('triggerSpeak', () => {
+ it('should call internal_execGroupOrchestration with speak decision', async () => {
+ const { result } = renderHook(() => useChatStore());
+
+ const internal_execGroupOrchestrationSpy = vi.fn().mockResolvedValue({ status: 'done' });
+ act(() => {
+ useChatStore.setState({
+ internal_execGroupOrchestration: internal_execGroupOrchestrationSpy,
+ });
+ });
+
+ await act(async () => {
+ await result.current.triggerSpeak({
+ supervisorAgentId: TEST_IDS.SUPERVISOR_AGENT_ID,
+ agentId: 'target-agent-id',
+ instruction: 'Test instruction',
+ skipCallSupervisor: true,
+ });
+ });
+
+ expect(internal_execGroupOrchestrationSpy).toHaveBeenCalledWith(
+ expect.objectContaining({
+ groupId: TEST_IDS.GROUP_ID,
+ supervisorAgentId: TEST_IDS.SUPERVISOR_AGENT_ID,
+ initialResult: expect.objectContaining({
+ type: 'supervisor_decided',
+ payload: expect.objectContaining({
+ decision: 'speak',
+ params: expect.objectContaining({
+ agentId: 'target-agent-id',
+ instruction: 'Test instruction',
+ }),
+ skipCallSupervisor: true,
+ }),
+ }),
+ }),
+ );
+ });
+ });
+
+ describe('triggerDelegate', () => {
+ it('should call internal_execGroupOrchestration with delegate decision', async () => {
+ const { result } = renderHook(() => useChatStore());
+
+ const internal_execGroupOrchestrationSpy = vi.fn().mockResolvedValue({ status: 'done' });
+ act(() => {
+ useChatStore.setState({
+ internal_execGroupOrchestration: internal_execGroupOrchestrationSpy,
+ });
+ });
+
+ await act(async () => {
+ await result.current.triggerDelegate({
+ supervisorAgentId: TEST_IDS.SUPERVISOR_AGENT_ID,
+ agentId: 'delegate-agent-id',
+ reason: 'Test reason',
+ });
+ });
+
+ expect(internal_execGroupOrchestrationSpy).toHaveBeenCalledWith(
+ expect.objectContaining({
+ groupId: TEST_IDS.GROUP_ID,
+ supervisorAgentId: TEST_IDS.SUPERVISOR_AGENT_ID,
+ initialResult: expect.objectContaining({
+ type: 'supervisor_decided',
+ payload: expect.objectContaining({
+ decision: 'delegate',
+ params: expect.objectContaining({
+ agentId: 'delegate-agent-id',
+ reason: 'Test reason',
+ }),
+ skipCallSupervisor: false,
+ }),
+ }),
+ }),
+ );
+ });
+ });
+});
diff --git a/src/store/chat/slices/aiAgent/actions/groupOrchestration.ts b/src/store/chat/slices/aiAgent/actions/groupOrchestration.ts
index 222b39218b4..937cf79300d 100644
--- a/src/store/chat/slices/aiAgent/actions/groupOrchestration.ts
+++ b/src/store/chat/slices/aiAgent/actions/groupOrchestration.ts
@@ -270,7 +270,7 @@ export const groupOrchestrationSlice: StateCreator<
// 1. Create Orchestration Operation
const { operationId } = get().startOperation({
type: 'execAgentRuntime',
- context: { groupId, topicId, agentId: supervisorAgentId },
+ context: { groupId, topicId, agentId: supervisorAgentId, scope: 'group' },
label: `Group Orchestration (${initialResult.type})`,
});