π€― 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(connect-agent): prevent device loading state flash (#18768)
AmAzing-4ffa0ec9c555
diff --git a/src/components/CommandLine/index.tsx b/src/components/CommandLine/index.tsxnew file mode 100644index 00000000000..19730ad55f8--- /dev/null+++ b/src/components/CommandLine/index.tsx@@ -0,0 +1,49 @@+'use client';++import { CopyButton } from '@lobehub/ui';+import { createStaticStyles, cssVar } from 'antd-style';+import { memo } from 'react';++const styles = createStaticStyles(({ css }) => ({+ codeBlock: css`+ display: flex;+ flex: none;+ gap: 12px;+ align-items: center;++ min-width: 0;+ padding-block: 12px;+ padding-inline: 16px;+ border: 1px solid ${cssVar.colorBorderSecondary};+ border-radius: ${cssVar.borderRadius};++ background: ${cssVar.colorFillQuaternary};+ `,+ command: css`+ overflow: hidden;+ flex: 1;++ min-width: 0;++ font-family: ${cssVar.fontFamilyCode};+ font-size: ${cssVar.fontSizeSM};+ color: ${cssVar.colorText};+ text-overflow: ellipsis;+ white-space: nowrap;+ `,+}));++interface CommandLineProps {+ command: string;+}++const CommandLine = memo<CommandLineProps>(({ command }) => (+ <div className={styles.codeBlock}>+ <code className={styles.command}>{command}</code>+ <CopyButton content={command} size={'small'} />+ </div>+));++CommandLine.displayName = 'CommandLine';++export default CommandLine;diff --git a/src/features/ConnectAgent/deviceListState.test.ts b/src/features/ConnectAgent/deviceListState.test.tsnew file mode 100644index 00000000000..b61f11ff98a--- /dev/null+++ b/src/features/ConnectAgent/deviceListState.test.ts@@ -0,0 +1,17 @@+import { describe, expect, it } from 'vitest';++import { getDeviceListState } from './deviceListState';++describe('getDeviceListState', () => {+ it('keeps an empty device result in loading state while the request is in flight', () => {+ expect(getDeviceListState({ hasDevices: false, isFetching: true })).toBe('loading');+ });++ it('reports empty only after the request settles', () => {+ expect(getDeviceListState({ hasDevices: false, isFetching: false })).toBe('empty');+ });++ it('keeps cached devices visible during revalidation', () => {+ expect(getDeviceListState({ hasDevices: true, isFetching: true })).toBe('ready');+ });+});diff --git a/src/features/ConnectAgent/deviceListState.ts b/src/features/ConnectAgent/deviceListState.tsnew file mode 100644index 00000000000..44452ba45ef--- /dev/null+++ b/src/features/ConnectAgent/deviceListState.ts@@ -0,0 +1,14 @@+export type DeviceListState = 'empty' | 'loading' | 'ready';++interface GetDeviceListStateOptions {+ hasDevices: boolean;+ isFetching: boolean;+}++export const getDeviceListState = ({+ hasDevices,+ isFetching,+}: GetDeviceListStateOptions): DeviceListState => {+ if (hasDevices) return 'ready';+ return isFetching ? 'loading' : 'empty';+};diff --git a/src/features/ConnectAgent/index.tsx b/src/features/ConnectAgent/index.tsxindex c4b4c6f1d0e..7f65d9740d9 100644--- a/src/features/ConnectAgent/index.tsx+++ b/src/features/ConnectAgent/index.tsx@@ -9,7 +9,7 @@ import type {import { isRemoteHeterogeneousType } from '@lobechat/heterogeneous-agents';import type { DeviceListItem } from '@lobechat/types';import { agentDisplayName } from '@lobechat/types';-import { CopyButton, Flexbox, Icon, Input, TextArea, Tooltip } from '@lobehub/ui';+import { Flexbox, Icon, Input, TextArea, Tooltip } from '@lobehub/ui';import {Alert,Button,@@ -20,7 +20,6 @@ import {Text,useModalContext,} from '@lobehub/ui/base-ui';-import { Typography } from 'antd';import { createStaticStyles, cssVar } from 'antd-style';import { t as i18nT } from 'i18next';import {@@ -36,6 +35,7 @@ import { memo, type ReactNode, useCallback, useEffect, useMemo, useState } fromimport { useTranslation } from 'react-i18next';import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';+import CommandLine from '@/components/CommandLine';import { DOWNLOAD_URL } from '@/const/url';import { getDeviceIcon } from '@/features/DeviceManager/getDeviceIcon';import { useDeviceList } from '@/features/DeviceManager/useDeviceList';@@ -46,6 +46,7 @@ import { heteroAgentDefaultName } from '@/store/agent/utils/heteroAgentDefaultNaimport { useElectronStore } from '@/store/electron';import { useHomeStore } from '@/store/home';+import { getDeviceListState } from './deviceListState';import type { ConnectableProvider, ConnectAgentProfile } from './providers';import { buildConnectAgentConfig, CONNECTABLE_PROVIDERS } from './providers';import type { ScanTarget } from './useAgentScan';@@ -64,17 +65,21 @@ const styles = createStaticStyles(({ css }) => ({overscroll-behavior: contain;max-height: min(50dvh, 400px);`,- cmd: css`- user-select: all;-- padding-block: 8px;- padding-inline: 12px;- border-radius: ${cssVar.borderRadiusSM};+ commandHint: css`+ display: flex;+ gap: 12px;+ align-items: center;+ justify-content: space-between;- font-family: ${cssVar.fontFamilyCode};- font-size: 12px;+ min-width: 0;+ padding-inline: 4px;- background: ${cssVar.colorFillTertiary};+ > span {+ overflow: hidden;+ min-width: 0;+ text-overflow: ellipsis;+ white-space: nowrap;+ }`,dot: css`flex: none;@@ -126,24 +131,11 @@ const styles = createStaticStyles(({ css }) => ({min-height: 28px;margin-block-start: auto;- > a {+ > a,+ > div {width: 100%;}`,- emptyOptionCode: css`- display: flex;- gap: 8px;- align-items: center;- justify-content: space-between;-- box-sizing: border-box;- width: 100%;- height: 32px;- padding-inline: 10px 4px;- border-radius: ${cssVar.borderRadius};-- background: ${cssVar.colorFillTertiary};- `,emptyOptions: css`display: grid;grid-template-columns: 1fr 1fr;@@ -261,6 +253,11 @@ const styles = createStaticStyles(({ css }) => ({animation: lobe-connect-agent-pulse 1.4s ease-in-out infinite;`,+ skeletonSquare: css`+ width: 36px;+ height: 36px;+ border-radius: ${cssVar.borderRadius};+ `,}));interface CreatedAgent {@@ -277,9 +274,13 @@ const SectionLabel = memo<{ children: ReactNode }>(({ children }) => (</Text>));-const SkeletonRow = memo<{ width: number }>(({ width }) => (+const SkeletonRow = memo<{ squareIcon?: boolean; width: number }>(({ squareIcon, width }) => (<div className={`${styles.row} ${styles.rowStatic}`}>- <div className={styles.skeletonCircle} />+ <div+ className={+ squareIcon ? `${styles.skeletonCircle} ${styles.skeletonSquare}` : styles.skeletonCircle+ }+ />{/* Column height matches a real row's two-line text block so thescanning β done swap doesn't shift the modal */}<Flexbox flex={1} gap={10} justify={'center'} style={{ height: 42 }}>@@ -626,6 +627,10 @@ const ConnectAgentContent = memo<ConnectAgentContentProps>(// ββ Step 1: choose the machine ββif (step === 0) {const isRefreshing = loadingDevices || fetchingDevices;+ const deviceListState = getDeviceListState({+ hasDevices: listedDevices.length > 0,+ isFetching: isRefreshing,+ });const showEmpty = !isDesktop && !isRefreshing && onlineDevices.length === 0;return (@@ -678,10 +683,7 @@ const ConnectAgentContent = memo<ConnectAgentContentProps>(</Text></Flexbox><div className={styles.emptyOptionAction}>- <div className={styles.emptyOptionCode}>- <code>{t('connectAgent.create.noDevicesCmd')}</code>- <CopyButton content={t('connectAgent.create.noDevicesCmd')} size={'small'} />- </div>+ <CommandLine command={t('connectAgent.create.noDevicesCmd')} /></div></div></div>@@ -713,7 +715,7 @@ const ConnectAgentContent = memo<ConnectAgentContentProps>(</div></Flexbox>)}- {listedDevices.length > 0 && (+ {deviceListState !== 'empty' && (<Flexbox gap={6}><Flexbox horizontal align={'center'} justify={'space-between'}><SectionLabel>{t('connectAgent.create.connectedDevices')}</SectionLabel>@@ -728,31 +730,33 @@ const ConnectAgentContent = memo<ConnectAgentContentProps>(</Button></Flexbox><div className={styles.groupList}>- {listedDevices.map((device) => (- <DeviceRow- icon={getDeviceIcon(device.platform, 18)}- key={device.deviceId}- offline={!device.online}- subtitle={device.hostname || device.deviceId}- title={deviceLabel(device)}- statusText={- device.online- ? t('connectAgent.create.online')- : t('connectAgent.create.offline')- }- onClick={() => pickTarget({ device, kind: 'device' })}- />- ))}+ {deviceListState === 'loading'+ ? [96, 140, 112].map((width) => (+ <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={+ device.online+ ? t('connectAgent.create.online')+ : t('connectAgent.create.offline')+ }+ onClick={() => pickTarget({ device, kind: 'device' })}+ />+ ))}</div></Flexbox>)}- {isDesktop && listedDevices.length === 0 && (- <Flexbox gap={4}>- <span>{t('connectAgent.create.noDevicesCliHint')}</span>- <Typography.Text code copyable>- {t('connectAgent.create.noDevicesCmd')}- </Typography.Text>- </Flexbox>+ {isDesktop && deviceListState === 'empty' && (+ <div className={styles.commandHint}>+ <Text type={'secondary'}>{t('connectAgent.create.noDevicesCliHint')}</Text>+ <CommandLine command={t('connectAgent.create.noDevicesCmd')} />+ </div>)}</Flexbox>)}diff --git a/src/features/DeviceManager/DeviceConnectModal.tsx b/src/features/DeviceManager/DeviceConnectModal.tsxindex b7f2a3f0819..e231226dba8 100644--- a/src/features/DeviceManager/DeviceConnectModal.tsx+++ b/src/features/DeviceManager/DeviceConnectModal.tsx@@ -2,7 +2,7 @@import { DOWNLOAD_URL } from '@lobechat/const';import type { DeviceScope, DeviceVisibility } from '@lobechat/types';-import { CopyButton, Flexbox, Icon } from '@lobehub/ui';+import { Flexbox, Icon } from '@lobehub/ui';import { Button, Tabs, Text } from '@lobehub/ui/base-ui';import { createStaticStyles, cssVar } from 'antd-style';import { DownloadIcon, MonitorDownIcon, ShieldCheckIcon, TerminalIcon } from 'lucide-react';@@ -10,31 +10,10 @@ import { memo, useEffect, useState } from 'react';import { useTranslation } from 'react-i18next';import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';+import CommandLine from '@/components/CommandLine';import ImperativeModal from '@/components/ImperativeModal';const styles = createStaticStyles(({ css }) => ({- codeBlock: css`- display: flex;- gap: 12px;- align-items: center;-- padding-block: 12px;- padding-inline: 16px;- border: 1px solid ${cssVar.colorBorderSecondary};- border-radius: ${cssVar.borderRadius};-- background: ${cssVar.colorFillQuaternary};- `,- command: css`- overflow: hidden;- flex: 1;-- font-family: ${cssVar.fontFamilyCode};- font-size: ${cssVar.fontSizeSM};- color: ${cssVar.colorText};- text-overflow: ellipsis;- white-space: nowrap;- `,footer: css`margin-block-start: 4px;padding-block-start: 16px;@@ -90,13 +69,6 @@ const Step = memo<StepProps>(({ index, title, desc, children, last }) => (</Flexbox>));-const CommandLine = memo<{ command: string }>(({ command }) => (- <div className={styles.codeBlock}>- <code className={styles.command}>{command}</code>- <CopyButton content={command} size={'small'} />- </div>-));-interface DeviceConnectModalProps {initialTab?: 'cli' | 'desktop';onClose: () => void;