🤯 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(chat-input): say where an Auto run lands on the execution target chip (#23774)
AmAzing-e7d6b607ce65
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.jsonindex 637e17b6d67..831f47c5fc6 100644--- a/locales/en-US/chat.json+++ b/locales/en-US/chat.json@@ -1610,7 +1610,10 @@"heteroAgent.codexQuota.totalEarned_one": "{{count}} earned in total","heteroAgent.codexQuota.totalEarned_other": "{{count}} earned in total","heteroAgent.executionTarget.auto": "Auto",+ "heteroAgent.executionTarget.autoAgentPicks": "Auto · Agent picks","heteroAgent.executionTarget.autoDesc": "Use an online device automatically, picking one when several are available",+ "heteroAgent.executionTarget.autoNoDevice": "Auto · No device online",+ "heteroAgent.executionTarget.autoOn": "Auto · {{name}}","heteroAgent.executionTarget.downloadDesktop": "Get Desktop App","heteroAgent.executionTarget.downloadDesktopDesc": "Run agents with access to your computer","heteroAgent.executionTarget.downloadDesktopTitle": "Get the desktop app",diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.jsonindex a205a17645c..640a6283475 100644--- a/locales/zh-CN/chat.json+++ b/locales/zh-CN/chat.json@@ -1610,7 +1610,10 @@"heteroAgent.codexQuota.totalEarned_one": "累计获得 {{count}} 次","heteroAgent.codexQuota.totalEarned_other": "累计获得 {{count}} 次","heteroAgent.executionTarget.auto": "自动",+ "heteroAgent.executionTarget.autoAgentPicks": "自动 · 由 Agent 选择","heteroAgent.executionTarget.autoDesc": "自动使用在线设备,有多台时择一使用",+ "heteroAgent.executionTarget.autoNoDevice": "自动 · 无在线设备",+ "heteroAgent.executionTarget.autoOn": "自动 · {{name}}","heteroAgent.executionTarget.downloadDesktop": "下载桌面端","heteroAgent.executionTarget.downloadDesktopDesc": "让 Agent 直接连接你的电脑","heteroAgent.executionTarget.downloadDesktopTitle": "下载桌面端",diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.tsindex 766cbf92ad1..d3d1d85b3a9 100644--- a/packages/locales/src/default/chat.ts+++ b/packages/locales/src/default/chat.ts@@ -985,8 +985,11 @@ export default {'heteroAgent.executionTarget.sandboxUnsupported':'{{name}} currently runs only on a local or connected device','heteroAgent.executionTarget.auto': 'Auto',+ 'heteroAgent.executionTarget.autoAgentPicks': 'Auto · Agent picks','heteroAgent.executionTarget.autoDesc':'Use an online device automatically, picking one when several are available',+ 'heteroAgent.executionTarget.autoNoDevice': 'Auto · No device online',+ 'heteroAgent.executionTarget.autoOn': 'Auto · {{name}}','heteroAgent.executionTarget.fixedTip':'The execution environment is fixed in the Agent Profile and cannot be switched while chatting.','heteroAgent.executionTarget.infoTooltip':diff --git a/src/features/ChatInput/ControlBar/HeteroDeviceSwitcher.tsx b/src/features/ChatInput/ControlBar/HeteroDeviceSwitcher.tsxindex a535ee87b2c..9350d0e9ab3 100644--- a/src/features/ChatInput/ControlBar/HeteroDeviceSwitcher.tsx+++ b/src/features/ChatInput/ControlBar/HeteroDeviceSwitcher.tsx@@ -50,6 +50,7 @@ import { useElectronStore } from '@/store/electron';import { useTopicId } from '../hooks/useTopicId';import { formatLockedControlTooltip } from '../utils/lockedControlTooltip';+import { autoDispatchPool, summarizeAutoTarget } from './autoTargetSummary';import CloudSandboxOptions from './CloudSandboxOptions';import DeviceGroupSubmenu from './DeviceGroupSubmenu';import DeviceOptionRow from './DeviceOptionRow';@@ -75,13 +76,14 @@ const styles = stylex.create({fontSize: '12px',color: { 'default': cssVar.colorTextSecondary, ':hover': cssVar.colorText },whiteSpace: 'nowrap',- transition: 'all 0.2s',+ transition: 'color 0.2s, background-color 0.2s',backgroundColor: { 'default': null, ':hover': cssVar.colorFillTertiary },backgroundImage: { 'default': null, ':hover': 'none' },},buttonLabel: {overflow: 'hidden',- maxWidth: '120px',+ // Room for "Auto · <device>" before a long machine name truncates.+ maxWidth: '160px',textOverflow: 'ellipsis',whiteSpace: 'nowrap',},@@ -158,7 +160,7 @@ const styles = stylex.create({},headerLink: {display: 'flex',- gap: '3px',+ gap: '4px',alignItems: 'center',fontSize: '11px',color: { 'default': cssVar.colorTextQuaternary, ':hover': cssVar.colorPrimary },@@ -169,7 +171,7 @@ const styles = stylex.create({manageButton: {cursor: 'pointer',display: 'flex',- gap: '3px',+ gap: '4px',alignItems: 'center',padding: '0',borderStyle: 'none',@@ -561,6 +563,28 @@ const HeteroDeviceSwitcher = memo<HeteroDeviceSwitcherProps>(({ agentId }) => {} else if (chipExecutionTarget === 'auto') {chipIcon = <ExecutionTargetIcon target={'auto'} />;chipLabel = t('heteroAgent.executionTarget.auto');+ // A bare "Auto" hides three different runs: one online device is used+ // directly, several leave the pick to the Agent, none runs without a+ // device. Say which one, from the pool the server dispatches among.+ if (canShowExecutionTargetSelector) {+ const autoSummary = summarizeAutoTarget({+ isConfirmed: isDeviceListConfirmed,+ pool: autoDispatchPool({ boundDeviceId, devices, isWorkspaceAgent }),+ });+ if (autoSummary.kind === 'single') {+ const name =+ isDesktop && isThisComputerDevice(autoSummary.device, localMachineDeviceIds)+ ? t('heteroAgent.executionTarget.local')+ : autoSummary.device.friendlyName ||+ autoSummary.device.hostname ||+ t('heteroAgent.executionTarget.unknownDevice');+ chipLabel = t('heteroAgent.executionTarget.autoOn', { name });+ } else if (autoSummary.kind === 'multiple') {+ chipLabel = t('heteroAgent.executionTarget.autoAgentPicks');+ } else if (autoSummary.kind === 'none') {+ chipLabel = t('heteroAgent.executionTarget.autoNoDevice');+ }+ }} else if (chipExecutionTarget === 'local') {// 本机始终使用通用的本地电脑图标,不区分具体平台chipIcon = <ExecutionTargetIcon target={canShowExecutionTargetSelector ? 'local' : 'device'} />;diff --git a/src/features/ChatInput/ControlBar/__tests__/HeteroDeviceSwitcher.sandboxMode.test.tsx b/src/features/ChatInput/ControlBar/__tests__/HeteroDeviceSwitcher.sandboxMode.test.tsxindex f4b8614c5bd..fb799254a74 100644--- a/src/features/ChatInput/ControlBar/__tests__/HeteroDeviceSwitcher.sandboxMode.test.tsx+++ b/src/features/ChatInput/ControlBar/__tests__/HeteroDeviceSwitcher.sandboxMode.test.tsx@@ -5,7 +5,10 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';import HeteroDeviceSwitcher from '../HeteroDeviceSwitcher';const state = vi.hoisted(() => ({+ agentWorkspaceId: undefined as string | undefined,+ boundDeviceId: undefined as string | undefined,devices: [] as object[],+ executionTarget: 'sandbox',selectTarget: vi.fn(),}));@@ -49,7 +52,7 @@ vi.mock('@/features/Workspace/useWorkspaceAwareNavigate', () => ({vi.mock('@/helpers/gatewayMode', () => ({ useIsGatewayModeEnabled: () => false }));vi.mock('@/hooks/useEffectiveAgencyConfig', () => ({useEffectiveAgencyConfig: () => ({- agencyConfig: { executionTarget: 'sandbox' },+ agencyConfig: { boundDeviceId: state.boundDeviceId, executionTarget: state.executionTarget },canDisplayExecutionTarget: true,canSelectExecutionTarget: true,isPreferenceLoading: false,@@ -61,7 +64,8 @@ vi.mock('@/hooks/useLocalMachineDeviceIds', () => ({ useLocalMachineDeviceIds: (vi.mock('@/services/device', () => ({ deviceService: {} }));vi.mock('@/services/electron/localFileService', () => ({ localFileService: {} }));vi.mock('@/store/agent', () => ({- useAgentStore: (selector: (s: object) => unknown) => selector({ agentMap: {} }),+ useAgentStore: (selector: (s: object) => unknown) =>+ selector({ agentMap: { 'agent-1': { workspaceId: state.agentWorkspaceId } } }),}));vi.mock('@/store/device', () => ({isDevicePresenceUnknown: () => false,@@ -97,7 +101,10 @@ vi.mock('../CloudSandboxOptions', () => ({const SANDBOX = 'heteroAgent.executionTarget.sandbox';beforeEach(() => {+ state.agentWorkspaceId = undefined;+ state.boundDeviceId = undefined;state.devices = [];+ state.executionTarget = 'sandbox';state.selectTarget.mockReset().mockResolvedValue(undefined);});@@ -171,3 +178,71 @@ describe('HeteroDeviceSwitcher — first level', () => {expect(follows(sandbox, devices)).toBe(true);});});++// A bare "Auto" hid where the run lands: one online device, the Agent's pick+// among several, or no device at all.+describe('HeteroDeviceSwitcher — auto chip', () => {+ const device = (deviceId: string, online: boolean) => ({+ deviceId,+ friendlyName: null,+ hostname: deviceId,+ online,+ platform: 'darwin',+ scope: 'personal',+ });+ const chipText = () => screen.getAllByTestId('chip')[0].textContent;++ beforeEach(() => {+ state.executionTarget = 'auto';+ });++ it('names the one online device the run will use', () => {+ state.devices = [device('mac-mini', true), device('old-pc', false)];+ render(<HeteroDeviceSwitcher agentId="agent-1" />);++ expect(chipText()).toBe('heteroAgent.executionTarget.autoOn');+ });++ it('says the Agent picks when several devices are online', () => {+ state.devices = [device('mac-mini', true), device('linux-box', true)];+ render(<HeteroDeviceSwitcher agentId="agent-1" />);++ expect(chipText()).toBe('heteroAgent.executionTarget.autoAgentPicks');+ });++ it('says no device is online instead of a bare Auto', () => {+ state.devices = [device('old-pc', false)];+ render(<HeteroDeviceSwitcher agentId="agent-1" />);++ expect(chipText()).toBe('heteroAgent.executionTarget.autoNoDevice');+ });++ // A member who picked "This computer" keeps that personal device bound when+ // switching to Auto, and the server adds it to the workspace run's pool.+ describe('workspace agent with a bound personal device', () => {+ const workspaceDevice = (deviceId: string, online: boolean) => ({+ ...device(deviceId, online),+ scope: 'workspace',+ visibility: 'public',+ });++ beforeEach(() => {+ state.agentWorkspaceId = 'ws-1';+ state.boundDeviceId = 'my-laptop';+ });++ it('names the personal device when the workspace pool has none online', () => {+ state.devices = [device('my-laptop', true), workspaceDevice('shared-box', false)];+ render(<HeteroDeviceSwitcher agentId="agent-1" />);++ expect(chipText()).toBe('heteroAgent.executionTarget.autoOn');+ });++ it('leaves the pick to the Agent when a workspace device is online too', () => {+ state.devices = [device('my-laptop', true), workspaceDevice('shared-box', true)];+ render(<HeteroDeviceSwitcher agentId="agent-1" />);++ expect(chipText()).toBe('heteroAgent.executionTarget.autoAgentPicks');+ });+ });+});diff --git a/src/features/ChatInput/ControlBar/autoTargetSummary.test.ts b/src/features/ChatInput/ControlBar/autoTargetSummary.test.tsnew file mode 100644index 00000000000..beb40654a99--- /dev/null+++ b/src/features/ChatInput/ControlBar/autoTargetSummary.test.ts@@ -0,0 +1,76 @@+import type { DeviceListItem } from '@lobechat/types';+import { describe, expect, it } from 'vitest';++import { autoDispatchPool, summarizeAutoTarget } from './autoTargetSummary';++const device = (id: string, online: boolean, onlineUnknown?: boolean) => ({+ deviceId: id,+ online,+ onlineUnknown,+});++describe('summarizeAutoTarget', () => {+ it('names the one online device, which an auto run uses directly', () => {+ const mac = device('mac', true);++ expect(summarizeAutoTarget({ isConfirmed: true, pool: [mac, device('pc', false)] })).toEqual({+ device: mac,+ kind: 'single',+ });+ });++ it('says the Agent picks when several devices are online', () => {+ expect(+ summarizeAutoTarget({ isConfirmed: true, pool: [device('a', true), device('b', true)] }),+ ).toEqual({ kind: 'multiple' });+ });++ it('says nothing is online, including for an empty pool', () => {+ expect(summarizeAutoTarget({ isConfirmed: true, pool: [device('a', false)] })).toEqual({+ kind: 'none',+ });+ expect(summarizeAutoTarget({ isConfirmed: true, pool: [] })).toEqual({ kind: 'none' });+ });++ // A stored copy's `online: false` is a placeholder: claiming "no device+ // online" from it would contradict the run a moment later.+ it('stays pending until the list and every presence are confirmed', () => {+ expect(summarizeAutoTarget({ isConfirmed: false, pool: [device('a', true)] })).toEqual({+ kind: 'pending',+ });+ expect(summarizeAutoTarget({ isConfirmed: true, pool: [device('a', false, true)] })).toEqual({+ kind: 'pending',+ });+ });+});++describe('autoDispatchPool', () => {+ const row = (deviceId: string, scope: 'personal' | 'workspace') =>+ ({ deviceId, online: true, scope, visibility: 'public' }) as DeviceListItem;+ const laptop = row('laptop', 'personal');+ const shared = row('shared', 'workspace');+ const devices = [laptop, shared];++ it('adds the bound personal device to a workspace agent pool, as dispatch does', () => {+ expect(autoDispatchPool({ boundDeviceId: 'laptop', devices, isWorkspaceAgent: true })).toEqual([+ shared,+ laptop,+ ]);+ });++ it('keeps the workspace pool alone without a personal binding', () => {+ expect(autoDispatchPool({ devices, isWorkspaceAgent: true })).toEqual([shared]);+ expect(autoDispatchPool({ boundDeviceId: 'shared', devices, isWorkspaceAgent: true })).toEqual([+ shared,+ ]);+ expect(autoDispatchPool({ boundDeviceId: 'gone', devices, isWorkspaceAgent: true })).toEqual([+ shared,+ ]);+ });++ it('uses the personal pool for a personal agent', () => {+ expect(autoDispatchPool({ boundDeviceId: 'laptop', devices, isWorkspaceAgent: false })).toEqual(+ [laptop],+ );+ });+});diff --git a/src/features/ChatInput/ControlBar/autoTargetSummary.ts b/src/features/ChatInput/ControlBar/autoTargetSummary.tsnew file mode 100644index 00000000000..374de8ea1b3--- /dev/null+++ b/src/features/ChatInput/ControlBar/autoTargetSummary.ts@@ -0,0 +1,80 @@+import type { DeviceListItem } from '@lobechat/types';++import { devicePoolForAgent, groupExecutionTargetDevices } from '@/features/ExecutionTargetPicker';++export type AutoTargetSummary<D = DeviceListItem> =+ { kind: 'pending' } | { device: D; kind: 'single' } | { kind: 'multiple' } | { kind: 'none' };++/**+ * The devices an `auto` run dispatches among, as the server builds them.+ *+ * Use when:+ * - Summarizing an `auto` target: the agent's own pool alone misses a device+ * the server adds to it+ *+ * Expects:+ * - `boundDeviceId` is the effective config's binding (a member override+ * keeps the personal device picked under "This computer" when switching to+ * `auto`)+ *+ * Returns:+ * - The agent's pool (`devicePoolForAgent`); for a workspace agent, plus the+ * caller's personal device that `boundDeviceId` names. The server unions it+ * into the workspace run's online set (`readOnlineDevices`), and+ * `resolveExecutionPlan` counts it among the `auto` candidates.+ */+export const autoDispatchPool = ({+ boundDeviceId,+ devices,+ isWorkspaceAgent,+}: {+ boundDeviceId?: string | null;+ devices: DeviceListItem[] | undefined;+ isWorkspaceAgent: boolean;+}): DeviceListItem[] => {+ const pool = devicePoolForAgent(devices, isWorkspaceAgent);+ if (!isWorkspaceAgent || !boundDeviceId || pool.some((d) => d.deviceId === boundDeviceId)) {+ return pool;+ }++ const bound = groupExecutionTargetDevices(devices).personal.find(+ (device) => device.deviceId === boundDeviceId,+ );++ return bound ? [...pool, bound] : pool;+};++/**+ * Where an `auto` run will land, so the chip can say it instead of a bare+ * "Auto".+ *+ * Use when:+ * - The execution-target chip shows `auto` and needs the outcome the server+ * will reach for the same pool (`resolveExecutionPlan`'s unbound branch)+ *+ * Expects:+ * - `pool` is the device pool the run dispatches to (`autoDispatchPool`),+ * the same set the server reads its online devices from+ *+ * Returns:+ * - `pending` until the server confirmed the list and every row's presence:+ * a stored copy's `online: false` is a placeholder, not a fact+ * - `single` with the one online device, which the run uses directly+ * - `multiple` when several are online, and the Agent picks one per run+ * - `none` when nothing is online, and the run gets no device+ */+export const summarizeAutoTarget = <D extends Pick<DeviceListItem, 'online' | 'onlineUnknown'>>({+ isConfirmed,+ pool,+}: {+ isConfirmed: boolean;+ pool: D[];+}): AutoTargetSummary<D> => {+ if (!isConfirmed || pool.some((device) => device.onlineUnknown)) return { kind: 'pending' };++ const online = pool.filter((device) => device.online);+ if (online.length === 1) return { device: online[0], kind: 'single' };+ if (online.length > 1) return { kind: 'multiple' };++ return { kind: 'none' };+};diff --git a/src/features/ExecutionTargetPicker/index.tsx b/src/features/ExecutionTargetPicker/index.tsxindex 07ec2099e1c..84b9d2627d4 100644--- a/src/features/ExecutionTargetPicker/index.tsx+++ b/src/features/ExecutionTargetPicker/index.tsx@@ -2,7 +2,7 @@import type { DeviceExecutionTarget, DeviceListItem } from '@lobechat/types';import { createStaticStyles, cssVar, Flexbox, Icon } from '@lobehub/ui';-import { BoxIcon, LaptopIcon, MonitorOffIcon, SparklesIcon } from 'lucide-react';+import { BoxIcon, LaptopIcon, MonitorOffIcon, MonitorSmartphoneIcon } from 'lucide-react';import { memo } from 'react';import { getDeviceIcon } from '@/features/DeviceManager/getDeviceIcon';@@ -295,7 +295,9 @@ export const ExecutionTargetIcon = memo<ExecutionTargetIconProps>(({ devicePlatform, size = 14, target }) => {switch (target) {case 'auto': {- return <Icon icon={SparklesIcon} size={size} />;+ // A device family, not sparkles: `auto` picks among the user's+ // devices, and sparkles read as an AI mode next to the model picker.+ return <Icon icon={MonitorSmartphoneIcon} size={size} />;}case 'device': {return <>{getDeviceIcon(devicePlatform, size)}</>;diff --git a/src/features/Projects/WorkingDirectories/ExecutionEnvironments.tsx b/src/features/Projects/WorkingDirectories/ExecutionEnvironments.tsxindex 6aec88346ba..344e5e3a000 100644--- a/src/features/Projects/WorkingDirectories/ExecutionEnvironments.tsx+++ b/src/features/Projects/WorkingDirectories/ExecutionEnvironments.tsx@@ -38,7 +38,7 @@ import {isMissingDirectoryError,} from './directoryAvailability';import { openEditDirectoryModal } from './EditDirectoryModal';-import type { ProjectExecutionEnvironment } from './executionEnvironments';+import type { ProjectExecutionEnvironment } from './executionEnvironmentOrder';import { useProjectExecutionEnvironments } from './useProjectExecutionEnvironments';/**diff --git a/src/features/Projects/WorkingDirectories/SidebarTopics.tsx b/src/features/Projects/WorkingDirectories/SidebarTopics.tsxindex afb09427c98..b4263e5b1c5 100644--- a/src/features/Projects/WorkingDirectories/SidebarTopics.tsx+++ b/src/features/Projects/WorkingDirectories/SidebarTopics.tsx@@ -41,7 +41,7 @@ import {} from '@/store/projectWorkingDirectory';import { filterTopics, type TopicListFilter } from '@/utils/client/topic';-import { pickExecutionEnvironment } from './executionEnvironments';+import { pickExecutionEnvironment } from './executionEnvironmentOrder';import { canStageDraftOn } from './startProjectTopicDraft';import { useAgentFixedDeviceId } from './useAgentFixedDeviceId';import {diff --git a/src/features/Projects/WorkingDirectories/executionEnvironments.test.ts b/src/features/Projects/WorkingDirectories/executionEnvironmentOrder.test.tssimilarity index 97%rename from src/features/Projects/WorkingDirectories/executionEnvironments.test.tsrename to src/features/Projects/WorkingDirectories/executionEnvironmentOrder.test.tsindex c9c5060b499..2d9c975883c 100644--- a/src/features/Projects/WorkingDirectories/executionEnvironments.test.ts+++ b/src/features/Projects/WorkingDirectories/executionEnvironmentOrder.test.ts@@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest';import type { ProjectDirectory } from '@/store/projectWorkingDirectory';-import { orderExecutionEnvironments, pickExecutionEnvironment } from './executionEnvironments';+import { orderExecutionEnvironments, pickExecutionEnvironment } from './executionEnvironmentOrder';const folder = (id: string, sortOrder = 0) => ({ id, sortOrder }) as unknown as ProjectDirectory;const ids = (items: { id: string }[]) => items.map((item) => item.id);diff --git a/src/features/Projects/WorkingDirectories/executionEnvironments.ts b/src/features/Projects/WorkingDirectories/executionEnvironmentOrder.tssimilarity index 100%rename from src/features/Projects/WorkingDirectories/executionEnvironments.tsrename to src/features/Projects/WorkingDirectories/executionEnvironmentOrder.tsdiff --git a/src/features/Projects/WorkingDirectories/useProjectExecutionEnvironments.ts b/src/features/Projects/WorkingDirectories/useProjectExecutionEnvironments.tsindex 333706529fd..82aab521447 100644--- a/src/features/Projects/WorkingDirectories/useProjectExecutionEnvironments.ts+++ b/src/features/Projects/WorkingDirectories/useProjectExecutionEnvironments.ts@@ -9,7 +9,7 @@ import { useProjectDirectories, useProjectDirectoryStore } from '@/store/projectimport {orderExecutionEnvironments,type ProjectExecutionEnvironment,-} from './executionEnvironments';+} from './executionEnvironmentOrder';const executionOrderKey = (projectId?: string) =>projectId ? ['project-execution-order', projectId] : null;