Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): 别的电脑连不上时,工作台保留旧内容但经那台转来的行按离线显示
Chris434e1235bbdf
diff --git a/apps/desktop/src/renderer/features/bots/BotWorkbench.tsx b/apps/desktop/src/renderer/features/bots/BotWorkbench.tsxindex 7cee9cafa0..e52ea00ff7 100644--- a/apps/desktop/src/renderer/features/bots/BotWorkbench.tsx+++ b/apps/desktop/src/renderer/features/bots/BotWorkbench.tsx@@ -87,13 +87,19 @@ export function BotWorkbench({const navigate = useNavigate();const devices = useDeviceLinkDeviceList();const self = devices?.find((device) => device.isSelf) ?? null;- const hostName = hostDeviceId ? (devices?.find((device) => device.deviceId === hostDeviceId)?.name ?? null) : null;+ const hostDevice = hostDeviceId ? (devices?.find((device) => device.deviceId === hostDeviceId) ?? null) : null;+ const hostName = hostDevice?.name ?? null;const host = useMemo(() => ({ deviceId: hostDeviceId, deviceName: hostName, selfDeviceId: self?.deviceId ?? null }),[hostDeviceId, hostName, self?.deviceId],);const { glance: raw, failed, fetchedAt } = useBotGlance(botId, host);- const glance = useMemo<BotGlance | null>(() => (raw ? rebaseGlance(raw, host) : null), [raw, host]);+ // 设备清单说它离线,或最近一次读取失败:保留上一份内容,但经那台转来的行按离线显示。+ const hostOnline = !hostDeviceId || (hostDevice?.online !== false && !failed);+ const glance = useMemo<BotGlance | null>(+ () => (raw ? rebaseGlance(raw, { ...host, online: hostOnline }) : null),+ [raw, host, hostOnline],+ );const now = useNow(30_000);const canNavigate = !isSidebarWindow();diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotWorkbenchView.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/BotWorkbenchView.test.tsxindex 9dce46d4cd..5ccd83562e 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/BotWorkbenchView.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotWorkbenchView.test.tsx@@ -197,6 +197,27 @@ it('reads a teammate on another computer from that computer and answers its ownexpect(m.remoteApi.getPendingInteractions).toHaveBeenCalledWith('s5');});+// 依据:工作台合同「别的电脑离线时不能替主人操作」;缺口:读过一次后那台断开,保留的旧内容仍显示在线、+// 「允许」可点。最小失败输入:首读成功、变化推送后的重读失败。tier:renderer unit。+it('greys out a remote teammate\'s rows once that computer stops answering, keeping the last content', async () => {+ let push: ((event: unknown, stamp: unknown) => void) | undefined;+ (window as unknown as { electronAPI: { deviceLink: { onRemotePush: unknown } } }).electronAPI.deviceLink.onRemotePush =+ (cb: (event: unknown, stamp: unknown) => void) => { push = cb; return () => undefined; };+ remoteInvoke.mockResolvedValueOnce(glance({+ waiting: [row({ sessionId: 's7', question: '删掉旧分支吗?', waitingFor: 'permission', requestId: 'r-7' })],+ }));+ render(<BotWorkbench botId="bot-1" hostDeviceId="dev-2" />);+ const allow = () => within(screen.getByText('删掉旧分支吗?').closest('li')!)+ .getByRole('button', { name: 'bots.workbench.glance.allow' }) as HTMLButtonElement;+ await screen.findByText('删掉旧分支吗?');+ expect(allow().disabled).toBe(false);++ remoteInvoke.mockRejectedValueOnce(new Error('offline'));+ act(() => push?.({ deviceId: 'dev-2', channel: 'maker:bot-autonomy:changed', payload: { botIds: ['bot-1'] } }, {}));+ await waitFor(() => expect(allow().disabled).toBe(true));+ expect(screen.getByText('删掉旧分支吗?')).toBeTruthy();+});+it('never approves a confirmation that carries no request id; it opens the task instead', async () => {// 宿主把 kind 含 confirm 的交互归成权限类但没有 requestId:那件任务里唯一的权限请求不一定是这一行。const confirmRow = row({ sessionId: 's3', question: '确认要发布吗?', waitingFor: 'permission', requestId: null });diff --git a/apps/desktop/src/renderer/features/bots/botGlance.ts b/apps/desktop/src/renderer/features/bots/botGlance.tsindex 723103c092..f9f30f8645 100644--- a/apps/desktop/src/renderer/features/bots/botGlance.ts+++ b/apps/desktop/src/renderer/features/bots/botGlance.ts@@ -28,6 +28,11 @@ export interface GlanceHost {deviceName?: string | null;/** 这台电脑在 device-link 里的 id,用来把远端记成「别的电脑」的行认回本机。 */selfDeviceId?: string | null;+ /**+ * 伙伴所在电脑当前能不能连上(设备在线且最近一次读取成功)。读不到时界面保留上一份内容,+ * 但经那台转来的行一律按离线显示(变灰、不能「允许」),不能继续显示成在线。+ */+ online?: boolean;}/** 远程任务的 sessionId 带 `deviceId::` 前缀;导航与交互要用那台电脑上的裸 id。 */@@ -41,14 +46,22 @@ export function bareGlanceSessionId(row: Pick<GlanceRow, 'sessionId' | 'deviceIdfunction rebaseRow(row: GlanceRow, host: GlanceHost): GlanceRow {if (!host.deviceId) return row;const bare = bareGlanceSessionId(row);+ const reachable = host.online !== false;if (!row.deviceId) {// 那台的本机任务:从这台看就是那台电脑上的任务。- return { ...row, deviceId: host.deviceId, deviceName: host.deviceName ?? row.deviceName, sessionId: `${host.deviceId}::${bare}` };+ return {+ ...row,+ deviceId: host.deviceId,+ deviceName: host.deviceName ?? row.deviceName,+ online: row.online && reachable,+ sessionId: `${host.deviceId}::${bare}`,+ };}if (host.selfDeviceId && row.deviceId === host.selfDeviceId) {return { ...row, deviceId: null, deviceName: null, online: true, sessionId: bare };}- return row;+ // 第三台电脑的行是经那台转来的:那台连不上时状态无从确认,同样按离线显示。+ return reachable ? row : { ...row, online: false };}export function rebaseGlance(glance: BotGlance, host: GlanceHost): BotGlance {