🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(channel): mark an Agent's acknowledgement in the list preview so it raises no notification (#23639)
Lobehub Coderaae9690136b6
diff --git a/packages/database/src/repositories/channel/__tests__/replyOpening.test.ts b/packages/database/src/repositories/channel/__tests__/replyOpening.test.tsindex d4370dba1dd..2e3ff20510f 100644--- a/packages/database/src/repositories/channel/__tests__/replyOpening.test.ts+++ b/packages/database/src/repositories/channel/__tests__/replyOpening.test.ts@@ -82,6 +82,30 @@ describe('Channel reply opening', () => {expect((await jobById(db, job.id)).threadId).toBeNull();});+ it('marks the acknowledgement in the list preview, so it raises no notification, and not the answer', async () => {+ const { channel, job } = await mentionAgent();+ const repository = new ChannelRepository(db, fixture.memberId, fixture.workspaceId);+ const preview = async () =>+ (await repository.list()).find((item) => item.id === channel.id)?.lastMessage;+ expect(await preview()).toMatchObject({ opening: false });++ await execution.open(channel.id, job.id, {+ ack: 'On it, comparing the two configs first.',+ threadTitle: 'Deploy failure',+ });+ expect(await preview()).toMatchObject({+ content: 'On it, comparing the two configs first.',+ opening: true,+ thread: { title: 'Deploy failure' },+ });++ await execution.claim(channel.id, job.id, lease);+ await execution.accepted(channel.id, job.id);+ await execution.saveDraft(channel.id, job.id, 'The token expired.');+ await execution.publish(channel.id, job.id);+ expect(await preview()).toMatchObject({ content: 'The token expired.', opening: false });+ });+it('names the acknowledgement on the job, so a failed run shows under it', async () => {const { channel, job } = await mentionAgent();await execution.open(channel.id, job.id, { ack: 'Got it, checking CI.' });diff --git a/packages/database/src/repositories/channel/lastMessage.ts b/packages/database/src/repositories/channel/lastMessage.tsindex 89da11c6d7f..6966dbb611d 100644--- a/packages/database/src/repositories/channel/lastMessage.ts+++ b/packages/database/src/repositories/channel/lastMessage.ts@@ -14,6 +14,7 @@ import type { LobeChatDatabase } from '../../type';import { agentTitleSql } from '../../utils/inboxAgent';import { notTrashed } from '../../utils/softDelete';import { isAgentAuthored } from './author';+import { isOpeningAck } from './openingAck';import { messageStands } from './tombstone';/** Characters of the latest message a Channel list item carries as its preview. */@@ -45,7 +46,8 @@ const attachmentsByMessage = async (db: LobeChatDatabase, messageIds: string[])* they do for the unread count: a reply in a Thread is the conversation's latest activity, and a* preview stopped at the main conversation reads as nothing new. Trashed Threads are skipped.* A Thread is named by its title, else the first line of the message it branched from. The- * sender and attachments come along, so a list can read "Me: [Image]".+ * sender and attachments come along, so a list can read "Me: [Image]". An Agent's pre-run+ * acknowledgement is marked `opening`, so a client can show it without announcing it.*/export const channelLastMessages = async (db: LobeChatDatabase,@@ -65,6 +67,7 @@ export const channelLastMessages = async (content: sql<string>`left(${channelMessages.content}, ${LIST_PREVIEW_LENGTH})`,createdAt: channelMessages.createdAt,id: channelMessages.id,+ opening: sql<boolean>`coalesce(${isOpeningAck}, false)`.mapWith(Boolean),routingStatus: channelMessages.routingStatus,threadId: channelMessages.threadId,threadTitle: sql<string | null>`coalesce(@@ -118,6 +121,7 @@ export const channelLastMessages = async (card: row.cardType ? { name: row.cardName, type: row.cardType } : null,content: row.content,createdAt: row.createdAt,+ opening: row.opening,thread: row.threadId ? { id: row.threadId, title: row.threadTitle } : null,},];diff --git a/packages/database/src/repositories/channel/openingAck.ts b/packages/database/src/repositories/channel/openingAck.tsnew file mode 100644index 00000000000..f8970aa07c7--- /dev/null+++ b/packages/database/src/repositories/channel/openingAck.ts@@ -0,0 +1,19 @@+import { and, eq, like, sql } from 'drizzle-orm';++import { channelMessages } from '../../schemas';++/**+ * Request keys of the acknowledgements an Agent posts before its run (`openingRequestKey` in+ * `./opening`, which imports the Channel view, so the prefix is repeated here).+ */+const OPENING_REQUEST_KEY_PATTERN = 'opening:%';++/**+ * An Agent's acknowledgement before its run: it says the work started, not what came of it. One+ * a failure turned into the reply's card is news again.+ */+export const isOpeningAck = and(+ eq(channelMessages.routingStatus, 'reply'),+ like(channelMessages.requestKey, OPENING_REQUEST_KEY_PATTERN),+ sql`COALESCE(${channelMessages.metadata} ->> 'replyError', '') = ''`,+);diff --git a/packages/database/src/repositories/channel/view.ts b/packages/database/src/repositories/channel/view.tsindex ebf44e315ad..7cf6ea6bca4 100644--- a/packages/database/src/repositories/channel/view.ts+++ b/packages/database/src/repositories/channel/view.ts@@ -24,7 +24,6 @@ import {inArray,isNotNull,isNull,- like,lt,or,type SQL,@@ -53,6 +52,7 @@ import { channelAttachments, fileIdsByMessage } from './attachments';import { isAgentAuthored } from './author';import { activeMembers } from './delivery';import { ChannelError } from './error';+import { isOpeningAck } from './openingAck';import { replyWorksByMessage } from './works';export const publicMessageColumns = {@@ -278,22 +278,6 @@ const sourceTopicsByMessage = async (const THREAD_PREVIEW_LENGTH = 240;-/**- * Request keys of the acknowledgements an Agent posts before its run (`openingRequestKey` in- * `./opening`, which imports this module, so the prefix is repeated here).- */-const OPENING_REQUEST_KEY_PATTERN = 'opening:%';--/**- * An Agent's acknowledgement before its run: it says the work started, not what came of it. One- * a failure turned into the reply's card is news again.- */-const isOpeningAck = and(- eq(channelMessages.routingStatus, 'reply'),- like(channelMessages.requestKey, OPENING_REQUEST_KEY_PATTERN),- sql`COALESCE(${channelMessages.metadata} ->> 'replyError', '') = ''`,-);-type ThreadSummary = {lastNewsAt: Date | null;lastReply: Pick<ReturnType<typeof publicMessage>, 'author' | 'content' | 'createdAt' | 'id'>;diff --git a/packages/types/src/channel.ts b/packages/types/src/channel.tsindex 0c0d57b03cf..b51ce36087f 100644--- a/packages/types/src/channel.ts+++ b/packages/types/src/channel.ts@@ -782,6 +782,11 @@ export interface ChannelLastMessage {card?: { name: string | null; type: ContactCardType } | null;content: string;createdAt: Date;+ /**+ * An Agent's acknowledgement posted before its run ("got it, checking the logs first"): it says+ * the work started, not what came of it, so it raises no desktop notification.+ */+ opening?: boolean;/*** The Thread it was posted in, named by its title or else the first line of its root message;* null for the main conversation.