π€― 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(agent-identity): title mail-woken topics with the mail subject (#22638)
Arvin Xued78f0dc975f
diff --git a/apps/server/src/services/agentIdentity/__tests__/mailWake.test.ts b/apps/server/src/services/agentIdentity/__tests__/mailWake.test.tsindex 076b06a4f86..9891c7c2631 100644--- a/apps/server/src/services/agentIdentity/__tests__/mailWake.test.ts+++ b/apps/server/src/services/agentIdentity/__tests__/mailWake.test.ts@@ -518,6 +518,7 @@ describe('mail digest flush', () => {expect(runs[0].params.hooks).toEqual([expect.objectContaining({ id: `agent-inbox-report:${accountId}`, type: 'onComplete' }),]);+ expect(runs[0].params.title).toBe('Agent workloads +1');expect(own).toContain('2 messages arrived');expect(own).not.toContain('launchdriftcloud');expect(fenced.startsWith('<untrusted_inbox>')).toBe(true);diff --git a/apps/server/src/services/agentIdentity/__tests__/waker.test.ts b/apps/server/src/services/agentIdentity/__tests__/waker.test.tsindex 1dcfd08efb2..ef507cae470 100644--- a/apps/server/src/services/agentIdentity/__tests__/waker.test.ts+++ b/apps/server/src/services/agentIdentity/__tests__/waker.test.ts@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';import { TopicStartReservationError } from '@/server/services/aiAgent/topicStartReservation';+import { buildInboxTopicTitle } from '../untrusted';import { createAgentInboundWaker } from '../waker';const { execAgent, findThreadTopicId, findTopic, markWoken } = vi.hoisted(() => ({@@ -85,3 +86,31 @@ describe('inbound waker β thread topics', () => {consoleError.mockRestore();});});++describe('inbound waker β topic title', () => {+ it('titles the topic with the mail subject rather than the prompt', async () => {+ findThreadTopicId.mockResolvedValue(undefined);+ execAgent.mockResolvedValueOnce({ topicId: 'tpc_new' });++ await waker.wake({ account, message });++ expect(execAgent).toHaveBeenCalledWith(expect.objectContaining({ title: 'Re: hello' }));+ });+});++describe('buildInboxTopicTitle', () => {+ it('counts the other messages of a digest behind the first subject', () => {+ expect(buildInboxTopicTitle([{ subject: null }, { subject: 'B' }, { subject: 'C' }])).toBe(+ 'B +2',+ );+ });++ it('flattens folded whitespace and caps a long subject', () => {+ expect(buildInboxTopicTitle([{ subject: ' a\r\n b ' }])).toBe('a b');+ expect(buildInboxTopicTitle([{ subject: 'x'.repeat(120) }])).toBe(`${'x'.repeat(100)}β¦`);+ });++ it.each([null, '', ' '])('leaves the title to the run for subject %j', (subject) => {+ expect(buildInboxTopicTitle([{ subject }])).toBeUndefined();+ });+});diff --git a/apps/server/src/services/agentIdentity/untrusted.ts b/apps/server/src/services/agentIdentity/untrusted.tsindex f715c7d1408..f0dfe192d45 100644--- a/apps/server/src/services/agentIdentity/untrusted.ts+++ b/apps/server/src/services/agentIdentity/untrusted.ts@@ -60,6 +60,27 @@ export const toUntrustedInboxEntry = (};};+/** Longest subject a topic title keeps; the mail itself stays readable in the run. */+const TOPIC_TITLE_MAX_CHARS = 100;++/**+ * The title of a topic a mail run opens: the subject, plus how many more messages share the run.+ * Undefined without a usable subject, which leaves the title to the run's own default.+ */+export const buildInboxTopicTitle = (+ messages: Pick<AgentInboxEntry, 'subject'>[],+): string | undefined => {+ const subject = messages.map((m) => m.subject?.replaceAll(/\s+/g, ' ').trim()).find(Boolean);+ if (!subject) return;++ const title =+ subject.length > TOPIC_TITLE_MAX_CHARS+ ? `${subject.slice(0, TOPIC_TITLE_MAX_CHARS)}β¦`+ : subject;++ return messages.length > 1 ? `${title} +${messages.length - 1}` : title;+};+/*** Render inbound messages as one fenced block. The payload is JSON so every* attacker-controlled string is quoted and escaped; the fence tag isdiff --git a/apps/server/src/services/agentIdentity/wake/digest.ts b/apps/server/src/services/agentIdentity/wake/digest.tsindex 9360d58b04f..da52831c674 100644--- a/apps/server/src/services/agentIdentity/wake/digest.ts+++ b/apps/server/src/services/agentIdentity/wake/digest.ts@@ -16,7 +16,7 @@ import {INBOX_RUN_INTERVENTION,OWNER_CHANNEL_INSTRUCTION,} from '../ownerChannel';-import { fenceUntrustedInbox, toUntrustedInboxEntry } from '../untrusted';+import { buildInboxTopicTitle, fenceUntrustedInbox, toUntrustedInboxEntry } from '../untrusted';import type { ResolvedWakeConfig } from './config';import { resolveWakeConfig } from './config';@@ -120,6 +120,7 @@ export const createDigestRunStarter =appContext: { scope: 'agent' },hooks: [createOwnerChannelReportHook(db, account.id)],prompt: buildDigestPrompt(account, messages),+ title: buildInboxTopicTitle(messages),trigger: RequestTrigger.Inbox,userInterventionConfig: INBOX_RUN_INTERVENTION,});diff --git a/apps/server/src/services/agentIdentity/waker.ts b/apps/server/src/services/agentIdentity/waker.tsindex b3c3d5fe419..0c6a764e6a5 100644--- a/apps/server/src/services/agentIdentity/waker.ts+++ b/apps/server/src/services/agentIdentity/waker.ts@@ -14,7 +14,7 @@ import {INBOX_RUN_INTERVENTION,OWNER_CHANNEL_INSTRUCTION,} from './ownerChannel';-import { fenceUntrustedInbox, toUntrustedInboxEntry } from './untrusted';+import { buildInboxTopicTitle, fenceUntrustedInbox, toUntrustedInboxEntry } from './untrusted';/** Body budget for the wake prompt; the full text stays readable through the tool. */const WAKE_BODY_PREVIEW_CHARS = 2000;@@ -65,6 +65,7 @@ export const createAgentInboundWaker = (db: LobeChatDatabase): AgentInboundWakerappContext: { scope: 'agent', topicId },hooks: [createOwnerChannelReportHook(db, account.id)],prompt: buildInboundPrompt(account, message),+ title: buildInboxTopicTitle([message]),trigger: RequestTrigger.Inbox,userInterventionConfig: INBOX_RUN_INTERVENTION,});