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): 只有解析成功的贴回才算已发到群聊,来源缺失在贴回里单独报错

Dash7c3f215bffde
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 976817baf8..162a6e319c 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
@@ -1431,7 +1431,8 @@ describe('Chat Server result delivery and refresh', () => {
it.each([['a root message', rootId], ['a deleted reply', deletedReply], ['an unknown message', '70000000-0000-4000-8000-0000000000ff']])(
'refuses to share %s', async (_label, messageId) => {
const result = await service.chatServer!.shareToMain({ groupId: roomId, messageId });
- expect(result).toMatchObject({ ok: false });
+ // A missing reply reads as unavailable here; MESSAGE_NOT_FOUND stays generic elsewhere.
+ expect(result).toMatchObject({ ok: false, errorCode: 'SHARE_UNAVAILABLE' });
expect(fixture.handle.mock.calls.some(([route, method]) => route === `/conversations/${roomId}/messages` && method === 'POST')).toBe(false);
});
diff --git a/apps/desktop/src/main/maker-ipc/chatServer.ts b/apps/desktop/src/main/maker-ipc/chatServer.ts
index 9456869ec2..ff7c2a38aa 100644
--- a/apps/desktop/src/main/maker-ipc/chatServer.ts
+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts
@@ -1414,8 +1414,8 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
shareToMain: input => result(async () => {
const i = z.object({ groupId: id, messageId: id }).strict().parse(input);
const room = await resolveGroup(i.groupId);
- const source = await api<Message>(`/conversations/${room}/messages/${i.messageId}`);
- if (!isShareableThreadReply(source)) throw new Error('SHARE_UNAVAILABLE');
+ const source = await readMessage(room, i.messageId);
+ if (!source || !isShareableThreadReply(source)) throw new Error('SHARE_UNAVAILABLE');
const members = await api<Member[]>(`/conversations/${room}/members`);
const author = members.find(member => member.id === source.authorId);
const card = buildBotGroupThreadShareCard({ messageId: source.id, threadRootId: source.threadRootId!,
diff --git a/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx b/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx
index e988fede0d..cbf0ca9a08 100644
--- a/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx
@@ -362,7 +362,8 @@ function BotGroupChatContent({ groupId }: { groupId: string }) {
const shares = new Map<string, { messageId: string; bySelf: boolean }>();
for (const message of messages) {
const share = message.threadShare;
- if (!share) continue;
+ // Only a share the server resolved inside its claimed thread stands for that reply.
+ if (share?.status !== 'available') continue;
const bySelf = message.authorKind === 'user' && message.isSelf !== false;
// Prefer the reader's own share: it is the one a repeat would return.
if (!shares.has(share.messageId) || bySelf) shares.set(share.messageId, { messageId: message.id, bySelf });
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 01623e257a..0235b5d71b 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
@@ -2392,6 +2392,24 @@ describe('thread share follow-ups', () => {
expect(screen.queryByRole('menuitem', { name: t('postToMain') })).toBeNull();
});
+ it('does not count a share the server could not resolve in its claimed thread as posted', async () => {
+ // The reader's own card names the right reply but the wrong thread, so it resolved as unavailable.
+ const misplaced = msg({ id: 'my-bad-share', sequence: 2, content: '↪ 卡片',
+ threadShare: share({ messageId: 'alice-reply', threadRootId: 'elsewhere', status: 'unavailable', authorName: '', content: '' }) });
+ mocks.getBotGroup.mockResolvedValue({ ok: true, group: detail({ serverBacked: true, messages: [msg({ id: 'u1', content: '去哪玩' }), misplaced] }) });
+ mocks.thread.mockResolvedValue({ ok: true, root: msg({ id: 'u1', content: '去哪玩' }), hasMore: false,
+ replies: [msg({ id: 'alice-reply', authorKind: 'user', isSelf: false, authorName: 'Alice', content: 'Alice says hi' })] });
+ const user = userEvent.setup();
+ renderView();
+ await user.click((await screen.findAllByRole('button', { name: 'bots.groupChat.server.startTopic' }))[0]!);
+ const reply = (await within(await screen.findByRole('complementary')).findByText('Alice says hi')).closest('article')!;
+ expect(within(reply).queryByRole('button', { name: t('postedBySelf') })).toBeNull();
+ expect(within(reply).queryByRole('button', { name: t('postedToMain') })).toBeNull();
+ fireEvent.pointerDown(within(reply).getByRole('button', { name: 'chat.messageActionBar.moreActions' }), { button: 0, ctrlKey: false });
+ expect(await screen.findByRole('menuitem', { name: t('postToMain') })).toBeTruthy();
+ expect(screen.queryByRole('menuitem', { name: t('viewInMain') })).toBeNull();
+ });
+
it('keeps every failed main-chat copy retryable, across switching threads', async () => {
mocks.getBotGroup.mockResolvedValue({ ok: true, group: detail({ serverBacked: true, messages: [msg({ id: 'u1', content: 'A' }), msg({ id: 'u2', sequence: 2, content: 'B' })] }) });
mocks.reply.mockResolvedValueOnce({ ok: true, messageId: 'first' }).mockResolvedValueOnce({ ok: true, messageId: 'second' });
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsx
index fee7412fc8..e76a8295b2 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsx
@@ -6,6 +6,7 @@ import { afterEach, beforeEach, describe, expect, it, onTestFinished, vi } from
import { ChatInviteButton, ChatJoinButton, ChatMessageActions } from '../ChatServerControls';
import { ChatThreadPanel } from '../ChatThreadPanel';
import { flashThreadTarget } from '../BotGroupThreadViews';
+import { chatErrorKey } from '../chatError';
import type { BotGroupDetail, BotGroupMessageView } from '../../../../shared/botGroupChat';
import { shareSelectionStore } from '@/components/chat/shareSelectionStore';
import { queryShareableMessageIds, stripInteractiveElements } from '@/lib/shareConversationImage';
@@ -124,6 +125,11 @@ describe('chat interaction controls', () => {
expect(mocks.shareToMain).toHaveBeenCalledTimes(1);
});
+ it('names an unavailable share only for posting; a missing message elsewhere stays generic', () => {
+ expect(chatErrorKey('SHARE_UNAVAILABLE')).toBe(k('thread.shareUnavailable'));
+ expect(chatErrorKey('MESSAGE_NOT_FOUND')).toBe(k('requestFailed'));
+ });
+
it.each([[true, 'auto'], [false, 'smooth']] as const)('jumps to a shared reply without smooth scrolling when reduced motion is %s', (reduced, behavior) => {
vi.stubGlobal('matchMedia', (query: string) => ({ matches: reduced && query === '(prefers-reduced-motion: reduce)' }));
const target = document.createElement('article');
diff --git a/apps/desktop/src/renderer/features/bots/chatError.ts b/apps/desktop/src/renderer/features/bots/chatError.ts
index 4c0858f5ab..0e34ac8c80 100644
--- a/apps/desktop/src/renderer/features/bots/chatError.ts
+++ b/apps/desktop/src/renderer/features/bots/chatError.ts
@@ -4,7 +4,7 @@ export function chatErrorKey(code: string) {
if (code === 'INVITE_REVOKE_UNSUPPORTED') return key('revokeUnsupported');
if (['INVITATION_NOT_FOUND', 'INVITATION_UNAVAILABLE', 'INVALID_INPUT'].includes(code)) return key('invalidInvite');
if (code === 'MENTION_UNAVAILABLE') return 'bots.groupChat.errors.mentionUnavailable';
- if (code === 'SHARE_UNAVAILABLE' || code === 'MESSAGE_NOT_FOUND') return key('thread.shareUnavailable');
+ if (code === 'SHARE_UNAVAILABLE') return key('thread.shareUnavailable');
if (code === 'LAST_OWNER') return key('settings.lastOwner');
if (code === 'REVISION_CONFLICT') return key('settings.conflict');
if (['FORBIDDEN', 'ROLE_REQUIRED', 'OWNER_REQUIRED', 'ACTOR_NOT_OWNED', 'IDENTITY_DOMAIN_MISMATCH'].includes(code)) return key('notAllowed');