🤯 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
✨ feat(billboard): open web onboarding for resetOnboarding action on desktop (#18379)
Inneib33ff33f2b68
diff --git a/src/features/Billboard/actions.test.ts b/src/features/Billboard/actions.test.tsindex 977a9d128b9..bf0bb7b9fd7 100644--- a/src/features/Billboard/actions.test.ts+++ b/src/features/Billboard/actions.test.ts@@ -8,11 +8,20 @@ import {runBillboardAction,} from './actions';-const { openChangelogModal, openFeedbackModal, resetOnboarding } = vi.hoisted(() => ({- openChangelogModal: vi.fn(),- openFeedbackModal: vi.fn(),- resetOnboarding: vi.fn(),-}));+const { openChangelogModal, openFeedbackModal, resetOnboarding, openExternalLink, electronState } =+ vi.hoisted(() => ({+ electronState: {+ dataSyncConfig: { storageMode: 'cloud' } as {+ active?: boolean;+ remoteServerUrl?: string;+ storageMode: 'cloud' | 'selfHost';+ },+ },+ openChangelogModal: vi.fn(),+ openExternalLink: vi.fn(),+ openFeedbackModal: vi.fn(),+ resetOnboarding: vi.fn(),+ }));vi.mock('@/components/ChangelogModal', () => ({default: openChangelogModal,@@ -28,8 +37,31 @@ vi.mock('@/store/user', () => ({getUserStoreState: () => ({ resetOnboarding }),}));+vi.mock('@/store/electron', () => ({+ getElectronStoreState: () => electronState,+}));++vi.mock('@/services/electron/system', () => ({+ electronSystemService: { openExternalLink },+}));++const importDesktopActions = async () => {+ vi.resetModules();+ vi.doMock('@lobechat/const', async (importOriginal) => ({+ ...((await importOriginal()) as typeof LobechatConst),+ isDesktop: true,+ }));+ return import('./actions');+};++const restoreDesktopMock = () => {+ vi.doUnmock('@lobechat/const');+ vi.resetModules();+};+beforeEach(() => {vi.clearAllMocks();+ electronState.dataSyncConfig = { storageMode: 'cloud' };});describe('isBillboardAction', () => {@@ -66,20 +98,41 @@ describe('resolveBillboardAction', () => {expect(resolveBillboardAction(undefined)).toBeNull();});- it('should not resolve web-only actions on desktop', async () => {- vi.resetModules();- vi.doMock('@lobechat/const', async (importOriginal) => ({- ...((await importOriginal()) as typeof LobechatConst),- isDesktop: true,- }));+ it('should not resolve resetOnboarding on desktop in local mode', async () => {+ electronState.dataSyncConfig = { active: false, storageMode: 'cloud' };try {- const desktopActions = await import('./actions');+ const desktopActions = await importDesktopActions();expect(desktopActions.resolveBillboardAction('resetOnboarding')).toBeNull();expect(desktopActions.resolveBillboardAction('openChangelog')).toBe('openChangelog');} finally {- vi.doUnmock('@lobechat/const');- vi.resetModules();+ restoreDesktopMock();+ }+ });++ it('should not resolve resetOnboarding on desktop synced to a self-host server', async () => {+ electronState.dataSyncConfig = {+ active: true,+ remoteServerUrl: 'https://my-server.example.com',+ storageMode: 'selfHost',+ };++ try {+ const desktopActions = await importDesktopActions();+ expect(desktopActions.resolveBillboardAction('resetOnboarding')).toBeNull();+ } finally {+ restoreDesktopMock();+ }+ });++ it('should resolve resetOnboarding on desktop synced to official cloud', async () => {+ electronState.dataSyncConfig = { active: true, storageMode: 'cloud' };++ try {+ const desktopActions = await importDesktopActions();+ expect(desktopActions.resolveBillboardAction('resetOnboarding')).toBe('resetOnboarding');+ } finally {+ restoreDesktopMock();}});});@@ -103,6 +156,21 @@ describe('runBillboardAction', () => {await runBillboardAction('resetOnboarding');expect(resetOnboarding).toHaveBeenCalledTimes(1);+ expect(openExternalLink).not.toHaveBeenCalled();+ });++ it('should reset then open the official web onboarding externally on desktop', async () => {+ electronState.dataSyncConfig = { active: true, storageMode: 'cloud' };++ try {+ const desktopActions = await importDesktopActions();+ await desktopActions.runBillboardAction('resetOnboarding');++ expect(resetOnboarding).toHaveBeenCalledTimes(1);+ expect(openExternalLink).toHaveBeenCalledWith('https://app.lobehub.com/onboarding');+ } finally {+ restoreDesktopMock();+ }});it('should have a runnable handler for every registered action', async () => {diff --git a/src/features/Billboard/actions.ts b/src/features/Billboard/actions.tsindex f2d188eb2cf..d9ce5da2a75 100644--- a/src/features/Billboard/actions.ts+++ b/src/features/Billboard/actions.ts@@ -1,7 +1,11 @@-import { isDesktop } from '@lobechat/const';+import { isDesktop, OFFICIAL_URL } from '@lobechat/const';+import urlJoin from 'url-join';import { openChangelogModal } from '@/components/ChangelogModal';import { openFeedbackModal } from '@/components/FeedbackModal';+import { electronSystemService } from '@/services/electron/system';+import { getElectronStoreState } from '@/store/electron';+import { electronSyncSelectors } from '@/store/electron/selectors';import { getUserStoreState } from '@/store/user';/**@@ -15,12 +19,36 @@ export const BILLBOARD_ACTIONS = ['openChangelog', 'openFeedback', 'resetOnboardexport type BillboardAction = (typeof BILLBOARD_ACTIONS)[number];-/** Actions only meaningful on the web SPA (desktop has its own onboarding flow). */-const WEB_ONLY_ACTIONS: readonly BillboardAction[] = ['resetOnboarding'];-export const isBillboardAction = (value: unknown): value is BillboardAction =>typeof value === 'string' && (BILLBOARD_ACTIONS as readonly string[]).includes(value);+const isSyncedToOfficialCloud = () => {+ const state = getElectronStoreState();+ return (+ electronSyncSelectors.isSyncActive(state) &&+ electronSyncSelectors.storageMode(state) === 'cloud'+ );+};++type BillboardActionGuard = (action: BillboardAction) => BillboardAction | null;++const onlyWhen =+ (target: BillboardAction, available: () => boolean): BillboardActionGuard =>+ (action) =>+ action !== target || available() ? action : null;++/**+ * Availability pipeline: the action flows through each guard, and any guard+ * may drop it to null (the CTA then falls back to `linkUrl`). Add a guard per+ * constraint instead of branching inside `resolveBillboardAction`.+ */+const actionGuards: BillboardActionGuard[] = [+ // The web onboarding flow only exists on the official cloud instance, and+ // the reset must apply to the same account the external browser will show —+ // so desktop honors resetOnboarding only when synced to official cloud.+ onlyWhen('resetOnboarding', () => !isDesktop || isSyncedToOfficialCloud()),+];+/*** Narrow a platform-configured value to an action this client can actually run:* unknown values and actions unavailable on the current platform both return@@ -28,8 +56,10 @@ export const isBillboardAction = (value: unknown): value is BillboardAction =>*/export const resolveBillboardAction = (value: unknown): BillboardAction | null => {if (!isBillboardAction(value)) return null;- if (isDesktop && WEB_ONLY_ACTIONS.includes(value)) return null;- return value;+ return actionGuards.reduce<BillboardAction | null>(+ (action, guard) => (action ? guard(action) : null),+ value,+ );};const billboardActionHandlers: Record<BillboardAction, () => Promise<void> | void> = {@@ -41,6 +71,12 @@ const billboardActionHandlers: Record<BillboardAction, () => Promise<void> | voi},resetOnboarding: async () => {await getUserStoreState().resetOnboarding();++ if (isDesktop) {+ await electronSystemService.openExternalLink(urlJoin(OFFICIAL_URL, '/onboarding'));+ return;+ }+window.location.href = '/onboarding';},};diff --git a/src/store/electron/selectors/sync.ts b/src/store/electron/selectors/sync.tsindex 85d768812cf..f7c0af9cfc8 100644--- a/src/store/electron/selectors/sync.ts+++ b/src/store/electron/selectors/sync.ts@@ -2,7 +2,7 @@ import { OFFICIAL_URL } from '@lobechat/const';import { type ElectronState } from '../initialState';-const isSyncActive = (s: ElectronState) => s.dataSyncConfig.active;+const isSyncActive = (s: ElectronState) => s.dataSyncConfig.active ?? false;const storageMode = (s: ElectronState) => s.dataSyncConfig.storageMode;