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(chat): keep mixed thread-share content as ordinary messages

Dash18f07b8b4ace
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 b6f6707a70..36d5f0de54 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
@@ -1724,6 +1724,34 @@ describe('Chat Server result delivery and refresh', () => {
expect(fixture.handle.mock.calls.some(([route]) => route.includes(`/messages/${shares[0].id}/continue`))).toBe(false);
});
+ it('keeps mixed-card text visible and eligible for discussion without marking it as a shared reply', async () => {
+ const mixed = msg(execution.source_message_id, 9, selfId, {
+ content: [...shareCard(botReply), { type: 'text', text: 'Bot, summarize this extra text' }],
+ });
+ fixture.handle.mockImplementation((route, method, body) => {
+ if (route.endsWith('/snapshot')) return { body: { room: room(roomId), members, messages: [mixed], cursor: '9' } };
+ if (route.startsWith(`/conversations/${roomId}/messages?`)) return { body: [mixed] };
+ if (route.endsWith('/executions')) return { body: [] };
+ return threadResponse(route, method, body);
+ });
+ const result = await service.getGroup(roomId);
+ if (!result.ok) throw new Error('Expected group');
+ expect(result.group.messages[0].threadShare).toBeUndefined();
+ expect(result.group.messages[0].content).toContain('Bot, summarize this extra text');
+ expect(await service.continueRound(roomId)).toEqual({ ok: true });
+ expect(fixture.handle).toHaveBeenCalledWith(`/conversations/${roomId}/messages/${mixed.id}/continue`, 'POST', expect.anything());
+
+ claimed = false;
+ fixture.handle.mockImplementation((route, method, body) => route.includes('all=true') ? { body: [mixed] }
+ : 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;
+ const history = [...prompt.matchAll(/<untrusted-data>\n(.*?)\n<\/untrusted-data>/g)].map(match => JSON.parse(match[1])).find(block => block.messages)!.messages;
+ expect(history.find((m: { id: string }) => m.id === mixed.id)).toMatchObject({ text: result.group.messages[0].content });
+ expect(history.find((m: { id: string }) => m.id === mixed.id)).not.toHaveProperty('sharedReplyId');
+ });
+
it('tells companions a share is a reference whose quoted @names address no one', async () => {
claimed = false;
fixture.handle.mockImplementation((route, method, body) => route.includes('all=true')
diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.md
index d88ac05ff3..37909ac483 100644
--- a/docs/product-rules/bot-group-chat.md
+++ b/docs/product-rules/bot-group-chat.md
@@ -556,7 +556,8 @@ Desktop 主聊天直接展示话题里的最新回复,并能把话题回复贴
自己贴过的,菜单变为「在群聊中查看」。贴回接口返回的消息 ID 会保留下来;那条贴回在主群更早的记录里、还没加载时,会提示往上加载。
主群未加载到的历史贴回,需要服务端提供按回复查询的索引才能显示状态;在此之前,重复贴回仍由服务端幂等去重。
- **持久化引用**:贴回是由分享者在主聊天发的一条新消息,内容只有一个 `cindy.thread-share` 卡片(revision 1),`data` 仅含 `messageId` 与
- `threadRootId`。客户端渲染时按 ID 读取服务器上这条回复的当前版本,原作者、正文和附件都来自服务器,卡片里的文字只是旧客户端的回退显示,
+ `threadRootId`。只有内容恰好是这一个有效卡片时才识别为贴回;混有文字、媒体或其他卡片时整条按普通消息处理,界面与伙伴上下文都保留正文。
+ 客户端渲染时按 ID 读取服务器上这条回复的当前版本,原作者、正文和附件都来自服务器,卡片里的文字只是旧客户端的回退显示,
不能借卡片冒充原作者。来源在后台读取,读取中显示「正在读取原回复…」。目标已删除、读者无权查看(服务器返回 404/403)、
或 ID 与所属话题不一致时,显示「原回复已删除,或你无权查看」。新版客户端在任何状态下都不显示卡片的回退文字,复制也不会带出这段文字;
贴回消息自己成为话题根时,话题面板里用同一个引用块展示,附件也一起显示。原回复留在话题里不移动;
diff --git a/packages/maker-shared/src/__tests__/botGroupThreadShare.test.ts b/packages/maker-shared/src/__tests__/botGroupThreadShare.test.ts
index 021f0b5b15..6be5bcfd13 100644
--- a/packages/maker-shared/src/__tests__/botGroupThreadShare.test.ts
+++ b/packages/maker-shared/src/__tests__/botGroupThreadShare.test.ts
@@ -22,6 +22,15 @@ describe('thread share card', () => {
expect(botGroupThreadShareOperationId(reply)).toMatch(/^[a-zA-Z0-9_.:-]{8,160}$/);
});
+ it.each(['text', 'media', 'card'])('keeps a share mixed with another %s block as ordinary content in either order', type => {
+ const card = buildBotGroupThreadShareCard({ messageId: reply, threadRootId: root, authorName: 'A', text: 'reply' });
+ const extra = type === 'card' ? card : { type };
+ for (const content of [[card, extra], [extra, card]]) {
+ expect(readBotGroupThreadShareCard({ threadRootId: null, content })).toBeNull();
+ }
+ expect(readBotGroupThreadShareCard({ content: [] })).toBeNull();
+ });
+
it.each([
['inside a thread', { threadRootId: root }],
['deleted', { deleted: true, threadRootId: null }],
diff --git a/packages/maker-shared/src/botGroupChat.ts b/packages/maker-shared/src/botGroupChat.ts
index 49758bb0c4..3b8380d3e2 100644
--- a/packages/maker-shared/src/botGroupChat.ts
+++ b/packages/maker-shared/src/botGroupChat.ts
@@ -205,8 +205,11 @@ export function readBotGroupThreadShareCard(message: {
}): { messageId: string; threadRootId: string } | null {
// A share lives in the main chat; a card copied into a thread is just content.
if (message.deleted === true || (message.threadRootId !== null && message.threadRootId !== undefined)) return null;
- const card = message.content.find(block => block.type === 'card' && block.namespace === BOT_GROUP_THREAD_SHARE_NAMESPACE
- && block.schemaRevision === THREAD_SHARE_REVISION);
+ // Classify the whole message, not a block: hiding mixed content would disagree with Agent history.
+ if (message.content.length !== 1) return null;
+ const card = message.content[0];
+ if (card?.type !== 'card' || card.namespace !== BOT_GROUP_THREAD_SHARE_NAMESPACE
+ || card.schemaRevision !== THREAD_SHARE_REVISION) return null;
if (!card?.data || typeof card.data !== 'object' || Array.isArray(card.data)) return null;
const { messageId, threadRootId } = card.data as Record<string, unknown>;
if (typeof messageId !== 'string' || typeof threadRootId !== 'string' || !UUID.test(messageId) || !UUID.test(threadRootId)