fix(chat): group run output and hide empty messages
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { groupRunMessages } from '../../packages/client/src/components/hermes/chat/groupRunMessages'
|
||||
import type { Message } from '../../packages/client/src/stores/hermes/chat'
|
||||
|
||||
const message = (id: string, role: Message['role'], content = ''): Message => ({ id, role, content, timestamp: 1 })
|
||||
|
||||
describe('groupRunMessages', () => {
|
||||
it('groups text across tool calls and marks completion only when the run ends', () => {
|
||||
const input = [message('u', 'user', 'question'), message('a', 'assistant', 'first'), message('t', 'tool'), message('b', 'assistant', 'second')]
|
||||
const active = groupRunMessages(input, true)
|
||||
expect(active.map(m => m.role)).toEqual(['user', 'assistant', 'tool'])
|
||||
expect(active[1]).toMatchObject({ id: 'b', content: 'first\n\nsecond' })
|
||||
const finished = groupRunMessages(input, false)
|
||||
expect(finished.at(-1)?.systemType).toBe('run-end')
|
||||
})
|
||||
|
||||
it('keeps separate user turns and explicit run markers separate', () => {
|
||||
const input = [message('u', 'user'), { ...message('a', 'assistant', 'one'), runMarker: '1' }, { ...message('b', 'assistant', 'two'), runMarker: '2' }, message('u2', 'user'), message('c', 'assistant', 'three')]
|
||||
expect(groupRunMessages(input, false).filter(m => m.role === 'assistant').map(m => m.content)).toEqual(['one', 'two', 'three'])
|
||||
expect(groupRunMessages(input, false).filter(m => m.systemType === 'run-end')).toHaveLength(3)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user