Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 防止配置卡重复导航并补齐设备身份回退
Dash39ddfbf6c339
diff --git a/apps/mobile/src/__tests__/InteractionPanelReceipt.test.tsx b/apps/mobile/src/__tests__/InteractionPanelReceipt.test.tsxindex a09e3ea950..dccf62537b 100644--- a/apps/mobile/src/__tests__/InteractionPanelReceipt.test.tsx+++ b/apps/mobile/src/__tests__/InteractionPanelReceipt.test.tsx@@ -8,9 +8,16 @@ import type { NormalizedRemoteMessage } from '@/session/messageNormalize';import { InteractionPanel, PluginSetupMessageContent } from '@/session/InteractionPanel';import { remoteSessionStore, useSessionPendingInteractions } from '@/session/remoteSessionStore';import { clearAllInteractionDrafts, readAskUserDraft, readPlanReviewDraft } from '@/session/interactionDraftStore';+import { forwardNavigationLock } from '@/utils/navigationLock';const { resolveInteraction, invoke, push } = vi.hoisted(() => ({ resolveInteraction: vi.fn(), invoke: vi.fn(), push: vi.fn() }));-vi.mock('expo-router', () => ({ useLocalSearchParams: () => ({ deviceId: 'd1' }), useRouter: () => ({ push }) }));+const { routeParams } = vi.hoisted(() => ({ routeParams: {} as { deviceId?: string; sessionId?: string } }));+vi.mock('expo-router', async () => {+ const { useEffect } = await import('react');+ return { useLocalSearchParams: () => routeParams, useRouter: () => ({ push }),+ useNavigation: () => ({ isFocused: () => true, addListener: () => () => {} }),+ useFocusEffect: useEffect };+});vi.mock('@/device-link/DeviceLinkContext', () => ({ useDeviceLink: () => ({ invoke }) }));vi.mock('@/device-link/useMobileMakerTransport', () => ({useMobileMakerTransport: () => ({ resolveInteraction }),@@ -59,6 +66,8 @@ function Harness({ companion = false }: { companion?: boolean }) {beforeEach(() => {Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });vi.resetAllMocks();+ routeParams.deviceId = 'd1'; routeParams.sessionId = 's1';+ forwardNavigationLock.reset();remoteSessionStore.clear();clearAllInteractionDrafts();host = document.createElement('div');@@ -247,11 +256,15 @@ it('opens only the target computer desktop without resolving or authorizing theremoteSessionStore.setPendingInteractions('s1', [{ request }]);await act(async () => root.render(<Harness />));await click('interaction.pluginSetup.remoteDesktop');+ await click('interaction.pluginSetup.remoteDesktop');+ expect(push).toHaveBeenCalledTimes(1);expect(push).toHaveBeenLastCalledWith({ pathname: '/devices/desktop/[deviceId]', params: { deviceId: 'd1', deviceName: 'd1' } });expect(resolveInteraction).not.toHaveBeenCalled(); expect(invoke).not.toHaveBeenCalled();expect(host.querySelector('input')).toBeNull();+ forwardNavigationLock.reset();await act(async () => root.render(<AuthorizationMessageCard message={{ authorization: request } as unknown as NormalizedRemoteMessage} />));await click('interaction.pluginSetup.remoteDesktop');+ await click('interaction.pluginSetup.remoteDesktop');expect(push).toHaveBeenCalledTimes(2);for (const deviceId of [undefined, sharedTaskHostPeer('test', 'd1')]) {await act(async () => root.render(<PluginSetupMessageContent request={request} deviceId={deviceId} busy={false} />));@@ -261,6 +274,31 @@ it('opens only the target computer desktop without resolving or authorizing theexpect(host.querySelector('[data-testid="interaction.pluginSetup.remoteDesktop"]')).toBeNull();});+it('uses the session device when a message route omits it, including a late store update', async () => {+ delete routeParams.deviceId;+ const authorization = { kind: 'plugin_setup', requestId: 'setup-fallback', revision: 1,+ ghost: { id: 'google-gmail', name: 'Gmail' },+ steps: [{ id: 'account', title: 'Connect Gmail', phase: 'pending' }] };+ await act(async () => root.render(<AuthorizationMessageCard message={{ authorization } as unknown as NormalizedRemoteMessage} />));+ expect(host.querySelector('[data-testid="interaction.pluginSetup.remoteDesktop"]')).toBeNull();+ await act(async () => remoteSessionStore.setDeviceIdentity([{ deviceId: 'stored-device', name: 'Work computer' }]));+ await act(async () => remoteSessionStore.setDeviceSessions('stored-device', 'Work computer', [+ { id: 's1' } as Parameters<typeof remoteSessionStore.setDeviceSessions>[2][number],+ ]));+ await click('interaction.pluginSetup.remoteDesktop');+ expect(push).toHaveBeenLastCalledWith({ pathname: '/devices/desktop/[deviceId]',+ params: { deviceId: 'stored-device', deviceName: 'Work computer' } });+ expect(invoke).not.toHaveBeenCalled();+ invoke.mockResolvedValueOnce({ accepted: true });+ await click('interaction.pluginSetup.cancelButton');+ expect(invoke.mock.calls[0][0]).toBe('stored-device');+ routeParams.deviceId = 'explicit-device';+ forwardNavigationLock.reset();+ await act(async () => root.render(<AuthorizationMessageCard message={{ authorization } as unknown as NormalizedRemoteMessage} />));+ await click('interaction.pluginSetup.remoteDesktop');+ expect(push.mock.calls.at(-1)?.[0].params.deviceId).toBe('explicit-device');+});+it('persistent setup cancellation waits for a host terminal update and allows retry after failure', async () => {let receipt!: (value: { accepted: boolean }) => void;const authorization = { kind: 'plugin_setup', requestId: 'setup-1', revision: 1,diff --git a/apps/mobile/src/session/AuthorizationMessageCard.tsx b/apps/mobile/src/session/AuthorizationMessageCard.tsxindex 20f82a9fa9..e6aa476a24 100644--- a/apps/mobile/src/session/AuthorizationMessageCard.tsx+++ b/apps/mobile/src/session/AuthorizationMessageCard.tsx@@ -1,4 +1,4 @@-import { useRef, useState } from 'react';+import { useRef, useState, useSyncExternalStore } from 'react';import { useLocalSearchParams } from 'expo-router';import { StyleSheet, View } from 'react-native';import { useTranslation } from 'react-i18next';@@ -9,11 +9,16 @@ import { useThemedStyles, type ThemeColors } from '@/theme';import { spacing, typeScale } from '@/theme/tokens';import { PluginSetupMessageContent } from './InteractionPanel';import type { NormalizedRemoteMessage } from './messageNormalize';+import { remoteSessionStore } from './remoteSessionStore';/** Remote transcript projection; credentials and browser login remain on the trusted Host. */export function AuthorizationMessageCard({ message }: { message: NormalizedRemoteMessage }) {const { t } = useTranslation();- const { deviceId } = useLocalSearchParams<{ deviceId?: string }>();+ const params = useLocalSearchParams<{ deviceId?: string | string[]; sessionId?: string | string[] }>();+ const sessionId = (Array.isArray(params.sessionId) ? params.sessionId[0] : params.sessionId) ?? '';+ const storedDeviceId = useSyncExternalStore(remoteSessionStore.subscribe,+ () => remoteSessionStore.getSessionDeviceId(sessionId));+ const deviceId = (Array.isArray(params.deviceId) ? params.deviceId[0] : params.deviceId) ?? storedDeviceId;const { invoke } = useDeviceLink();const styles = useThemedStyles(makeStyles);const [busy, setBusy] = useState(false);diff --git a/apps/mobile/src/session/InteractionPanel.tsx b/apps/mobile/src/session/InteractionPanel.tsxindex b1431dba9b..37cfed39b2 100644--- a/apps/mobile/src/session/InteractionPanel.tsx+++ b/apps/mobile/src/session/InteractionPanel.tsx@@ -1,7 +1,7 @@import { usePaneViewport } from '@/platform/AdaptiveWindowContext';import { createContext, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';import { useTranslation } from 'react-i18next';-import { useRouter } from 'expo-router';+import { useGuardedPush } from '@/utils/useGuardedPush';import { isSharedTaskPeer } from '@cindy/device-link';import { mobilePresentationLocalizer } from '@/i18n/presentationLocalizer';import {@@ -1603,7 +1603,7 @@ function PluginSetupCard({/** Navigation only: authorization and credentials stay in the computer's own UI. */function PluginSetupRemoteDesktopButton({ deviceId, busy }: { deviceId: string; busy: boolean }) {- const router = useRouter();+ const push = useGuardedPush();const devices = useRemoteDeviceIdentity();const styles = useInteractionStyles();const { t } = useTranslation();@@ -1611,7 +1611,7 @@ function PluginSetupRemoteDesktopButton({ deviceId, busy }: { deviceId: string;const label = t('interaction.pluginSetup.remoteDesktop');return <InteractionTouchButton accessibilityLabel={label} disabled={busy}style={styles.primaryButton} testID="interaction.pluginSetup.remoteDesktop"- onPress={() => router.push({ pathname: '/devices/desktop/[deviceId]', params: { deviceId, deviceName } })}>+ onPress={() => push({ pathname: '/devices/desktop/[deviceId]', params: { deviceId, deviceName } })}><Text style={styles.primaryText}>{label}</Text></InteractionTouchButton>;}