Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mobile): 修复共享任务链接与重连后的引用设备解析

Dash28d9a4e07a31
diff --git a/apps/mobile/src/__tests__/sessionLinks.test.ts b/apps/mobile/src/__tests__/sessionLinks.test.ts
index 3080b0949e..a1b1e218cc 100644
--- a/apps/mobile/src/__tests__/sessionLinks.test.ts
+++ b/apps/mobile/src/__tests__/sessionLinks.test.ts
@@ -1,4 +1,5 @@
import { describe, expect, it } from 'vitest';
+import { sharedTaskHostPeer } from '@cindy/device-link';
import {
buildMobileSessionDeepLink,
buildMobileSessionMessageDeepLink,
@@ -98,6 +99,16 @@ describe('session links', () => {
expect(buildMobileSessionMessageDeepLink('abc', 'c1', { deviceId: null })).toBe('cindy://session/abc?message=c1');
});
+ it('exports shared-task links with the physical host device instead of a local peer handle', () => {
+ const deviceId = sharedTaskHostPeer('shared-task', 'host-device');
+ expect(buildMobileSessionDeepLink('abc', { deviceId })).toBe(
+ 'cindy://session/abc?device=host-device',
+ );
+ expect(buildMobileSessionMessageDeepLink('abc', 'm1', { deviceId })).toBe(
+ 'cindy://session/abc?message=m1&device=host-device',
+ );
+ });
+
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.ts
index 776c7ee999..55dd1b2b7d 100644
--- a/apps/mobile/src/__tests__/sessionMenu.test.ts
+++ b/apps/mobile/src/__tests__/sessionMenu.test.ts
@@ -1,4 +1,5 @@
import { beforeAll, describe, expect, it } from 'vitest';
+import { sharedTaskHostPeer } from '@cindy/device-link';
import { i18n } from '@/i18n';
import {
addSessionExtraDir,
@@ -167,6 +168,10 @@ describe('sessionMenu navigation', () => {
.toBe('cindy://session/abc?device=physical');
expect(sessionMenuCopyLink(session({ id: 'abc', canonicalDeviceId: 'canonical', deviceLinkDeviceId: 'physical' })))
.toBe('cindy://session/abc?device=canonical');
+ expect(sessionMenuCopyLink(session({
+ id: 'abc',
+ deviceLinkDeviceId: sharedTaskHostPeer('shared-task', 'host-device'),
+ }))).toBe('cindy://session/abc?device=host-device');
});
it('settles back navigation in two stages', () => {
diff --git a/apps/mobile/src/__tests__/sessionReferences.test.ts b/apps/mobile/src/__tests__/sessionReferences.test.ts
index 4812263298..a70fdace7f 100644
--- a/apps/mobile/src/__tests__/sessionReferences.test.ts
+++ b/apps/mobile/src/__tests__/sessionReferences.test.ts
@@ -3,6 +3,7 @@ import {
DeviceLinkError,
DL_HISTORY_MESSAGES_CHANNEL,
DL_SESSION_REFERENCE_CAPABILITY_CHANNEL,
+ sharedTaskHostPeer,
} from '@cindy/device-link';
import { i18n } from '@/i18n';
import type { RemoteInvoke } from '@/device-link/mobileMakerTransport';
@@ -140,19 +141,26 @@ describe('mobile session-reference links', () => {
)).toEqual([{ sessionId: 'source', deviceId: 'source-device' }]);
});
- it('prefers the device frozen into the link over store lookup and hints', () => {
- // 桌面端深链冻结的 `?device=` 优先;store 查不到时也不丢远程判定。
+ it('refreshes a restored draft device from the store and retains frozen devices for unlisted tasks', () => {
expect(extractMobileSessionReferences(
'cindy://session/source?device=dev-frozen',
() => 'dev-live',
[{ sessionId: 'source', deviceId: 'dev-hint' }],
- )).toEqual([{ sessionId: 'source', deviceId: 'dev-frozen' }]);
+ )).toEqual([{ sessionId: 'source', deviceId: 'dev-live' }]);
expect(extractMobileSessionReferences(
'cindy://session/source?message=anchor&device=dev-frozen',
() => undefined,
)).toEqual([{ sessionId: 'source', messageClientId: 'anchor', deviceId: 'dev-frozen' }]);
});
+ it('uses the local shared-task route when a portable link identifies its physical host', () => {
+ const peer = sharedTaskHostPeer('shared-task', 'host-device');
+ expect(extractMobileSessionReferences(
+ 'cindy://session/source?message=anchor&device=host-device',
+ () => peer,
+ )).toEqual([{ sessionId: 'source', messageClientId: 'anchor', deviceId: peer }]);
+ });
+
it('clears stale refs and trusted snapshots when an edit removes the link', async () => {
const invoke = vi.fn();
const prepared = await prepareMobileQueuedSessionReferences({
diff --git a/apps/mobile/src/session/sessionLinks.ts b/apps/mobile/src/session/sessionLinks.ts
index a75e807ba2..c141cff1b9 100644
--- a/apps/mobile/src/session/sessionLinks.ts
+++ b/apps/mobile/src/session/sessionLinks.ts
@@ -1,3 +1,4 @@
+import { parseSharedTaskPeer } from '@cindy/device-link';
import { BRAND_IDENTITY, allDeepLinkSchemes } from '@cindy/maker-shared/brand-identity';
// 深链双 scheme(身份单点派生):cindy 主 + xdt-maker 永久兼容(存量消息里的
@@ -35,7 +36,9 @@ function sessionDeepLinkQuery(
): string {
const pairs: string[] = [];
if (messageClientId) pairs.push(`message=${encodeURIComponent(messageClientId)}`);
- if (opts?.deviceId) pairs.push(`device=${encodeURIComponent(opts.deviceId)}`);
+ // 共享任务句柄只在当前客户端有效;跨端链接携带房主的真实电脑 ID。
+ const deviceId = parseSharedTaskPeer(opts?.deviceId)?.deviceId ?? opts?.deviceId;
+ if (deviceId) pairs.push(`device=${encodeURIComponent(deviceId)}`);
return pairs.length > 0 ? `?${pairs.join('&')}` : '';
}
diff --git a/apps/mobile/src/session/sessionReferences.ts b/apps/mobile/src/session/sessionReferences.ts
index c39c5fe948..fa059efd44 100644
--- a/apps/mobile/src/session/sessionReferences.ts
+++ b/apps/mobile/src/session/sessionReferences.ts
@@ -6,6 +6,7 @@ import type { RemoteInvoke } from '@/device-link/mobileMakerTransport';
import {
createSessionLinkPattern,
parseSessionDeepLinkUrl,
+ resolveSessionLinkDeviceId,
trimSessionLinkMatch,
} from '@/session/sessionLinks';
import { isSyntheticTriggerText } from '@cindy/maker-shared/synthetic-trigger';
@@ -158,11 +159,12 @@ export function extractMobileSessionReferences(
const key = mobileSessionReferenceMetadataKey(target.sessionId, target.messageClientId);
if (seen.has(key)) continue;
seen.add(key);
- // 深链里冻结的 `?device=`(生成时刻的会话归属)优先——与桌面端
- // reconcileSessionRefsForText 同口径;会话归属不会迁移,冻结值不受
- // 发送时刻 store 状态(设备离线 / 列表未同步)影响。
- const deviceId = target.deviceId
- ?? deviceIdForSession(target.sessionId)
+ // 与打开链接使用同一顺序:重新连接后的设备或共享任务本地句柄优先,
+ // 未同步的归档任务仍用链接冻结值,最后保留队列里的来源提示。
+ const deviceId = resolveSessionLinkDeviceId({
+ listedDeviceId: deviceIdForSession(target.sessionId),
+ linkedDeviceId: target.deviceId,
+ })
?? previousDeviceIds.get(key)
?? previousDeviceIdsBySession.get(target.sessionId);
refs.push({