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(companion-cloud): D1 tell an offline main computer from one that has not opened remote control

nanad98d03097ee8
diff --git a/apps/desktop/src/main/companion-cloud/view.ts b/apps/desktop/src/main/companion-cloud/view.ts
index 9e4e90a153..cd02aafa71 100644
--- a/apps/desktop/src/main/companion-cloud/view.ts
+++ b/apps/desktop/src/main/companion-cloud/view.ts
@@ -18,7 +18,8 @@ export async function companionCloudView(
if (!actor.homeDeviceId) return { ...actor, homeDevice: null };
const isSelf = actor.homeDeviceId === snapshot.selfDeviceId;
const device = devices.find(candidate => candidate.deviceId === actor.homeDeviceId);
- return { ...actor, homeDevice: { deviceId: actor.homeDeviceId, name: device?.name ?? '', online: isSelf || device?.online === true, isSelf } };
+ return { ...actor, homeDevice: { deviceId: actor.homeDeviceId, name: device?.name ?? '', online: isSelf || device?.online === true,
+ ...(device ? { remoteControlEnabled: device.remoteControlEnabled } : {}), isSelf } };
}),
};
}
diff --git a/apps/desktop/src/renderer/features/bots/CloudCompanionOfflineView.tsx b/apps/desktop/src/renderer/features/bots/CloudCompanionOfflineView.tsx
index 5172cc319a..f5ea0da83d 100644
--- a/apps/desktop/src/renderer/features/bots/CloudCompanionOfflineView.tsx
+++ b/apps/desktop/src/renderer/features/bots/CloudCompanionOfflineView.tsx
@@ -29,8 +29,8 @@ export interface CloudCompanionOfflineViewProps {
avatarColor?: string | null;
/** Home computer name; empty when this device never saw it. */
deviceName: string;
- /** The home is online but does not allow remote control from here. */
- reachable?: boolean;
+ /** The home is online but has not opened remote control; otherwise it is simply not reachable. */
+ controlOff?: boolean;
}
type TakeOverState =
@@ -39,7 +39,7 @@ type TakeOverState =
| { kind: 'conflict'; device: string }
| { kind: 'error'; key: string };
-export function CloudCompanionOfflineView({ botId, deviceId, name, avatar, avatarColor, deviceName, reachable = false }: CloudCompanionOfflineViewProps) {
+export function CloudCompanionOfflineView({ botId, deviceId, name, avatar, avatarColor, deviceName, controlOff = false }: CloudCompanionOfflineViewProps) {
const { t } = useTranslation();
const navigate = useNavigate();
const devices = useDeviceLinkDeviceList();
@@ -136,7 +136,7 @@ export function CloudCompanionOfflineView({ botId, deviceId, name, avatar, avata
<BotAvatar bot={identity} size="sm" />
<div className="min-w-0 flex-1">
<p className="text-14 font-medium text-[var(--text-primary)]">
- {t(reachable ? 'bots.cloud.homeUnreachable' : 'bots.cloud.homeOffline', { device })}
+ {t(controlOff ? 'bots.cloud.homeControlOff' : 'bots.cloud.homeOffline', { device })}
</p>
<p className="mt-0.5 text-12 text-[var(--text-secondary)]">
{state.kind === 'running' ? t('bots.cloud.takingOver', { name })
diff --git a/apps/desktop/src/renderer/features/bots/RemoteBotSessionView.tsx b/apps/desktop/src/renderer/features/bots/RemoteBotSessionView.tsx
index 857525ad1b..aae6c83f98 100644
--- a/apps/desktop/src/renderer/features/bots/RemoteBotSessionView.tsx
+++ b/apps/desktop/src/renderer/features/bots/RemoteBotSessionView.tsx
@@ -119,7 +119,7 @@ export function RemoteBotSessionView() {
avatar={bot?.avatar || cloudActor.avatar}
avatarColor={bot?.avatarColor}
deviceName={bot?.deviceName || cloudActor.homeDevice?.name || ''}
- reachable={!bot && cloudActor.homeDevice?.online === true}
+ controlOff={!bot && cloudActor.homeDevice?.online === true && cloudActor.homeDevice.remoteControlEnabled === false}
/>
</Suspense>
);
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/companionCloudUi.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/companionCloudUi.test.tsx
index 628c5b4b95..0647b85381 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/companionCloudUi.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/companionCloudUi.test.tsx
@@ -121,6 +121,14 @@ describe('CloudCompanionOfflineView', () => {
expect(screen.getByText('bots.cloud.readOnlyNote')).toBeTruthy();
});
+ it('says the main computer is offline unless it is online with remote control off', async () => {
+ maker.getCompanionTranscript.mockResolvedValue(page);
+ const { rerender } = renderView();
+ expect(screen.getByText('bots.cloud.homeOffline:{"device":"Laptop"}')).toBeTruthy();
+ rerender(<CloudCompanionOfflineView botId="mia" deviceId="laptop" name="Mia" deviceName="Laptop" controlOff />);
+ expect(screen.getByText('bots.cloud.homeControlOff:{"device":"Laptop"}')).toBeTruthy();
+ });
+
it('shows the files of a cloud message, brought from the room', async () => {
maker.getCompanionTranscript.mockResolvedValue({ messages: [
{ id: 'm1', seq: '1', role: 'user', text: '', createdAt: 1, attachments: [{ mediaId: 'media-1', name: 'cat.png' }] }] });
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/remoteBotSession.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/remoteBotSession.test.tsx
index dc5196ba31..3cf10245c6 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/remoteBotSession.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/remoteBotSession.test.tsx
@@ -11,6 +11,7 @@ const h = vi.hoisted(() => ({
merge: vi.fn(),
view: vi.fn(),
online: true,
+ listed: true,
lastReplyAt: 0,
cloud: { enabled: false, selfDeviceId: null, humanActorId: null, actors: [], demotedBotIds: [] } as import('../../../../shared/companionCloud').CompanionCloudSnapshot,
cloudView: vi.fn(),
@@ -23,7 +24,7 @@ vi.mock('react-router-dom', () => ({ useParams: () => ({ deviceId: 'home', botId
vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
vi.mock('../useRemoteBots', () => ({
markRemoteBotRead: h.markRead,
- useRemoteBots: () => [
+ useRemoteBots: () => !h.listed ? [] : [
{
id: 'writer',
deviceId: 'home',
@@ -56,6 +57,7 @@ import { CLOUD_HOME_GRACE_MS, RemoteBotSessionView } from '../RemoteBotSessionVi
beforeEach(() => {
h.markRead.mockClear();
h.online = true;
+ h.listed = true;
h.lastReplyAt = 0;
h.cloud = { enabled: false, selfDeviceId: null, humanActorId: null, actors: [], demotedBotIds: [] };
h.cloudView.mockReset();
@@ -153,3 +155,20 @@ it('keeps the open chat through a brief drop, then shows the cloud conversation
rerender(<RemoteBotSessionView />);
await waitFor(() => expect(h.view).toHaveBeenLastCalledWith(expect.objectContaining({ readOnly: true })));
});
+
+it('calls a main computer that is not listed offline, and "control off" only when it reports remote control off', async () => {
+ h.listed = false;
+ const home = { deviceId: 'home', name: 'Home', online: true, isSelf: false };
+ const actor = { id: 'a-writer', externalId: 'writer', name: 'Writer', avatar: null, homeDeviceId: 'home', homeDevice: home };
+ h.cloud = { enabled: true, selfDeviceId: 'desk', humanActorId: 'human', demotedBotIds: [], actors: [actor] };
+ const { rerender } = render(<RemoteBotSessionView />);
+ await screen.findByText('cloud-offline-view');
+ // Online in the device list but not answering (a stale presence): same as offline.
+ expect(h.cloudView).toHaveBeenLastCalledWith(expect.objectContaining({ controlOff: false }));
+ h.cloud = { ...h.cloud, actors: [{ ...actor, homeDevice: { ...home, remoteControlEnabled: true } }] };
+ rerender(<RemoteBotSessionView />);
+ expect(h.cloudView).toHaveBeenLastCalledWith(expect.objectContaining({ controlOff: false }));
+ h.cloud = { ...h.cloud, actors: [{ ...actor, homeDevice: { ...home, remoteControlEnabled: false } }] };
+ rerender(<RemoteBotSessionView />);
+ expect(h.cloudView).toHaveBeenLastCalledWith(expect.objectContaining({ controlOff: true }));
+});
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index becca59ed4..b143812449 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -9970,7 +9970,7 @@
"homeLabel": "Main Computer",
"thisComputer": "This computer",
"homeOffline": "Main computer “{{device}}” is offline",
- "homeUnreachable": "Main computer “{{device}}” doesn’t allow remote control",
+ "homeControlOff": "Main computer “{{device}}” doesn’t allow remote control",
"continueHere": "Continue on This Computer",
"takeOverHint": "{{name}} will run here from now on, and the conversation below comes along.",
"takingOver": "Getting {{name}} ready on this computer…",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index ecd2636a59..73357a8fff 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -9936,7 +9936,7 @@
"homeLabel": "メインのパソコン",
"thisComputer": "このパソコン",
"homeOffline": "メインのパソコン「{{device}}」がオフラインです",
- "homeUnreachable": "メインのパソコン「{{device}}」はリモート操作を許可していません",
+ "homeControlOff": "メインのパソコン「{{device}}」はリモート操作を許可していません",
"continueHere": "このパソコンで続ける",
"takeOverHint": "このパソコンで続けると、{{name}} はこちらで動作し、下の会話も引き継がれます。",
"takingOver": "このパソコンで {{name}} を準備しています…",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 1619dba7ff..659ffe4e90 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -9936,7 +9936,7 @@
"homeLabel": "주 컴퓨터",
"thisComputer": "이 컴퓨터",
"homeOffline": "주 컴퓨터 '{{device}}' 오프라인",
- "homeUnreachable": "주 컴퓨터 '{{device}}'에서 원격 제어를 허용하지 않았습니다",
+ "homeControlOff": "주 컴퓨터 '{{device}}'에서 원격 제어를 허용하지 않았습니다",
"continueHere": "이 컴퓨터에서 계속하기",
"takeOverHint": "이 컴퓨터에서 계속하면 {{name}}이(가) 여기에서 실행되고 아래 대화도 함께 옮겨집니다.",
"takingOver": "이 컴퓨터에서 {{name}}을(를) 준비하는 중…",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 6e548a8ea8..e38106eba1 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -9936,7 +9936,7 @@
"homeLabel": "主力电脑",
"thisComputer": "这台电脑",
"homeOffline": "主力电脑「{{device}}」离线",
- "homeUnreachable": "主力电脑「{{device}}」没有开放远程控制",
+ "homeControlOff": "主力电脑「{{device}}」没有开放远程控制",
"continueHere": "在这台电脑继续",
"takeOverHint": "在这台电脑继续后,{{name}} 改在这里运行,下面的对话一起带过来。",
"takingOver": "正在这台电脑上准备 {{name}}…",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index 0f600030bd..8f8e577e4e 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -9936,7 +9936,7 @@
"homeLabel": "主力電腦",
"thisComputer": "這台電腦",
"homeOffline": "主力電腦「{{device}}」離線",
- "homeUnreachable": "主力電腦「{{device}}」沒有開放遠端控制",
+ "homeControlOff": "主力電腦「{{device}}」沒有開放遠端控制",
"continueHere": "在這台電腦繼續",
"takeOverHint": "在這台電腦繼續後,{{name}} 改在這裡執行,下面的對話一起帶過來。",
"takingOver": "正在這台電腦上準備 {{name}}…",
diff --git a/apps/desktop/src/shared/companionCloud.ts b/apps/desktop/src/shared/companionCloud.ts
index b0f8e4c8e7..4dc52879c9 100644
--- a/apps/desktop/src/shared/companionCloud.ts
+++ b/apps/desktop/src/shared/companionCloud.ts
@@ -4,6 +4,8 @@ export interface CompanionCloudHomeDevice {
/** Device-link name; empty when the device is not in this account's device list. */
name: string;
online: boolean;
+ /** The device list says this computer allows remote control; absent when the list had no entry for it. */
+ remoteControlEnabled?: boolean;
isSelf: boolean;
}
diff --git a/docs/product-rules/cloud-companions.md b/docs/product-rules/cloud-companions.md
index c86e8e455c..5e5d055848 100644
--- a/docs/product-rules/cloud-companions.md
+++ b/docs/product-rules/cloud-companions.md
@@ -88,6 +88,7 @@
- 桌面:主力电脑持续连不上超过 15 秒,或打开时就连不上,聊天区改为云端对话(只读)与横幅
「主力电脑「<名字>」离线 · 在这台电脑继续」。
- 这台设备从没列到过主力电脑名下的伙伴(只能从云端补行),点开直接进入云端对话。
+ - 横幅只在设备列表明确说主力电脑在线、但它没有开放「允许同账号设备控制本机」时写「没有开放远程控制」;其余情况(进程不在、连不上、在线状态还没刷新)都按离线处理。
- 云端对话与在线聊天显示同样的消息:主人发的消息(包括主人在主力电脑上直接输入的)都上云;别的来源
(任务、其他伙伴、插件、共享成员、定时任务、IM 渠道、群聊)发进来的消息加「〔来自…〕」前缀;只有不在聊天里
显示的内部续接输入不上云。