feat(chat): collapse tool calls by run
This commit is contained in:
@@ -8,7 +8,8 @@ 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.map(m => m.role)).toEqual(['user', 'assistant', 'system'])
|
||||
expect(active[2]).toMatchObject({ systemType: 'tool-group', toolMessages: [input[2]] })
|
||||
expect(active[1]).toMatchObject({ id: 'b', content: 'first\n\nsecond' })
|
||||
const finished = groupRunMessages(input, false)
|
||||
expect(finished.at(-1)?.systemType).toBe('run-end')
|
||||
@@ -19,4 +20,10 @@ describe('groupRunMessages', () => {
|
||||
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)
|
||||
})
|
||||
|
||||
it('keeps tool calls grouped within their own turn', () => {
|
||||
const input = [message('u', 'user'), message('a', 'tool'), message('b', 'tool'), message('u2', 'user'), message('c', 'tool')]
|
||||
const groups = groupRunMessages(input, false).filter(m => m.systemType === 'tool-group')
|
||||
expect(groups.map(group => group.toolMessages?.map(tool => tool.id))).toEqual([['a', 'b'], ['c']])
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user