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(bots): 手机远程查看时贴回卡片附件不带本机路径;话题内唤醒时背景里的贴回也标为引用

Dash3704c22b4c73
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botGroupRemoteResourceProvider.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botGroupRemoteResourceProvider.test.ts
index b1fc636035..6190af1cd0 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/botGroupRemoteResourceProvider.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/botGroupRemoteResourceProvider.test.ts
@@ -25,8 +25,10 @@ import {
BOT_GROUP_CHAT_PRIMITIVE,
BOT_GROUP_REMOTE_COLLECTION_ID,
BOT_GROUP_REMOTE_RESOURCE_KIND,
+ type BotGroupAttachment,
type BotGroupDetail,
type BotGroupSummary,
+ type BotGroupThreadShareView,
} from '../../../shared/botGroupChat.js';
const context = { controllerDeviceId: 'phone-1' };
@@ -382,6 +384,23 @@ describe('bot group remote resources', () => {
expect(plain.blocks?.[0]?.fallbackMarkdown).toContain('📎 photo.png 📎 需求.pdf');
});
+ it('keeps host paths off the attachments of shared thread replies', async () => {
+ const file: BotGroupAttachment = { id: 'a2', name: '需求.pdf', category: 'pdf', mimeType: 'application/pdf', size: 4, url: null, path: '/Users/me/cache/需求.pdf' };
+ const share: BotGroupThreadShareView = {
+ messageId: 'r1', threadRootId: 'm1', status: 'available', authorKind: 'bot', authorBotId: 'abu', authorName: '阿布',
+ sharedByAuthor: false, content: '附件在这', attachments: [file], createdAt: 20, edited: false,
+ };
+ service.getGroup.mockResolvedValue({ ok: true, group: detail({
+ messages: [{ ...detail().messages[0]!, id: 's1', threadShare: share }],
+ threadShareUpdates: { s0: { ...share, messageId: 'r0' } },
+ }) });
+ const rich = await remoteResourceRegistry.get(context, { client: client([BOT_GROUP_CHAT_PRIMITIVE]), ref: ref('g1') });
+ const data = rich.blocks![0]!.data as ReturnType<typeof botGroupRemoteChatData>;
+ expect(data.messages[0]!.threadShare!.attachments).toEqual([{ ...file, path: null }]);
+ expect(data.threadShareUpdates!.s0!.attachments).toEqual([{ ...file, path: null }]);
+ expect(JSON.stringify(rich)).not.toContain('/Users/me/cache');
+ });
+
it('writes nothing once the computer has switched accounts during the checks', async () => {
// The first owner check runs after the visibility reads; by then the account has changed.
h.ownerCurrent = () => false;
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
index d2f635c892..9b7e60038d 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
@@ -1449,6 +1449,22 @@ describe('Chat Server result delivery and refresh', () => {
expect(history.find((m: { id: string }) => m.id === shares[0].id)).toMatchObject({ sharedReplyId: botReply });
expect(history.find((m: { id: string }) => m.id === execution.source_message_id)).not.toHaveProperty('sharedReplyId');
});
+
+ it('marks a share in the main-group background of a Thread request as a reference too', async () => {
+ claimed = false;
+ const rootId = '90000000-0000-4000-8000-0000000000bb';
+ const source = { ...msg(execution.source_message_id, 2, selfId), threadRootId: rootId, content: [{ type: 'text', text: 'Bot, summarize' }] };
+ fixture.handle.mockImplementation((route, method, body) => route.includes('all=true') || route.includes('threadRootId=') ? { body: [source] }
+ : route.startsWith(`/conversations/${roomId}/messages?limit=`) ? { body: [shares[0]] }
+ : route === `/conversations/${roomId}/messages/${rootId}` ? { body: msg(rootId, 1, selfId) }
+ : route.endsWith('/snapshot') || route.endsWith('/members') ? threadResponse(route, method, body) : response(route));
+ await vi.advanceTimersByTimeAsync(2000);
+ expect(deps.dispatch).toHaveBeenCalledOnce();
+ const prompt = vi.mocked(deps.dispatch).mock.calls[0][0].message;
+ expect(prompt).toContain('A message with sharedReplyId re-posts an existing thread reply');
+ const background = [...prompt.matchAll(/<untrusted-data>\n(.*?)\n<\/untrusted-data>/g)].map(match => JSON.parse(match[1])).find(block => block.mainGroupBackground)!.mainGroupBackground;
+ expect(background).toEqual([expect.objectContaining({ id: shares[0].id, sharedReplyId: botReply })]);
+ });
});
});
diff --git a/apps/desktop/src/main/maker-ipc/botGroupRemoteResourceProvider.ts b/apps/desktop/src/main/maker-ipc/botGroupRemoteResourceProvider.ts
index 84c152bf17..3cb890dde1 100644
--- a/apps/desktop/src/main/maker-ipc/botGroupRemoteResourceProvider.ts
+++ b/apps/desktop/src/main/maker-ipc/botGroupRemoteResourceProvider.ts
@@ -41,9 +41,11 @@ import {
BOT_GROUP_REMOTE_RESOURCE_KIND,
type BotGroupDetail,
type BotGroupFailure,
+ type BotGroupMessageView,
type BotGroupRemoteActionId,
type BotGroupRemoteChatData,
type BotGroupSummary,
+ type BotGroupThreadShareView,
} from '../../shared/botGroupChat.js';
import type { BotGroupChatService } from './botGroupChatService.js';
import { projectBotGroupExecutionFailures } from '@cindy/maker-shared/botGroupPresentation';
@@ -178,6 +180,15 @@ export function botGroupRemoteItem(group: BotGroupSummary): RemoteCollectionItem
};
}
+function withoutPaths(attachments: BotGroupMessageView['attachments']): BotGroupMessageView['attachments'] {
+ return attachments.map((attachment) => ({ ...attachment, path: null }));
+}
+
+/** A shared reply carries its own attachments, downloaded to this computer. */
+function shareWithoutPaths(share: BotGroupThreadShareView): BotGroupThreadShareView {
+ return share.attachments.length > 0 ? { ...share, attachments: withoutPaths(share.attachments) } : share;
+}
+
/** Host paths stay on the computer; the phone gets the folder name and attachment names only. */
export function botGroupRemoteChatData(detail: BotGroupDetail): BotGroupRemoteChatData {
return {
@@ -186,9 +197,12 @@ export function botGroupRemoteChatData(detail: BotGroupDetail): BotGroupRemoteCh
projectDirName: detail.projectDir ? path.basename(detail.projectDir) : null,
plans: detail.plans.map((plan) => ({ ...plan, workDir: null })),
// Older phones consume message views only; derive from this read's state here.
- messages: projectBotGroupExecutionFailures(detail.messages, detail.executionFailures).map((message) => (message.attachments.length > 0
- ? { ...message, attachments: message.attachments.map((attachment) => ({ ...attachment, path: null })) }
- : message)),
+ messages: projectBotGroupExecutionFailures(detail.messages, detail.executionFailures).map((message) => {
+ const view = message.attachments.length > 0 ? { ...message, attachments: withoutPaths(message.attachments) } : message;
+ return view.threadShare ? { ...view, threadShare: shareWithoutPaths(view.threadShare) } : view;
+ }),
+ ...(detail.threadShareUpdates ? { threadShareUpdates: Object.fromEntries(Object.entries(detail.threadShareUpdates)
+ .map(([id, share]) => [id, shareWithoutPaths(share)])) } : {}),
supportsAttachments: true,
supportsMemberRemoval: detail.serverBacked === true,
supportsSettingsManagement: detail.serverBacked === true,
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
index 679c9ce252..c8a6ca91f4 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
@@ -1955,7 +1955,8 @@ describe('more older shares than one refresh re-reads', () => {
const t = (name: string) => `bots.groupChat.server.thread.${name}`;
beforeEach(() => { vi.stubGlobal('ResizeObserver', class { observe() {} disconnect() {} }); });
- it('never keeps showing a share the refresh could not check, and gets to it within a few refreshes', async () => {
+ // Crossing the per-read cap takes more cards than a shared CI runner renders within the default.
+ it('never keeps showing a share the refresh could not check, and gets to it within a few refreshes', { timeout: 20_000 }, async () => {
type Share = NonNullable<BotGroupMessageView['threadShare']>;
const shareOf = (i: number, extra: Partial<Share> = {}): Share => ({ messageId: `reply-${i}`, threadRootId: 'root', status: 'available', authorKind: 'bot',
authorBotId: 'xiaoman', authorName: '小满', sharedByAuthor: false, content: `原文 ${i}`, attachments: [], createdAt: 1, edited: false, version: 1, ...extra });