char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierrefactor: Clean up UI types (#26909)a6040c925

char/aliceai-t5-moe
2.3 KiB83 linesraw
1import { REASONING_TAGS } from '$lib/constants';
2import { AgenticSectionType } from '$lib/enums';
3import type { AgenticSection } from '$lib/types/agentic';
4import { buildAssistantRawOutput } from '$lib/utils/agentic';
5import { describe, expect, it } from 'vitest';
6
7function makeSection(
8	overrides: Partial<AgenticSection> & { type: AgenticSectionType }
9): AgenticSection {
10	return {
11		content: '',
12		...overrides
13	};
14}
15
16describe('buildAssistantRawOutput', () => {
17	it('returns empty string for empty sections', () => {
18		expect(buildAssistantRawOutput([])).toBe('');
19	});
20
21	it('formats a reasoning section with a single newline between tags and content', () => {
22		const sections = [makeSection({ content: 'thinking...', type: AgenticSectionType.REASONING })];
23
24		expect(buildAssistantRawOutput(sections)).toBe(
25			`${REASONING_TAGS.START}\nthinking...${REASONING_TAGS.END}`
26		);
27	});
28
29	it('formats a text section as-is', () => {
30		const sections = [makeSection({ content: 'Hello', type: AgenticSectionType.TEXT })];
31
32		expect(buildAssistantRawOutput(sections)).toBe('Hello');
33	});
34
35	it('formats a tool call with JSON args and no result label', () => {
36		const sections = [
37			makeSection({
38				toolArgs: JSON.stringify({ path: '/tmp/file.txt' }),
39				toolName: 'read_file',
40				toolResult: 'file contents',
41				type: AgenticSectionType.TOOL_CALL
42			})
43		];
44
45		expect(buildAssistantRawOutput(sections)).toBe(
46			[
47				'{',
48				'  "name": "read_file",',
49				'  "arguments": {',
50				'    "path": "/tmp/file.txt"',
51				'  }',
52				'}',
53				'',
54				'',
55				'file contents'
56			].join('\n')
57		);
58	});
59
60	it('joins multiple sections with double newlines', () => {
61		const sections = [
62			makeSection({ content: 'Hello', type: AgenticSectionType.TEXT }),
63			makeSection({ toolName: 'noop', type: AgenticSectionType.TOOL_CALL })
64		];
65
66		expect(buildAssistantRawOutput(sections)).toBe('Hello\n\n{\n  "name": "noop"\n}');
67	});
68
69	it('falls back to raw string args when JSON parsing fails', () => {
70		const sections = [
71			makeSection({
72				toolArgs: '{not json',
73				toolName: 'broken',
74				toolResult: 'result',
75				type: AgenticSectionType.TOOL_CALL
76			})
77		];
78
79		expect(buildAssistantRawOutput(sections)).toBe(
80			['{', '  "name": "broken",', '  "arguments": "{not json"', '}', '', '', 'result'].join('\n')
81		);
82	});
83});