Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(channel): stop showing Agent replies as unavailable quotes (#22033)

AmAzing-e893acaf99c6
diff --git a/src/features/Channels/ChannelMessage.tsx b/src/features/Channels/ChannelMessage.tsx
index 0e1fb1aabc4..3c5c050b42c 100644
--- a/src/features/Channels/ChannelMessage.tsx
+++ b/src/features/Channels/ChannelMessage.tsx
@@ -17,6 +17,7 @@ import { authorAvatar, isCurrentUserAuthor, memberName } from './memberName';
import { CHANNEL_MENTION_TAG, remarkChannelMentions } from './mentionMarkdown';
import { MessageAttachments } from './MessageAttachments';
import { MessageFailureMark, MessageRoutingStatus } from './MessageReceipts';
+import { showsReplyQuote } from './replyQuote';
import { styles } from './styles';
import type { ChannelThreadDraft } from './threadDraft';
import type { ChannelReplyTarget } from './useReplyTarget';
@@ -119,7 +120,7 @@ export const ChannelMessage = ({
<CollapsibleContent key={message.id}>
<Flexbox gap={8}>
{!isRoot &&
- message.replyToId &&
+ showsReplyQuote(message) &&
(message.replyTo ? (
<Button
aria-label={t('reply.viewOriginal')}
diff --git a/src/features/Channels/replyQuote.test.ts b/src/features/Channels/replyQuote.test.ts
new file mode 100644
index 00000000000..789ed15d4bc
--- /dev/null
+++ b/src/features/Channels/replyQuote.test.ts
@@ -0,0 +1,40 @@
+import type { ChannelPublicMessage } from '@lobechat/types';
+import { describe, expect, it } from 'vitest';
+
+import { showsReplyQuote } from './replyQuote';
+
+describe('Channel reply quote', () => {
+ const original = {
+ author: { avatar: null, id: 'user-1', name: 'Ada', type: 'user' as const },
+ content: 'who is codex',
+ id: 'request',
+ sequence: 1,
+ threadId: null,
+ };
+ const message = (patch: Partial<ChannelPublicMessage>) =>
+ ({
+ replyTo: null,
+ replyToId: null,
+ routingStatus: 'skipped',
+ ...patch,
+ }) as ChannelPublicMessage;
+
+ it('does not treat the request an Agent reply answers as a quote', () => {
+ expect(
+ showsReplyQuote(message({ replyTo: original, replyToId: 'request', routingStatus: 'reply' })),
+ ).toBe(false);
+ expect(
+ showsReplyQuote(message({ replyTo: null, replyToId: 'request', routingStatus: 'reply' })),
+ ).toBe(false);
+ });
+
+ it("quotes a person's reply, including when its original is gone", () => {
+ expect(showsReplyQuote(message({ replyTo: original, replyToId: 'request' }))).toBe(true);
+ expect(showsReplyQuote(message({ replyTo: null, replyToId: 'request' }))).toBe(true);
+ });
+
+ it('shows nothing when the view does not carry the quote', () => {
+ expect(showsReplyQuote(message({ replyTo: undefined, replyToId: 'request' }))).toBe(false);
+ expect(showsReplyQuote(message({ replyToId: null }))).toBe(false);
+ });
+});
diff --git a/src/features/Channels/replyQuote.ts b/src/features/Channels/replyQuote.ts
new file mode 100644
index 00000000000..cd4b9ca97b2
--- /dev/null
+++ b/src/features/Channels/replyQuote.ts
@@ -0,0 +1,8 @@
+import type { ChannelPublicMessage } from '@lobechat/types';
+
+/**
+ * Only a person's reply quotes: an Agent reply's `replyToId` is the request it answers. A view
+ * without `replyTo` (an older server, or a persisted copy) cannot tell a deleted original.
+ */
+export const showsReplyQuote = (message: ChannelPublicMessage) =>
+ !!message.replyToId && message.routingStatus !== 'reply' && message.replyTo !== undefined;