🤯 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
💄 style(device-picker): merge this computer with its own row, fold offline devices (#23773)
Arvin Xu952c8506465b
diff --git a/locales/en-US/device.json b/locales/en-US/device.jsonindex 95818e1f22b..499942238cb 100644--- a/locales/en-US/device.json+++ b/locales/en-US/device.json@@ -1,4 +1,6 @@{+ "picker.offlineGroup": "Offline ({{count}})",+ "picker.thisDevice": "This device","workingDirectory.addFolder": "Add folder…","workingDirectory.addFolderDesc": "Enter an absolute path on the target device, e.g. /Users/name/projects","workingDirectory.addFolderFailed": "Could not add this folder. Please try again.",diff --git a/locales/zh-CN/device.json b/locales/zh-CN/device.jsonindex 73d0cf76c40..70c3ea0888d 100644--- a/locales/zh-CN/device.json+++ b/locales/zh-CN/device.json@@ -1,4 +1,6 @@{+ "picker.offlineGroup": "离线设备({{count}})",+ "picker.thisDevice": "本机","workingDirectory.addFolder": "添加目录…","workingDirectory.addFolderDesc": "输入目标设备上的绝对路径,如 /Users/name/projects","workingDirectory.addFolderFailed": "无法添加此文件夹,请重试。",diff --git a/packages/locales/src/default/device.ts b/packages/locales/src/default/device.tsindex d9b04a613b4..322981105ba 100644--- a/packages/locales/src/default/device.ts+++ b/packages/locales/src/default/device.ts@@ -1,4 +1,6 @@export default {+ 'picker.offlineGroup': 'Offline ({{count}})',+ 'picker.thisDevice': 'This device','workingDirectory.newFolderCreated': 'Created folder: {{path}}','workingDirectory.newFolderInvalidWindowsName':'Use a Windows folder name without reserved names (such as CON), special characters (< > : " / \\ | ? *), control characters, or a trailing space or period.',diff --git a/src/features/AgentTasks/features/TaskDeviceChip.tsx b/src/features/AgentTasks/features/TaskDeviceChip.tsxindex aa65a3aa8ea..63bb3b7f284 100644--- a/src/features/AgentTasks/features/TaskDeviceChip.tsx+++ b/src/features/AgentTasks/features/TaskDeviceChip.tsx@@ -7,6 +7,12 @@ import { memo, useCallback, useState } from 'react';import { useTranslation } from 'react-i18next';import { formatLockedControlTooltip } from '@/features/ChatInput/utils/lockedControlTooltip';+import {+ isCurrentMachineDevice,+ splitPickerDevices,+ useCurrentMachine,+} from '@/features/DeviceManager/devicePicker';+import { OfflineDevicesToggle } from '@/features/DeviceManager/OfflineDevicesToggle';import { ExecutionTargetDeviceStatus, ExecutionTargetIcon } from '@/features/ExecutionTargetPicker';import { taskExecutionStyles as styles } from './taskExecutionStyles';@@ -73,8 +79,10 @@ const TaskDeviceChip = memo<TaskDeviceChipProps>(onFollowChange,value,}) => {- const { t } = useTranslation('chat');+ const { t } = useTranslation(['chat', 'device']);const [open, setOpen] = useState(false);+ const [showOffline, setShowOffline] = useState(false);+ const currentMachine = useCurrentMachine();const {canSelect,@@ -134,6 +142,14 @@ const TaskDeviceChip = memo<TaskDeviceChipProps>([canSelect, isLocked, onChange],);+ // This machine first, then reachable devices; offline ones fold away unless pinned.+ const { available, offline } = splitPickerDevices(devices ?? [], currentMachine);+ const visibleDevices = [+ ...available,+ ...offline.filter((device) => device.deviceId === pinnedDeviceId),+ ];+ const foldedDevices = offline.filter((device) => device.deviceId !== pinnedDeviceId);+const renderDeviceRow = (device: DeviceListItem) => {const isActive = device.deviceId === pinnedDeviceId;return (@@ -147,6 +163,9 @@ const TaskDeviceChip = memo<TaskDeviceChipProps>(<Flexbox flex={1} style={{ minWidth: 0 }}><Flexbox horizontal align={'center'} gap={6}><div className={styles.rowTitle}>{deviceLabel(device, unknownLabel)}</div>+ {isCurrentMachineDevice(device, currentMachine) && (+ <span className={styles.badge}>{t('picker.thisDevice', { ns: 'device' })}</span>+ )}{device.deviceId === inheritedDeviceId && (<span className={styles.badge}>{t('taskExecution.agentDefault')}</span>)}@@ -228,7 +247,17 @@ const TaskDeviceChip = memo<TaskDeviceChipProps>(</div>)}{!isPending && !devicesFailed && devices && devices.length > 0 && (- <div className={styles.scroll}>{devices.map(renderDeviceRow)}</div>+ <div className={styles.scroll}>+ {visibleDevices.map(renderDeviceRow)}+ {foldedDevices.length > 0 && (+ <OfflineDevicesToggle+ count={foldedDevices.length}+ expanded={showOffline}+ onToggle={() => setShowOffline((v) => !v)}+ />+ )}+ {showOffline && foldedDevices.map(renderDeviceRow)}+ </div>)}{!isPending && !devicesFailed && devices?.length === 0 && (<div className={styles.emptyHint}>{t('heteroAgent.executionTarget.noDevices')}</div>diff --git a/src/features/Channels/CreateChannel/EnvironmentFields.tsx b/src/features/Channels/CreateChannel/EnvironmentFields.tsxindex 9e6b5dc62fc..ef8a0fded49 100644--- a/src/features/Channels/CreateChannel/EnvironmentFields.tsx+++ b/src/features/Channels/CreateChannel/EnvironmentFields.tsx@@ -1,10 +1,19 @@import type { DeviceListItem } from '@lobechat/types';-import { Button, Select, Text } from '@lobehub/ui';+import { Button, Flexbox, Select, Tag, Text } from '@lobehub/ui';import * as stylex from '@stylexjs/stylex';import { FolderOpen } from 'lucide-react';+import { useState } from 'react';import { useTranslation } from 'react-i18next';import AsyncError from '@/components/AsyncError';+import {+ isCurrentMachineDevice,+ isDeviceOffline,+ splitPickerDevices,+ useCurrentMachine,+} from '@/features/DeviceManager/devicePicker';+import { getDeviceIcon } from '@/features/DeviceManager/getDeviceIcon';+import { OfflineDevicesToggle } from '@/features/DeviceManager/OfflineDevicesToggle';import { openPickWorkingDirModal } from '@/features/WorkingDirectory';import type { DeviceListResult } from '@/store/device/useDeviceList';@@ -30,7 +39,48 @@ export const EnvironmentFields = ({devices: DeviceListResult;name: string;}) => {- const { t } = useTranslation('channel');+ const { t } = useTranslation(['channel', 'device']);+ const currentMachine = useCurrentMachine();+ const [showOffline, setShowOffline] = useState(false);+ // This computer first, then reachable devices; offline ones fold into one+ // group at the end unless one of them is the pick.+ const folds = (device: DeviceListItem) =>+ devices.isConfirmed && isDeviceOffline(device) && device.deviceId !== draft.deviceId;+ const { available, offline } = splitPickerDevices(devices.data ?? [], currentMachine);+ const visibleDevices = [...available, ...offline].filter((device) => !folds(device));+ const foldedDevices = offline.filter(folds);+ const deviceOption = (device: DeviceListItem) => {+ const suffix =+ !devices.isConfirmed || device.onlineUnknown+ ? t('environment.checkingDevice')+ : device.online+ ? ''+ : t('offline');+ return {+ disabled:+ !devices.isConfirmed ||+ !device.online ||+ !!device.onlineUnknown ||+ (device.scope === 'workspace' && device.visibility !== 'public'),+ label: (+ <Flexbox horizontal align={'center'} gap={8} style={{ minWidth: 0 }}>+ {getDeviceIcon(device.platform, 14)}+ <Text ellipsis>{deviceLabel(device)}</Text>+ {isCurrentMachineDevice(device, currentMachine) && (+ <Tag size={'small'} style={{ flex: 'none' }}>+ {t('picker.thisDevice', { ns: 'device' })}+ </Tag>+ )}+ {suffix && (+ <Text fontSize={12} style={{ flex: 'none' }} type={'secondary'}>+ {suffix}+ </Text>+ )}+ </Flexbox>+ ),+ value: device.deviceId,+ };+ };const missingDevice =draft.deviceId && !devices.data?.some((item) => item.deviceId === draft.deviceId);const canChooseDirectory =@@ -66,15 +116,21 @@ export const EnvironmentFields = ({},]: []),- ...(devices.data ?? []).map((device) => ({- disabled:- !devices.isConfirmed ||- !device.online ||- !!device.onlineUnknown ||- (device.scope === 'workspace' && device.visibility !== 'public'),- label: `${deviceLabel(device)}${!devices.isConfirmed || device.onlineUnknown ? ` · ${t('environment.checkingDevice')}` : device.online ? '' : ` · ${t('offline')}`}`,- value: device.deviceId,- })),+ ...visibleDevices.map(deviceOption),+ ...(foldedDevices.length > 0+ ? [+ {+ label: (+ <OfflineDevicesToggle+ count={foldedDevices.length}+ expanded={showOffline}+ onToggle={() => setShowOffline((v) => !v)}+ />+ ),+ options: showOffline ? foldedDevices.map(deviceOption) : [],+ },+ ]+ : []),]}onChange={changeDevice}/>diff --git a/src/features/ChatInput/ControlBar/DeviceGroupSubmenu.tsx b/src/features/ChatInput/ControlBar/DeviceGroupSubmenu.tsxindex b8417a4fd77..03a7c553bd4 100644--- a/src/features/ChatInput/ControlBar/DeviceGroupSubmenu.tsx+++ b/src/features/ChatInput/ControlBar/DeviceGroupSubmenu.tsx@@ -3,7 +3,10 @@import type { DeviceListItem } from '@lobechat/types';import { Icon } from '@lobehub/ui';import { Building2Icon, LockKeyholeIcon, MonitorSmartphoneIcon } from 'lucide-react';-import { memo, type ReactNode } from 'react';+import { memo, type ReactNode, useState } from 'react';++import { isDeviceOffline } from '@/features/DeviceManager/devicePicker';+import { OfflineDevicesToggle } from '@/features/DeviceManager/OfflineDevicesToggle';import { summarizeDeviceGroup } from './deviceGroupSummary';import GroupSubmenu from './GroupSubmenu';@@ -34,6 +37,11 @@ interface DeviceGroupSubmenuProps {const DeviceGroupSubmenu = memo<DeviceGroupSubmenuProps>(({ activeDeviceId, devices, kind, label, renderDevice }) => {const { activeDevice } = summarizeDeviceGroup(devices, activeDeviceId);+ const [showOffline, setShowOffline] = useState(false);+ // Reachable machines first; offline ones fold away unless one is the pick.+ const folds = (d: DeviceListItem) => isDeviceOffline(d) && d.deviceId !== activeDeviceId;+ const visible = devices.filter((d) => !folds(d));+ const folded = devices.filter(folds);return (<GroupSubmenu@@ -43,7 +51,15 @@ const DeviceGroupSubmenu = memo<DeviceGroupSubmenuProps>(label={label}testId={`device-group-${kind}`}>- {devices.map((d) => renderDevice(d))}+ {visible.map((d) => renderDevice(d))}+ {folded.length > 0 && (+ <OfflineDevicesToggle+ count={folded.length}+ expanded={showOffline}+ onToggle={() => setShowOffline((v) => !v)}+ />+ )}+ {showOffline && folded.map((d) => renderDevice(d))}</GroupSubmenu>);},diff --git a/src/features/ChatInput/ControlBar/ProjectDeviceSwitcher.tsx b/src/features/ChatInput/ControlBar/ProjectDeviceSwitcher.tsxindex 78486e8ac5e..7eba5b31912 100644--- a/src/features/ChatInput/ControlBar/ProjectDeviceSwitcher.tsx+++ b/src/features/ChatInput/ControlBar/ProjectDeviceSwitcher.tsx@@ -10,6 +10,8 @@ import { useTranslation } from 'react-i18next';import RepositoryAvatar from '@/components/RepositoryAvatar';import { useChatInputResourceAccess } from '@/features/ChatInput/hooks/useChatInputResourceAccess';import DeviceLoadMeter, { useDeviceLoad } from '@/features/DeviceManager/DeviceLoadMeter';+import { isCurrentMachineDevice, useCurrentMachine } from '@/features/DeviceManager/devicePicker';+import { OfflineDevicesToggle } from '@/features/DeviceManager/OfflineDevicesToggle';import { ExecutionTargetDeviceStatus, ExecutionTargetIcon } from '@/features/ExecutionTargetPicker';import { getProjectSettingsPath } from '@/features/Projects/Layout/navigation';import { useProjectExecutionEnvironments } from '@/features/Projects/WorkingDirectories/useProjectExecutionEnvironments';@@ -102,9 +104,11 @@ const ProjectDeviceSwitcher = ({projectId: projectIdProp,sandbox,}: ProjectDeviceSwitcherProps) => {- const { t } = useTranslation('chat');+ const { t } = useTranslation(['chat', 'device']);const navigate = useWorkspaceAwareNavigate();const [open, setOpen] = useState(false);+ const [showOffline, setShowOffline] = useState(false);+ const currentMachine = useCurrentMachine();const { canUseResource } = useChatInputResourceAccess();const directory = directories.find((d) => d.id === directoryId);const projectId = projectIdProp ?? directories[0]?.projectId;@@ -136,6 +140,13 @@ const ProjectDeviceSwitcher = ({...targets.map((target) => ({ id: target.directory.id, kind: 'directory' as const })),];+ const isCurrent = (target: ProjectDeviceTarget) =>+ !!target.device && isCurrentMachineDevice(target.device, currentMachine);+ // The project's order stays; offline devices fold away at the end unless one is the pick.+ const isFolded = (target: ProjectDeviceTarget) =>+ !target.online && !target.onlineUnknown && !target.active;+ const offlineTargets = targets.filter(isFolded);+const handleSelect = (target: ProjectDeviceTarget) => {setOpen(false);if (!target.active) onSelect?.(target);@@ -176,7 +187,6 @@ const ProjectDeviceSwitcher = ({icon={<ExecutionTargetIcon devicePlatform={target.directory.platform} target={'device'} />}key={target.directory.id}label={target.label}- tags={target.active && activeTag ? [activeTag] : []}desc={target.allowed ? (<>@@ -195,6 +205,10 @@ const ProjectDeviceSwitcher = ({<span {...stylex.props(styles.desc)}>{t('heteroAgent.executionTarget.fixedTip')}</span>)}+ tags={[+ ...(isCurrent(target) ? [t('picker.thisDevice', { ns: 'device' })] : []),+ ...(target.active && activeTag ? [activeTag] : []),+ ]}onClick={() => (selectable ? handleSelect(target) : undefined)}/>);@@ -230,8 +244,16 @@ const ProjectDeviceSwitcher = ({{rows.map((item) => {if (item.kind === 'sandbox') return sandboxRow;const target = targetById.get(item.id);- return target ? renderTarget(target) : null;+ return target && !isFolded(target) ? renderTarget(target) : null;})}+ {offlineTargets.length > 0 && (+ <OfflineDevicesToggle+ count={offlineTargets.length}+ expanded={showOffline}+ onToggle={() => setShowOffline((v) => !v)}+ />+ )}+ {showOffline && offlineTargets.map(renderTarget)}</Flexbox>);diff --git a/src/features/ChatInput/ControlBar/__tests__/DeviceGroupSubmenu.test.tsx b/src/features/ChatInput/ControlBar/__tests__/DeviceGroupSubmenu.test.tsxindex 8a1648e978f..b116b18cbb8 100644--- a/src/features/ChatInput/ControlBar/__tests__/DeviceGroupSubmenu.test.tsx+++ b/src/features/ChatInput/ControlBar/__tests__/DeviceGroupSubmenu.test.tsx@@ -58,7 +58,10 @@ describe('DeviceGroupSubmenu', () => {const submenu = screen.getByTestId('submenu');expect(submenu.textContent).toContain('row:hetzner');expect(submenu.textContent).toContain('row:zeabur');- expect(submenu.textContent).toContain('row:lin-pc');+ // Offline machines fold behind a toggle at the end of the submenu.+ expect(submenu.textContent).not.toContain('row:lin-pc');+ fireEvent.click(screen.getByRole('button', { expanded: false }));+ expect(screen.getByTestId('submenu').textContent).toContain('row:lin-pc');});it('names the picked device on the first level when it is in the group', () => {diff --git a/src/features/ChatTerminal/Content.tsx b/src/features/ChatTerminal/Content.tsxindex eaebc2bad21..3788417e96d 100644--- a/src/features/ChatTerminal/Content.tsx+++ b/src/features/ChatTerminal/Content.tsx@@ -25,6 +25,7 @@ import {import { memo, useEffect, useRef } from 'react';import { useTranslation } from 'react-i18next';+import { useCurrentMachine } from '@/features/DeviceManager/devicePicker';import { useChatStore } from '@/store/chat';import { useGlobalStore } from '@/store/global';import { densityVars } from '@/styles/densityVars';@@ -90,7 +91,7 @@ const styles = createStaticStyles(({ css, cssVar }) => ({}));const Content = memo(() => {- const { t } = useTranslation('chat');+ const { t } = useTranslation(['chat', 'device']);const topicId = useChatStore((s) => s.activeTopicId);const agentId = useChatStore((s) => s.activeAgentId);@@ -112,6 +113,7 @@ const Content = memo(() => {const setActivePane = useChatTerminalStore((s) => s.setActivePane);const setPaneFlex = useChatTerminalStore((s) => s.setPaneFlex);+ const currentMachine = useCurrentMachine();const { canSpawn, cwd, selectTarget, targetDeviceId, targets } = useTerminalTarget(topicKey,agentId || undefined,@@ -153,10 +155,11 @@ const Content = memo(() => {},];- const targetOptions = buildTargetOptions(- targets,- isDesktop ? t('terminalPanel.targetLocal') : undefined,- );+ // This computer goes by its own name, tagged, as in every other device picker.+ const localLabel = currentMachine.hostname+ ? `${currentMachine.hostname} · ${t('picker.thisDevice', { ns: 'device' })}`+ : t('terminalPanel.targetLocal');+ const targetOptions = buildTargetOptions(targets, isDesktop ? localLabel : undefined);return (<Flexbox className={styles.container}>diff --git a/src/features/ChatTerminal/useTerminalTarget.test.ts b/src/features/ChatTerminal/useTerminalTarget.test.tsindex 824e947e62c..75a1807fcc0 100644--- a/src/features/ChatTerminal/useTerminalTarget.test.ts+++ b/src/features/ChatTerminal/useTerminalTarget.test.ts@@ -39,6 +39,10 @@ vi.mock('@/store/electron', () => ({useElectronStore: (selector: (s: unknown) => unknown) =>selector({ gatewayDeviceInfo: { deviceId: env.currentDeviceId } }),}));+vi.mock('@/features/DeviceManager/devicePicker', async (importOriginal) => ({+ ...(await importOriginal<object>()),+ useCurrentMachine: () => ({ ids: env.currentDeviceId ? [env.currentDeviceId] : [] }),+}));vi.mock('@/store/device', async (importOriginal) => ({...(await importOriginal<object>()),useDeviceStore: Object.assign(diff --git a/src/features/ChatTerminal/useTerminalTarget.ts b/src/features/ChatTerminal/useTerminalTarget.tsindex f94b7f8e87e..ab71977c20e 100644--- a/src/features/ChatTerminal/useTerminalTarget.ts+++ b/src/features/ChatTerminal/useTerminalTarget.ts@@ -2,6 +2,7 @@ import { isDesktop } from '@lobechat/const';import type { DeviceListItem } from '@lobechat/types';import { useMemo } from 'react';+import { isCurrentMachineDevice, useCurrentMachine } from '@/features/DeviceManager/devicePicker';import { resolveTargetDeviceId } from '@/helpers/agentWorkingDirectory';import { resolveExecutionTarget } from '@/helpers/executionTarget';import { useIsGatewayModeEnabled } from '@/helpers/gatewayMode';@@ -60,12 +61,14 @@ export const useTerminalTarget = (topicKey: string, agentId?: string): TerminalT// live connections are all from a desktop without terminal support, answers// a terminal RPC with a refusal — offering it would fail the session the// moment it is claimed. This desktop's own row is "this machine" already.+ const currentMachine = useCurrentMachine();const targets = useMemo(() =>devices.filter(- (device) => canHostTerminal(device) && !(isDesktop && device.deviceId === currentDeviceId),+ (device) =>+ canHostTerminal(device) && !(isDesktop && isCurrentMachineDevice(device, currentMachine)),),- [devices, currentDeviceId],+ [devices, currentMachine],);const { deviceId: targetDeviceId, ready: canSpawn } = resolveTerminalDevice({configLoading: isPreferenceLoading,diff --git a/src/features/ConnectAgent/DeviceSwitch.tsx b/src/features/ConnectAgent/DeviceSwitch.tsxnew file mode 100644index 00000000000..be8c6a21e2b--- /dev/null+++ b/src/features/ConnectAgent/DeviceSwitch.tsx@@ -0,0 +1,115 @@+'use client';++import type { DeviceListItem } from '@lobechat/types';+import { Flexbox, Icon, Select, Tag, Text } from '@lobehub/ui';+import { LaptopIcon } from 'lucide-react';+import { memo, useState } from 'react';+import { useTranslation } from 'react-i18next';++import { getDeviceIcon } from '@/features/DeviceManager/getDeviceIcon';+import { OfflineDevicesToggle } from '@/features/DeviceManager/OfflineDevicesToggle';++import type { ScanTarget } from './useAgentScan';++/**+ * The switch's value for this computer. Not empty: the select reads an empty+ * value as no selection and would show a blank trigger.+ */+const LOCAL_TARGET_VALUE = '__local__';++const deviceLabel = (device: DeviceListItem) =>+ device.friendlyName || device.hostname || device.deviceId;++interface DeviceSwitchProps {+ /** Other devices that are online or still being checked. */+ available: DeviceListItem[];+ localLabel: string;+ /** This computer's own row, when listed: it lends the local option its icon. */+ localRow?: DeviceListItem;+ offline: DeviceListItem[];+ onPick: (target: ScanTarget) => void;+ target: ScanTarget;+}++/** "Runs on": this computer first and tagged, other devices after, offline ones folded. */+export const DeviceSwitch = memo<DeviceSwitchProps>(+ ({ available, localLabel, localRow, offline, onPick, target }) => {+ const { t } = useTranslation(['chat', 'device']);+ const [showOffline, setShowOffline] = useState(false);+ // An offline device stays visible while it is the one picked.+ const offlineExpanded =+ showOffline ||+ (target.kind === 'device' && offline.some((d) => d.deviceId === target.device.deviceId));++ const deviceOption = (device: DeviceListItem) => ({+ disabled: !device.online,+ label: (+ <Flexbox horizontal align={'center'} gap={8}>+ {getDeviceIcon(device.platform, 14)}+ <span>{deviceLabel(device)}</span>+ {!device.online && (+ <Text fontSize={12} type={'secondary'}>+ {t('connectAgent.create.offline')}+ </Text>+ )}+ </Flexbox>+ ),+ value: device.deviceId,+ });++ return (+ <Flexbox horizontal align={'center'} gap={8} style={{ paddingInline: 4 }}>+ <Text fontSize={12} style={{ flex: 'none' }} type={'secondary'}>+ {t('connectAgent.create.switchDevice')}+ </Text>+ <Select+ aria-label={t('connectAgent.create.switchDevice')}+ popupMatchSelectWidth={false}+ size={'small'}+ style={{ minWidth: 180 }}+ value={target.kind === 'device' ? target.device.deviceId : LOCAL_TARGET_VALUE}+ options={[+ {+ label: (+ <Flexbox horizontal align={'center'} gap={8}>+ {localRow ? (+ getDeviceIcon(localRow.platform, 14)+ ) : (+ <Icon icon={LaptopIcon} size={14} />+ )}+ <span>{localLabel}</span>+ <Tag size={'small'} style={{ flex: 'none' }}>+ {t('picker.thisDevice', { ns: 'device' })}+ </Tag>+ </Flexbox>+ ),+ value: LOCAL_TARGET_VALUE,+ },+ ...available.map(deviceOption),+ ...(offline.length > 0+ ? [+ {+ label: (+ <OfflineDevicesToggle+ count={offline.length}+ expanded={offlineExpanded}+ onToggle={() => setShowOffline((v) => !v)}+ />+ ),+ options: offlineExpanded ? offline.map(deviceOption) : [],+ },+ ]+ : []),+ ]}+ onChange={(value) => {+ if (value === LOCAL_TARGET_VALUE) return onPick({ kind: 'local' });+ const device = [...available, ...offline].find((d) => d.deviceId === value);+ if (device) onPick({ device, kind: 'device' });+ }}+ />+ </Flexbox>+ );+ },+);++DeviceSwitch.displayName = 'ConnectAgentDeviceSwitch';diff --git a/src/features/ConnectAgent/index.tsx b/src/features/ConnectAgent/index.tsxindex d923b555174..82d7779087f 100644--- a/src/features/ConnectAgent/index.tsx+++ b/src/features/ConnectAgent/index.tsx@@ -21,7 +21,6 @@ import {Input,type ModalInstance,ScrollArea,- Select,Text,TextArea,Tooltip,@@ -49,17 +48,23 @@ import CreateVisibilityField, {type CreateVisibility,useCreateVisibility,} from '@/features/CreateVisibilityField';+import {+ isCurrentMachineDevice,+ splitPickerDevices,+ useCurrentMachine,+} from '@/features/DeviceManager/devicePicker';import { getDeviceIcon } from '@/features/DeviceManager/getDeviceIcon';+import { OfflineDevicesToggle } from '@/features/DeviceManager/OfflineDevicesToggle';import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';import { deviceService } from '@/services/device';import { useAgentStore } from '@/store/agent';import { heteroAgentDefaultName } from '@/store/agent/utils/heteroAgentDefaultName';import { isDevicePresenceUnknown, useDeviceList } from '@/store/device';-import { useElectronStore } from '@/store/electron';import { useHomeStore } from '@/store/home';import { densityVars } from '@/styles/densityVars';import { getDeviceListState, isListableDevice } from './deviceListState';+import { DeviceSwitch } from './DeviceSwitch';import type { ConnectableProvider, ConnectAgentProfile } from './providers';import { buildConnectAgentConfig, CONNECTABLE_PROVIDERS } from './providers';import type { ScanTarget } from './useAgentScan';@@ -269,9 +274,6 @@ interface CreatedAgent {version?: string;}-/** The device switch's value for this computer; device ids are never empty. */-const LOCAL_TARGET_VALUE = '';-const SectionLabel = memo<{ children: ReactNode }>(({ children }) => (<Text fontSize={12} style={{ paddingInline: 4 }} type={'secondary'}>{children}@@ -398,7 +400,7 @@ const ConnectAgentContent = memo<ConnectAgentContentProps>(showOpenChat = true,visibility: initialVisibility,}) => {- const { t } = useTranslation('chat');+ const { t } = useTranslation(['chat', 'device']);// Same "Private / Workspace" field as the create-agent form; the caller's// value is only where it starts.const visibilityState = useCreateVisibility({ groupId, visibility: initialVisibility });@@ -406,7 +408,9 @@ const ConnectAgentContent = memo<ConnectAgentContentProps>(const { close, setCanDismissByClickOutside } = useModalContext();const navigate = useWorkspaceAwareNavigate();const storeCreateAgent = useAgentStore((s) => s.createAgent);- const currentDeviceId = useElectronStore((s) => s.gatewayDeviceInfo?.deviceId);+ const currentMachine = useCurrentMachine();+ const currentDeviceId = currentMachine.ids[0];+ const [showOffline, setShowOffline] = useState(false);const refreshAgentList = useHomeStore((s) => s.refreshAgentList);// Workspace agents must bind workspace devices: a workspace agent on a@@ -455,16 +459,28 @@ const ConnectAgentContent = memo<ConnectAgentContentProps>(mutate: refetchDevices,} = useDeviceList();- // This computer is offered as "This computer" already, so its gateway row is left out.- const listedDevices = useMemo(+ const listableDevices = useMemo(+ () => (devices ?? []).filter((d) => isListableDevice(d, restrictToWorkspaceDevices)),+ [devices, restrictToWorkspaceDevices],+ );+ // This computer is offered as the local option already, so its own row is+ // left out — it lends that option its name instead.+ const { available, offline } = useMemo(() =>- (devices ?? []).filter(- (d) =>- isListableDevice(d, restrictToWorkspaceDevices) &&- !(isDesktop && d.deviceId === currentDeviceId),+ splitPickerDevices(+ listableDevices.filter((d) => !(isDesktop && isCurrentMachineDevice(d, currentMachine))),+ currentMachine,),- [currentDeviceId, devices, restrictToWorkspaceDevices],+ [currentMachine, listableDevices],);+ const localRow = useMemo(+ () =>+ isDesktop+ ? listableDevices.find((d) => isCurrentMachineDevice(d, currentMachine))+ : undefined,+ [currentMachine, listableDevices],+ );+ const listedDevices = useMemo(() => [...available, ...offline], [available, offline]);const onlineDevices = listedDevices.filter((d) => d.online);// Rows painted from the persisted list until the server confirms presence:// none of them is offline yet, so "no devices" would be a guess.@@ -475,8 +491,11 @@ const ConnectAgentContent = memo<ConnectAgentContentProps>([],);- const targetLabel =- target?.kind === 'device' ? deviceLabel(target.device) : t('connectAgent.create.localDevice');+ // This computer goes by its own name once its row is known, so it never reads+ // as a second machine next to that row.+ const localLabel = localRow ? deviceLabel(localRow) : t('connectAgent.create.localDevice');++ const targetLabel = target?.kind === 'device' ? deviceLabel(target.device) : localLabel;const inventory = useMemo(() => {if (scanState.status !== 'success' || !scanState.agents) return [];@@ -784,10 +803,16 @@ const ConnectAgentContent = memo<ConnectAgentContentProps>(<SectionLabel>{t('connectAgent.create.thisDevice')}</SectionLabel><Surface padded={false}><DeviceRow- icon={<Icon icon={LaptopIcon} size={18} />}statusText={t('connectAgent.create.online')}subtitle={t('connectAgent.create.localDeviceDesc')}- title={t('connectAgent.create.localDevice')}+ title={localLabel}+ icon={+ localRow ? (+ getDeviceIcon(localRow.platform, 18)+ ) : (+ <Icon icon={LaptopIcon} size={18} />+ )+ }onClick={() => pickTarget({ kind: 'local' })}/></Surface>@@ -819,23 +844,32 @@ const ConnectAgentContent = memo<ConnectAgentContentProps>(<SkeletonRow squareIcon key={width} width={width} />))) : (- listedDevices.map((device) => (- <DeviceRow- icon={getDeviceIcon(device.platform, 18)}- key={device.deviceId}- offline={!device.online}- subtitle={device.hostname || device.deviceId}- title={deviceLabel(device)}- statusText={- isDevicePresenceUnknown(device)- ? t('heteroAgent.executionTarget.presenceChecking')- : device.online- ? t('connectAgent.create.online')- : t('connectAgent.create.offline')- }- onClick={() => pickTarget({ device, kind: 'device' })}- />- ))+ [...available, ...(showOffline || available.length === 0 ? offline : [])].map(+ (device) => (+ <DeviceRow+ icon={getDeviceIcon(device.platform, 18)}+ key={device.deviceId}+ offline={!device.online}+ subtitle={device.hostname || device.deviceId}+ title={deviceLabel(device)}+ statusText={+ isDevicePresenceUnknown(device)+ ? t('heteroAgent.executionTarget.presenceChecking')+ : device.online+ ? t('connectAgent.create.online')+ : t('connectAgent.create.offline')+ }+ onClick={() => pickTarget({ device, kind: 'device' })}+ />+ ),+ )+ )}+ {deviceListState === 'ready' && available.length > 0 && offline.length > 0 && (+ <OfflineDevicesToggle+ count={offline.length}+ expanded={showOffline}+ onToggle={() => setShowOffline((v) => !v)}+ />)}</Surface></Flexbox>@@ -884,49 +918,14 @@ const ConnectAgentContent = memo<ConnectAgentContentProps>(</Flexbox>{deviceInline && listedDevices.length > 0 && (- <Flexbox horizontal align={'center'} gap={8} style={{ paddingInline: 4 }}>- <Text fontSize={12} style={{ flex: 'none' }} type={'secondary'}>- {t('connectAgent.create.switchDevice')}- </Text>- <Select- aria-label={t('connectAgent.create.switchDevice')}- popupMatchSelectWidth={false}- size={'small'}- style={{ minWidth: 180 }}- value={target.kind === 'device' ? target.device.deviceId : LOCAL_TARGET_VALUE}- options={[- {- label: (- <Flexbox horizontal align={'center'} gap={8}>- <Icon icon={LaptopIcon} size={14} />- {t('connectAgent.create.localDevice')}- </Flexbox>- ),- value: LOCAL_TARGET_VALUE,- },- ...listedDevices.map((device) => ({- disabled: !device.online,- label: (- <Flexbox horizontal align={'center'} gap={8}>- {getDeviceIcon(device.platform, 14)}- <span>{deviceLabel(device)}</span>- {!device.online && (- <Text fontSize={12} type={'secondary'}>- {t('connectAgent.create.offline')}- </Text>- )}- </Flexbox>- ),- value: device.deviceId,- })),- ]}- onChange={(value: string) => {- if (value === LOCAL_TARGET_VALUE) return pickTarget({ kind: 'local' });- const device = listedDevices.find((d) => d.deviceId === value);- if (device) pickTarget({ device, kind: 'device' });- }}- />- </Flexbox>+ <DeviceSwitch+ available={available}+ localLabel={localLabel}+ localRow={localRow}+ offline={offline}+ target={target}+ onPick={pickTarget}+ />)}{scanning && (diff --git a/src/features/DeviceManager/OfflineDevicesToggle.tsx b/src/features/DeviceManager/OfflineDevicesToggle.tsxnew file mode 100644index 00000000000..7c7f5f1f5b6--- /dev/null+++ b/src/features/DeviceManager/OfflineDevicesToggle.tsx@@ -0,0 +1,66 @@+'use client';++import { Icon } from '@lobehub/ui';+import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';+import * as stylex from '@stylexjs/stylex';+import { ChevronRightIcon } from 'lucide-react';+import { memo } from 'react';+import { useTranslation } from 'react-i18next';++const styles = stylex.create({+ chevron: { display: 'flex', transition: 'transform 150ms ease' },+ chevronOpen: { transform: 'rotate(90deg)' },+ toggle: {+ cursor: 'pointer',++ display: 'flex',+ gap: '4px',+ alignItems: 'center',++ width: '100%',+ paddingBlock: '4px',+ paddingInline: '8px',+ borderStyle: 'none',++ fontSize: '12px',+ color: { 'default': cssVar.colorTextTertiary, ':hover': cssVar.colorTextSecondary },+ textAlign: 'start',++ backgroundColor: 'transparent',+ },+});++interface OfflineDevicesToggleProps {+ count: number;+ expanded: boolean;+ onToggle: () => void;+}++/** The folded "Offline (n)" header every device picker puts its offline devices under. */+export const OfflineDevicesToggle = memo<OfflineDevicesToggleProps>(+ ({ count, expanded, onToggle }) => {+ const { t } = useTranslation('device');++ return (+ <button+ aria-expanded={expanded}+ type={'button'}+ {...stylex.props(styles.toggle)}+ // Inside a select popup a press must not reach the list, which would close it.+ onPointerDown={(event) => event.stopPropagation()}+ onClick={(event) => {+ event.preventDefault();+ event.stopPropagation();+ onToggle();+ }}+ >+ <span {...stylex.props(styles.chevron, expanded && styles.chevronOpen)}>+ <Icon icon={ChevronRightIcon} size={12} />+ </span>+ {t('picker.offlineGroup', { count })}+ </button>+ );+ },+);++OfflineDevicesToggle.displayName = 'OfflineDevicesToggle';diff --git a/src/features/DeviceManager/devicePicker.test.ts b/src/features/DeviceManager/devicePicker.test.tsnew file mode 100644index 00000000000..bb5f112ecff--- /dev/null+++ b/src/features/DeviceManager/devicePicker.test.ts@@ -0,0 +1,49 @@+import type { DeviceListItem } from '@lobechat/types';+import { describe, expect, it } from 'vitest';++import { isCurrentMachineDevice, splitPickerDevices } from './devicePicker';++const device = (deviceId: string, patch: Partial<DeviceListItem> = {}) =>+ ({ deviceId, hostname: deviceId, online: true, ...patch }) as DeviceListItem;++describe('isCurrentMachineDevice', () => {+ it('matches by any of the machine ids', () => {+ expect(isCurrentMachineDevice(device('a'), { ids: ['b', 'a'] })).toBe(true);+ expect(isCurrentMachineDevice(device('c'), { ids: ['b', 'a'] })).toBe(false);+ });++ it('falls back to the hostname only for an online row', () => {+ const machine = { hostname: 'WIN', ids: ['x'] };+ expect(isCurrentMachineDevice(device('ws', { hostname: 'WIN' }), machine)).toBe(true);+ expect(+ isCurrentMachineDevice(device('stale', { hostname: 'WIN', online: false }), machine),+ ).toBe(false);+ });+});++describe('splitPickerDevices', () => {+ it('puts this machine first and separates offline devices', () => {+ const result = splitPickerDevices(+ [+ device('mac'),+ device('old', { online: false }),+ device('win'),+ device('checking', { online: false, onlineUnknown: true }),+ ],+ { ids: ['win'] },+ );++ expect(result.current?.deviceId).toBe('win');+ expect(result.available.map((d) => d.deviceId)).toEqual(['win', 'mac', 'checking']);+ expect(result.offline.map((d) => d.deviceId)).toEqual(['old']);+ });++ it('prefers an id match over a hostname match', () => {+ const result = splitPickerDevices(+ [device('ws', { hostname: 'WIN' }), device('win', { hostname: 'WIN' })],+ { hostname: 'WIN', ids: ['win'] },+ );++ expect(result.current?.deviceId).toBe('win');+ });+});diff --git a/src/features/DeviceManager/devicePicker.ts b/src/features/DeviceManager/devicePicker.tsnew file mode 100644index 00000000000..7ea99fa38a0--- /dev/null+++ b/src/features/DeviceManager/devicePicker.ts@@ -0,0 +1,85 @@+import { isDesktop } from '@lobechat/const';+import type { DeviceListItem } from '@lobechat/types';+import { useMemo } from 'react';++import { useLocalMachineDeviceIds } from '@/hooks/useLocalMachineDeviceIds';+import { isDevicePresenceUnknown } from '@/store/device';+import { useElectronStore } from '@/store/electron';+import { electronGatewaySelectors } from '@/store/electron/selectors';++/** How the app recognises the machine it runs on among the listed devices. */+export interface CurrentMachine {+ hostname?: string;+ /**+ * Every id this machine holds: its resolved stable id, the gateway's reported+ * one (they differ before the gateway connects), and its row in the active+ * workspace.+ */+ ids: string[];+}++const NO_MACHINE: CurrentMachine = { ids: [] };++/**+ * This desktop's identity, for every picker that lists devices: one place that+ * loads it, so no picker reads a gateway id nobody fetched and lists this+ * machine twice. Empty on web.+ */+export const useCurrentMachine = (): CurrentMachine => {+ useElectronStore((s) => s.useFetchGatewayStableDeviceId)();+ const localIds = useLocalMachineDeviceIds();+ const hostname = useElectronStore((s) => s.gatewayDeviceInfo?.hostname);+ const stableId = useElectronStore(electronGatewaySelectors.gatewayStableDeviceId);++ return useMemo(() => {+ if (!isDesktop) return NO_MACHINE;+ const ids = [stableId, ...localIds].filter((id): id is string => !!id);+ return { hostname, ids: [...new Set(ids)] };+ }, [hostname, localIds, stableId]);+};++/**+ * Whether a listed device is this machine. The id is the reliable signal; the+ * hostname covers a row enrolled under an identity this desktop has not+ * resolved yet, and only while online, so a stale row of an old install is not+ * mistaken for the running one.+ */+export const isCurrentMachineDevice = (device: DeviceListItem, machine: CurrentMachine): boolean =>+ machine.ids.includes(device.deviceId) ||+ (!!machine.hostname && device.online && device.hostname === machine.hostname);++/** A device that is known to be offline — not one still waiting on its first presence check. */+export const isDeviceOffline = (device: DeviceListItem): boolean =>+ !device.online && !isDevicePresenceUnknown(device);++export interface PickerDevices {+ /** Online (or still being checked) devices, this machine first. */+ available: DeviceListItem[];+ /** This machine's row, when it is listed. */+ current?: DeviceListItem;+ /** Offline devices, which pickers fold away by default. */+ offline: DeviceListItem[];+}++/** Splits a device list the way every picker shows it: this machine, then reachable, then offline. */+export const splitPickerDevices = (+ devices: DeviceListItem[],+ machine: CurrentMachine,+): PickerDevices => {+ const current =+ devices.find((device) => machine.ids.includes(device.deviceId)) ??+ devices.find((device) => isCurrentMachineDevice(device, machine));+ const rest = devices.filter((device) => device !== current);++ return {+ available: [+ ...(current && !isDeviceOffline(current) ? [current] : []),+ ...rest.filter((device) => !isDeviceOffline(device)),+ ],+ current,+ offline: [+ ...(current && isDeviceOffline(current) ? [current] : []),+ ...rest.filter(isDeviceOffline),+ ],+ };+};diff --git a/src/features/DeviceManager/useDeviceSelectOptions.tsx b/src/features/DeviceManager/useDeviceSelectOptions.tsxnew file mode 100644index 00000000000..aa965575dab--- /dev/null+++ b/src/features/DeviceManager/useDeviceSelectOptions.tsx@@ -0,0 +1,67 @@+'use client';++import type { DeviceListItem } from '@lobechat/types';+import type { SelectOptions } from '@lobehub/ui';+import { Flexbox, Tag, Text } from '@lobehub/ui';+import { useState } from 'react';+import { useTranslation } from 'react-i18next';++import { isCurrentMachineDevice, splitPickerDevices, useCurrentMachine } from './devicePicker';+import { getDeviceIcon } from './getDeviceIcon';+import { OfflineDevicesToggle } from './OfflineDevicesToggle';++/**+ * Select options for a plain device field, laid out like every other device+ * picker: this computer first and tagged, then reachable devices, offline ones+ * folded into a group at the end unless one of them is `selectedId`.+ */+export const useDeviceSelectOptions = (+ devices: DeviceListItem[],+ selectedId?: string,+): SelectOptions => {+ const { t } = useTranslation(['device', 'chat']);+ const currentMachine = useCurrentMachine();+ const [showOffline, setShowOffline] = useState(false);++ const { available, offline } = splitPickerDevices(devices, currentMachine);+ const folded = offline.filter((device) => device.deviceId !== selectedId);+ const visible = [...available, ...offline.filter((device) => device.deviceId === selectedId)];++ const option = (device: DeviceListItem) => ({+ label: (+ <Flexbox horizontal align={'center'} gap={8} style={{ minWidth: 0 }}>+ {getDeviceIcon(device.platform, 14)}+ <Text ellipsis>{device.friendlyName || device.hostname || device.deviceId}</Text>+ {isCurrentMachineDevice(device, currentMachine) && (+ <Tag size={'small'} style={{ flex: 'none' }}>+ {t('picker.thisDevice')}+ </Tag>+ )}+ {!device.online && !device.onlineUnknown && (+ <Text fontSize={12} style={{ flex: 'none' }} type={'secondary'}>+ {t('heteroAgent.executionTarget.offline', { ns: 'chat' })}+ </Text>+ )}+ </Flexbox>+ ),+ value: device.deviceId,+ });++ return [+ ...visible.map(option),+ ...(folded.length > 0+ ? [+ {+ label: (+ <OfflineDevicesToggle+ count={folded.length}+ expanded={showOffline}+ onToggle={() => setShowOffline((v) => !v)}+ />+ ),+ options: showOffline ? folded.map(option) : [],+ },+ ]+ : []),+ ];+};diff --git a/src/features/HeterogeneousAgent/ExecutionEnvironment/HeteroExecutionTargetSelect.tsx b/src/features/HeterogeneousAgent/ExecutionEnvironment/HeteroExecutionTargetSelect.tsxindex 265500bdabd..cd58157ae8b 100644--- a/src/features/HeterogeneousAgent/ExecutionEnvironment/HeteroExecutionTargetSelect.tsx+++ b/src/features/HeterogeneousAgent/ExecutionEnvironment/HeteroExecutionTargetSelect.tsx@@ -6,11 +6,18 @@ import type { DeviceExecutionTarget, DeviceListItem } from '@lobechat/types';import type { SelectOption, SelectOptions } from '@lobehub/ui';import { Select, Text } from '@lobehub/ui';import * as stylex from '@stylexjs/stylex';-import { memo } from 'react';+import { memo, useState } from 'react';import { useTranslation } from 'react-i18next';import AsyncError from '@/components/AsyncError';import { useSelectExecutionTarget } from '@/features/ChatInput/hooks/useSelectExecutionTarget';+import {+ isCurrentMachineDevice,+ isDeviceOffline,+ splitPickerDevices,+ useCurrentMachine,+} from '@/features/DeviceManager/devicePicker';+import { OfflineDevicesToggle } from '@/features/DeviceManager/OfflineDevicesToggle';import {devicePoolForAgent,ExecutionTargetLabel,@@ -60,7 +67,9 @@ interface HeteroExecutionTargetSelectProps {*/export const HeteroExecutionTargetSelect = memo<HeteroExecutionTargetSelectProps>(({ agentId, deviceId, isOverridden, isPending, isSelectable, providerType, target }) => {- const { t } = useTranslation(['setting', 'chat']);+ const { t } = useTranslation(['setting', 'chat', 'device']);+ const currentMachine = useCurrentMachine();+ const [showOffline, setShowOffline] = useState(false);const agent = useAgentStore((s) => s.agentMap[agentId]);const isWorkspaceAgent = !!agent?.workspaceId;const { canManageAgent } = useAgentManagementAccess(agentId);@@ -121,8 +130,12 @@ export const HeteroExecutionTargetSelect = memo<HeteroExecutionTargetSelectPropscompact={compact}description=""device={device}- label={device.friendlyName || device.hostname || device.deviceId}target={'device'}+ label={+ isCurrentMachineDevice(device, currentMachine)+ ? `${device.friendlyName || device.hostname || device.deviceId} · ${t('device:picker.thisDevice')}`+ : device.friendlyName || device.hostname || device.deviceId+ }/>);@@ -148,6 +161,43 @@ export const HeteroExecutionTargetSelect = memo<HeteroExecutionTargetSelectProps? [{ disabled: true, label: emptyLabel, value: 'status:empty' }]: [];+ // This machine first, then reachable devices; offline ones fold into one+ // group at the end unless one of them is the pick.+ const pickedDeviceId = target === 'device' ? deviceId : undefined;+ const folds = (device: DeviceListItem) =>+ isConfirmed && isDeviceOffline(device) && device.deviceId !== pickedDeviceId;+ const ordered = (rows: DeviceListItem[]) => {+ const { available, offline } = splitPickerDevices(rows, currentMachine);+ return [...available, ...offline].filter((device) => !folds(device));+ };+ const foldedDevices = (+ isWorkspaceAgent ? [...privateWorkspace, ...workspace] : personal+ ).filter(folds);+ const offlineGroup: SelectOptions<string> =+ !error && foldedDevices.length > 0+ ? [+ {+ label: (+ <OfflineDevicesToggle+ count={foldedDevices.length}+ expanded={showOffline}+ onToggle={() => setShowOffline((v) => !v)}+ />+ ),+ options: showOffline+ ? foldedDevices.map((device) =>+ toDeviceOption(+ device,+ device.scope === 'workspace' &&+ device.visibility === 'private' &&+ !!privateDeviceBlockedReason,+ ),+ )+ : [],+ },+ ]+ : [];+const fixedTargetOptions: SelectOption<string>[] = [...(isDesktop? [@@ -172,7 +222,7 @@ export const HeteroExecutionTargetSelect = memo<HeteroExecutionTargetSelectProps? []: !isWorkspaceAgent? [- ...personal.map((device) => toDeviceOption(device)),+ ...ordered(personal).map((device) => toDeviceOption(device)),...poolStatusOptions(personal, t('chat:heteroAgent.executionTarget.noDevices')),]: [@@ -183,7 +233,7 @@ export const HeteroExecutionTargetSelect = memo<HeteroExecutionTargetSelectProps{label: t('chat:heteroAgent.executionTarget.personalGroup'),options: [- ...privateWorkspace.map((device) =>+ ...ordered(privateWorkspace).map((device) =>toDeviceOption(device, !!privateDeviceBlockedReason),),...(privateDeviceBlockedReason@@ -202,7 +252,7 @@ export const HeteroExecutionTargetSelect = memo<HeteroExecutionTargetSelectProps{label: t('chat:heteroAgent.executionTarget.workspaceGroup'),options: [- ...workspace.map((device) => toDeviceOption(device)),+ ...ordered(workspace).map((device) => toDeviceOption(device)),...poolStatusOptions(workspace, t('settingAgent.devicePolicy.noPublicDevice')),],},@@ -217,7 +267,7 @@ export const HeteroExecutionTargetSelect = memo<HeteroExecutionTargetSelectPropsclassNames={executionTargetSelectClassNames}disabled={isPending || !isSelectable}optionRender={(option) => option.label}- options={[...fixedTargetOptions, ...deviceOptions]}+ options={[...fixedTargetOptions, ...deviceOptions, ...offlineGroup]}placeholder={t('settingAgent.devicePolicy.selectTarget')}popupMatchSelectWidth={true}value={getTargetSelectValue(target, deviceId)}diff --git a/src/features/Projects/WorkingDirectories/AddDirectoryModal.tsx b/src/features/Projects/WorkingDirectories/AddDirectoryModal.tsxindex 12c13613898..ec5a35949ee 100644--- a/src/features/Projects/WorkingDirectories/AddDirectoryModal.tsx+++ b/src/features/Projects/WorkingDirectories/AddDirectoryModal.tsx@@ -14,6 +14,7 @@ import { useTranslation } from 'react-i18next';import AsyncError from '@/components/AsyncError';import { getDeviceIcon } from '@/features/DeviceManager/getDeviceIcon';+import { useDeviceSelectOptions } from '@/features/DeviceManager/useDeviceSelectOptions';import { deviceService } from '@/services/device';import { deviceSelectors, useDeviceStore } from '@/store/device';import { useProjectDirectoryStore, useProjectEnvironments } from '@/store/projectWorkingDirectory';@@ -51,6 +52,7 @@ function AddDirectoryContent({? fixedDevice?.friendlyName || fixedDevice?.hostname || initialDeviceId: undefined;const [path, setPath] = useState('');+ const deviceOptions = useDeviceSelectOptions(devices, deviceId);const [pending, setPending] = useState(false);const [error, setError] = useState<unknown>();const bind = useProjectDirectoryStore((s) => s.bind);@@ -96,12 +98,9 @@ function AddDirectoryContent({<Selectaria-label={t('directories.device')}disabled={pending}+ options={deviceOptions}placeholder={t('directories.device')}value={deviceId}- options={devices.map((d) => ({- value: d.deviceId,- label: d.friendlyName || d.deviceId,- }))}onChange={(id) => {setDevice(id ?? '');setError(undefined);diff --git a/src/features/Projects/WorkingDirectories/EditDirectoryModal.tsx b/src/features/Projects/WorkingDirectories/EditDirectoryModal.tsxindex 6a3c97f5106..888fb5a06c5 100644--- a/src/features/Projects/WorkingDirectories/EditDirectoryModal.tsx+++ b/src/features/Projects/WorkingDirectories/EditDirectoryModal.tsx@@ -14,6 +14,7 @@ import { useState } from 'react';import { useTranslation } from 'react-i18next';import AsyncError from '@/components/AsyncError';+import { useDeviceSelectOptions } from '@/features/DeviceManager/useDeviceSelectOptions';import { deviceService } from '@/services/device';import { deviceSelectors, useDeviceStore } from '@/store/device';import type { ProjectDirectory } from '@/store/projectWorkingDirectory';@@ -49,6 +50,7 @@ function EditDirectoryContent({const devices = useDeviceStore(deviceSelectors.deviceList);const [deviceId, setDevice] = useState(directory.deviceId);const [path, setPath] = useState(directory.path);+ const deviceOptions = useDeviceSelectOptions(devices, deviceId);const [pending, setPending] = useState(false);const [error, setError] = useState<unknown>();const relocate = useProjectDirectoryStore((s) => s.relocateDirectory);@@ -76,7 +78,7 @@ function EditDirectoryContent({<Selectaria-label={t('directories.device')}disabled={pending}- options={devices.map((d) => ({ value: d.deviceId, label: d.friendlyName || d.deviceId }))}+ options={deviceOptions}placeholder={t('directories.device')}value={deviceId}onChange={(id) => {