fix group chat agent mentions (#1111)

This commit is contained in:
ekko
2026-05-29 09:02:38 +08:00
committed by GitHub
parent 1373b4746b
commit 717f577380
4 changed files with 57 additions and 9 deletions
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest'
import { countTokens } from '../../packages/server/src/lib/context-compressor'
import {
estimateGroupHistoryMessageTokens,
groupBridgeReasoningDeltaFromEvent,
groupContextTokensWithFixedOverhead,
} from '../../packages/server/src/services/hermes/group-chat/agent-clients'
@@ -22,4 +23,19 @@ describe('group chat fixed context cache helpers', () => {
expect(groupContextTokensWithFixedOverhead(undefined, [{ content: 'hello' }])).toBeUndefined()
expect(groupContextTokensWithFixedOverhead(null, [{ content: 'hello' }])).toBeUndefined()
})
it('keeps spinner thinking events out of persisted group-chat reasoning', () => {
expect(groupBridgeReasoningDeltaFromEvent({
event: 'thinking.delta',
text: '(◕‿◕✿) pondering...',
})).toBeNull()
expect(groupBridgeReasoningDeltaFromEvent({
event: 'reasoning.delta',
text: 'real reasoning',
})).toBe('real reasoning')
expect(groupBridgeReasoningDeltaFromEvent({
event: 'reasoning.delta',
text: '',
})).toBeNull()
})
})
+17 -3
View File
@@ -270,15 +270,15 @@ describe('Group Chat member/agent identity sync', () => {
expect(ctx.body).toEqual({ rooms })
})
it('routes @mentions only from user messages, not agent replies', () => {
it('routes @mentions from users and bounded agent replies', () => {
const server = Object.create(GroupChatServer.prototype) as any
const emit = vi.fn()
server.rooms = new Map([
['room-1', {
hasOnlineMember: vi.fn(() => true),
getOnlineMemberBySocketId: vi.fn((socketId: string) => socketId === 'agent-socket'
? { userId: 'agent-1', name: '丫鬟' }
: { userId: 'human-1', name: 'Human' }),
? { userId: 'agent-1', name: '丫鬟', source: 'agent' }
: { userId: 'human-1', name: 'Human', source: 'human' }),
}],
])
server.socketUserMap = new Map([
@@ -297,9 +297,23 @@ describe('Group Chat member/agent identity sync', () => {
server.handleMessage({ id: 'human-socket' }, { roomId: 'room-1', content: '@all hi', role: 'user' }, vi.fn())
expect(server.agentClients.processMentions).toHaveBeenCalledTimes(1)
expect(server.agentClients.processMentions).toHaveBeenLastCalledWith('room-1', expect.objectContaining({
content: '@all hi',
senderId: 'human-1',
mentionDepth: 0,
}))
server.agentClients.processMentions.mockClear()
server.handleMessage({ id: 'agent-socket' }, { roomId: 'room-1', content: '@all agent says hi', role: 'assistant', mentionDepth: 1 }, vi.fn())
expect(server.agentClients.processMentions).toHaveBeenCalledTimes(1)
expect(server.agentClients.processMentions).toHaveBeenLastCalledWith('room-1', expect.objectContaining({
content: '@all agent says hi',
senderId: 'agent-1',
mentionDepth: 1,
}))
server.agentClients.processMentions.mockClear()
server.handleMessage({ id: 'agent-socket' }, { roomId: 'room-1', content: '@all too deep', role: 'assistant', mentionDepth: 4 }, vi.fn())
expect(server.agentClients.processMentions).not.toHaveBeenCalled()
})
})