π€― 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(hetero): forward user images on regenerate so vision input isn't dropped (#15592)
Arvin Xu6c6c8698d33c
diff --git a/src/features/Conversation/store/slices/generation/action.ts b/src/features/Conversation/store/slices/generation/action.tsindex 202ceeab6ae..eb73ef26a37 100644--- a/src/features/Conversation/store/slices/generation/action.ts+++ b/src/features/Conversation/store/slices/generation/action.ts@@ -1,6 +1,10 @@import { AgentManagementIdentifier } from '@lobechat/builtin-tool-agent-management';import { LOADING_FLAT } from '@lobechat/const';-import type { ConversationContext, HeterogeneousProviderConfig } from '@lobechat/types';+import type {+ ChatImageItem,+ ConversationContext,+ HeterogeneousProviderConfig,+} from '@lobechat/types';import { t } from 'i18next';import { type StateCreator } from 'zustand';@@ -71,12 +75,15 @@ const runHeterogeneousFromExistingMessage = async (params: {context: ConversationContext;heterogeneousProvider: HeterogeneousProviderConfig;+ /** Image attachments from the original user message β forwarded to the CLI for vision support */+ imageList?: ChatImageItem[];parentMessageId: string;parentOperationId: string;prompt: string;},): Promise<string> => {- const { context, heterogeneousProvider, parentMessageId, parentOperationId, prompt } = params;+ const { context, heterogeneousProvider, imageList, parentMessageId, parentOperationId, prompt } =+ params;const agentId = context.agentId;if (!agentId) throw new Error('agentId is required for heterogeneous agent');@@ -132,6 +139,7 @@ const runHeterogeneousFromExistingMessage = async (assistantMessageId: assistantMsg.id,context,heterogeneousProvider,+ imageList: imageList?.length ? imageList : undefined,message: prompt,operationId: heteroOpId,resumeSessionId,@@ -526,6 +534,11 @@ export const generationSlice: StateCreator<await runHeterogeneousFromExistingMessage(chatStore, {context,heterogeneousProvider,+ // Forward the original user message's images so regenerate re-runs+ // the CLI with the same vision input as the first attempt. Without+ // this, regenerate silently drops attachments (the send path reads+ // imageList off the persisted user message; this path must too).+ imageList: item.imageList,parentMessageId: messageId,parentOperationId: operationId,prompt: item.content,diff --git a/src/features/Conversation/store/slices/generation/regenerateHeteroImages.test.ts b/src/features/Conversation/store/slices/generation/regenerateHeteroImages.test.tsnew file mode 100644index 00000000000..81d0bbf6bda--- /dev/null+++ b/src/features/Conversation/store/slices/generation/regenerateHeteroImages.test.ts@@ -0,0 +1,143 @@+import { act } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import { type ConversationContext } from '../../../types';+import { createStore } from '../../index';++// ββ Mock the hetero runtime seam ββ+// regenerate (hetero) re-creates an assistant row, then delegates to+// `executeHeterogeneousAgent`. We spy on that boundary and assert the original+// user message's `imageList` is forwarded β the regression this guards against+// is regenerate silently dropping image attachments (the send path forwards+// them; this path must too).+const mockExecuteHeterogeneousAgent = vi.fn();+vi.mock('@/store/chat/slices/aiChat/actions/heterogeneousAgentExecutor', () => ({+ executeHeterogeneousAgent: (...args: any[]) => mockExecuteHeterogeneousAgent(...args),+}));++vi.mock('@/store/chat/slices/aiChat/actions/agentDispatcher', () => ({+ selectRuntimeType: () => 'hetero',+}));++vi.mock('@/store/chat/slices/aiChat/actions/heteroResume', () => ({+ resolveHeteroResume: () => ({ cwdChanged: false, resumeSessionId: 'sess-1' }),+}));++vi.mock('@/store/chat/utils/activeTopicDocumentContext', () => ({+ mergeAgentRuntimeInitialContexts: () => undefined,+ resolveActiveTopicDocumentInitialContext: async () => undefined,+}));++vi.mock('@/store/chat/slices/operation/selectors', () => ({+ operationSelectors: { isMessageProcessing: () => () => false },+}));++vi.mock('@/services/message', () => ({+ messageService: { createMessage: vi.fn(async () => ({ id: 'assistant-new' })) },+}));++vi.mock('@/store/agent', () => ({ getAgentStoreState: () => ({}) }));++vi.mock('@/store/agent/selectors', () => ({+ agentByIdSelectors: { getAgentWorkingDirectoryById: () => () => '/work/dir' },+ agentSelectors: {+ getAgentConfigById: () => () => ({+ agencyConfig: {+ executionTarget: 'local',+ heterogeneousProvider: { type: 'claude-code' },+ },+ }),+ },+}));++vi.mock('@/store/chat/selectors', () => ({+ topicSelectors: { getTopicById: () => () => undefined },+}));++vi.mock('@/store/electron', () => ({+ getElectronStoreState: () => ({ gatewayDeviceInfo: { deviceId: 'device-1' } }),+}));++vi.mock('@/components/AntdStaticMethods', () => ({+ message: { info: vi.fn() },+}));++const noop = vi.fn();+vi.mock('@/store/chat', () => ({+ useChatStore: {+ getState: vi.fn(() => ({+ operations: {},+ operationsByMessage: {},++ associateMessageWithOperation: noop,+ completeOperation: noop,+ failOperation: noop,+ internal_updateTopicLoading: noop,+ isGatewayModeEnabled: () => false,+ refreshMessages: vi.fn(async () => {}),+ startOperation: vi.fn(() => ({ operationId: 'hetero-op-id' })),+ switchMessageBranch: vi.fn(async () => {}),+ })),+ setState: vi.fn(),+ },+}));++describe('regenerateUserMessage (hetero) β image forwarding', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ });++ it('forwards the original user message imageList to executeHeterogeneousAgent', async () => {+ const context: ConversationContext = {+ agentId: 'agent-1',+ topicId: 'topic-1',+ threadId: null,+ };++ const imageList = [{ alt: 'shot.png', id: 'img-1', url: 'https://x/img-1.png' }];++ const store = createStore({ context });+ act(() => {+ store.setState({+ displayMessages: [{ content: 'describe this', id: 'msg-1', imageList, role: 'user' }],+ dbMessages: [{ content: 'describe this', id: 'msg-1', role: 'user' }],+ } as any);+ });++ await act(async () => {+ await store.getState().regenerateUserMessage('msg-1');+ });++ expect(mockExecuteHeterogeneousAgent).toHaveBeenCalledTimes(1);+ const [, params] = mockExecuteHeterogeneousAgent.mock.calls[0];+ expect(params).toMatchObject({+ assistantMessageId: 'assistant-new',+ imageList,+ message: 'describe this',+ });+ });++ it('passes undefined imageList when the original message had no images', async () => {+ const context: ConversationContext = {+ agentId: 'agent-1',+ topicId: 'topic-1',+ threadId: null,+ };++ const store = createStore({ context });+ act(() => {+ store.setState({+ displayMessages: [{ content: 'hello', id: 'msg-1', role: 'user' }],+ dbMessages: [{ content: 'hello', id: 'msg-1', role: 'user' }],+ } as any);+ });++ await act(async () => {+ await store.getState().regenerateUserMessage('msg-1');+ });++ expect(mockExecuteHeterogeneousAgent).toHaveBeenCalledTimes(1);+ const [, params] = mockExecuteHeterogeneousAgent.mock.calls[0];+ expect(params.imageList).toBeUndefined();+ });+});