Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 手机生成的会话深链冻结所属设备
Dash29a62dafa31a
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsxindex f9b7bf83fd..6cd33103f9 100644--- a/apps/mobile/app/sessions/[sessionId].tsx+++ b/apps/mobile/app/sessions/[sessionId].tsx@@ -9420,10 +9420,11 @@ function SessionScreenContent() {}, [deviceId, deviceName, router, sessionId, setError, t]);// 长按/操作条「复制消息链接」:复制带消息锚点的会话深链,可跨端粘贴跳转。+ // 冻结当前任务所在设备:目标归档 / 未同步后,从别的电脑的任务里点开也能找到它。const copyMessageLink = useCallback((clientId: string) => {if (!sessionId) return;- void copyMessageText(buildMobileSessionMessageDeepLink(sessionId, clientId));- }, [sessionId]);+ void copyMessageText(buildMobileSessionMessageDeepLink(sessionId, clientId, { deviceId }));+ }, [deviceId, sessionId]);const resolvePastedSessionLinkLabel = useCallback(async (href: string) => {const target = parseSessionDeepLinkUrl(href);@@ -9490,7 +9491,7 @@ function SessionScreenContent() {const summary = target ? mobileSessionMessageDisplayText(target) : null;const bounded = summary ? boundAgentReferenceText(summary) : null;const node = sessionLinkComposerNode({- href: buildMobileSessionMessageDeepLink(sessionId, clientId),+ href: buildMobileSessionMessageDeepLink(sessionId, clientId, { deviceId }),label: compactSessionMessageLabel(summary ?? clientId),titled: true,...(bounded?.text ? { agentText: bounded.text } : {}),@@ -9500,7 +9501,7 @@ function SessionScreenContent() {if (editor) editor.insertNode(node);else applyComposerDocument(appendComposerNode(composerDocumentRef.current, node));requestAnimationFrame(() => composerInputRef.current?.focus());- }, [applyComposerDocument, canUseComposer, messages, sessionId]);+ }, [applyComposerDocument, canUseComposer, deviceId, messages, sessionId]);const deleteMessage = useCallback((clientId: string) => {if (!deviceId || messageActionBusy) return;diff --git a/apps/mobile/src/__tests__/sessionLinks.test.ts b/apps/mobile/src/__tests__/sessionLinks.test.tsindex 06cc8cf590..3080b0949e 100644--- a/apps/mobile/src/__tests__/sessionLinks.test.ts+++ b/apps/mobile/src/__tests__/sessionLinks.test.ts@@ -82,6 +82,22 @@ describe('session links', () => {expect(extractSessionLinkIds('没有链接')).toEqual([]);});+ it('freezes the owner device into generated links in the desktop query order', () => {+ expect(buildMobileSessionDeepLink('abc', { deviceId: 'device/1' })).toBe(+ 'cindy://session/abc?device=device%2F1',+ );+ expect(buildMobileSessionMessageDeepLink('abc', 'client/9', { deviceId: 'device/1' })).toBe(+ 'cindy://session/abc?message=client%2F9&device=device%2F1',+ );+ expect(parseSessionDeepLinkUrl(buildMobileSessionMessageDeepLink('abc', 'client/9', { deviceId: 'device/1' }))).toEqual({+ sessionId: 'abc',+ messageClientId: 'client/9',+ deviceId: 'device/1',+ });+ // 缺设备时保持旧格式。+ expect(buildMobileSessionMessageDeepLink('abc', 'c1', { deviceId: null })).toBe('cindy://session/abc?message=c1');+ });+it('resolves the device for a session link, falling back when the target is not listed', () => {// 已同步列表里的可达设备优先于深链冻结值(re-link 后冻结值可能已过期)。expect(resolveSessionLinkDeviceId({diff --git a/apps/mobile/src/__tests__/sessionMenu.test.ts b/apps/mobile/src/__tests__/sessionMenu.test.tsindex 91765c5d92..776c7ee999 100644--- a/apps/mobile/src/__tests__/sessionMenu.test.ts+++ b/apps/mobile/src/__tests__/sessionMenu.test.ts@@ -163,6 +163,10 @@ describe('sessionMenu info model', () => {describe('sessionMenu navigation', () => {it('copies the mobile deep link for the session', () => {expect(sessionMenuCopyLink(session({ id: 'abc' }))).toBe('cindy://session/abc');+ expect(sessionMenuCopyLink(session({ id: 'abc', deviceLinkDeviceId: 'physical' })))+ .toBe('cindy://session/abc?device=physical');+ expect(sessionMenuCopyLink(session({ id: 'abc', canonicalDeviceId: 'canonical', deviceLinkDeviceId: 'physical' })))+ .toBe('cindy://session/abc?device=canonical');});it('settles back navigation in two stages', () => {diff --git a/apps/mobile/src/session/sessionLinks.ts b/apps/mobile/src/session/sessionLinks.tsindex 95989da3f4..a75e807ba2 100644--- a/apps/mobile/src/session/sessionLinks.ts+++ b/apps/mobile/src/session/sessionLinks.ts@@ -21,16 +21,38 @@ export function isCindyDeepLinkUrl(url: string): boolean {return typeof url === 'string' && DEEP_LINK_SCHEMES.some((s) => url.startsWith(`${s}://`));}-export function buildMobileSessionDeepLink(sessionId: string): string {- return `${SESSION_LINK_PREFIX}${encodeURIComponent(sessionId)}`;+/**+ * deviceId = 会话归属的 device-link 设备,冻进 `?device=`(与桌面端 builder 同形):+ * 目标任务归档 / 未同步后,点开与引用仍能按它找到那台电脑,不必猜当前设备。+ */+export interface MobileSessionDeepLinkOptions {+ deviceId?: string | null;+}++function sessionDeepLinkQuery(+ opts: MobileSessionDeepLinkOptions | undefined,+ messageClientId?: string,+): string {+ const pairs: string[] = [];+ if (messageClientId) pairs.push(`message=${encodeURIComponent(messageClientId)}`);+ if (opts?.deviceId) pairs.push(`device=${encodeURIComponent(opts.deviceId)}`);+ return pairs.length > 0 ? `?${pairs.join('&')}` : '';+}++export function buildMobileSessionDeepLink(+ sessionId: string,+ opts?: MobileSessionDeepLinkOptions,+): string {+ return `${SESSION_LINK_PREFIX}${encodeURIComponent(sessionId)}${sessionDeepLinkQuery(opts)}`;}/** 带消息锚点的会话深链(clientId 语义,与桌面端 builder 等价镜像)。 */export function buildMobileSessionMessageDeepLink(sessionId: string,messageClientId: string,+ opts?: MobileSessionDeepLinkOptions,): string {- return `${buildMobileSessionDeepLink(sessionId)}?message=${encodeURIComponent(messageClientId)}`;+ return `${SESSION_LINK_PREFIX}${encodeURIComponent(sessionId)}${sessionDeepLinkQuery(opts, messageClientId)}`;}export interface SessionDeepLinkTarget {@@ -92,8 +114,9 @@ export function parseSessionDeepLinkUrl(url: string): SessionDeepLinkTarget | nu/*** 点开 / 解析会话深链时目标任务所在的设备。已同步列表反查到的可达设备优先* (re-link 后深链冻结的 `?device=` 可能已过期);列表里没有(已归档 / 尚未同步)- * 时用冻结值,再退回当前任务所在设备——正文里的深链多由当前任务所在电脑生成,- * 归档任务不在列表里,但仍在那台电脑上。+ * 时用冻结值,再退回当前任务所在设备。手机与桌面端生成远程会话深链时都会冻结+ * `?device=`;不带它的只剩电脑本机生成的深链(Agent 回复正文、桌面端本机会话),+ * 多在同一台电脑的任务里出现,归档任务不在列表里,但仍在那台电脑上。*/export function resolveSessionLinkDeviceId({listedDeviceId,diff --git a/apps/mobile/src/session/sessionMenu.ts b/apps/mobile/src/session/sessionMenu.tsindex 6ab29afd3e..f84a9681b7 100644--- a/apps/mobile/src/session/sessionMenu.ts+++ b/apps/mobile/src/session/sessionMenu.ts@@ -161,9 +161,13 @@ export function removeSessionExtraDir(return normalizeExtraDirs(current ?? undefined).filter((dir) => dir !== path);}-/** 会话深链(一级「复制链接」的复制值)。 */-export function sessionMenuCopyLink(session: Pick<RemoteSession, 'id'>): string {- return buildMobileSessionDeepLink(session.id);+/** 会话深链(一级「复制链接」的复制值),冻结会话所在设备(可达优先,与打开会话同口径)。 */+export function sessionMenuCopyLink(+ session: Pick<RemoteSession, 'id' | 'canonicalDeviceId' | 'deviceLinkDeviceId'>,+): string {+ return buildMobileSessionDeepLink(session.id, {+ deviceId: session.canonicalDeviceId ?? session.deviceLinkDeviceId,+ });}/** Android 返回键 / 关闭手势的两段式收敛:info 先回 menu,menu 才关 sheet。 */