char-fork/llama.cpp

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

nachobhui : fix MCP image attachments not displayed in tool block (#25789) (#28089)85d5703a3

char/aliceai-t5-moe
4.3 KiB140 linesraw
1import { classifyToolResult } from '$lib/utils/agentic';
2import { describe, expect, it } from 'vitest';
3
4describe('classifyToolResult', () => {
5	describe('text', () => {
6		it('returns text for undefined input', () => {
7			expect(classifyToolResult(undefined)).toBe('text');
8		});
9
10		it('returns text for empty string', () => {
11			expect(classifyToolResult('')).toBe('text');
12		});
13
14		it('returns text for whitespace-only input', () => {
15			expect(classifyToolResult('   \n  ')).toBe('text');
16		});
17
18		it('returns text for plain prose', () => {
19			expect(classifyToolResult('Hello, this is just some text.')).toBe('text');
20		});
21
22		it('returns text for shell-style line listings', () => {
23			expect(classifyToolResult('file1.java\nfile2.java\nfile3.java\n')).toBe('text');
24		});
25
26		it('returns text when a brace-like string is not valid JSON', () => {
27			expect(classifyToolResult('{key: value}')).toBe('text');
28		});
29	});
30
31	describe('json', () => {
32		it('classifies a flat JSON object', () => {
33			expect(classifyToolResult('{"key": "value", "n": 42}')).toBe('json');
34		});
35
36		it('classifies a JSON array', () => {
37			expect(classifyToolResult('["a", "b", "c"]')).toBe('json');
38		});
39
40		it('classifies a nested JSON array', () => {
41			expect(classifyToolResult('[[1, 2], [3, 4]]')).toBe('json');
42		});
43
44		it('classifies a pretty-printed JSON object', () => {
45			expect(classifyToolResult('{\n  "key": "value"\n}')).toBe('json');
46		});
47
48		it('classifies a deeply nested JSON payload', () => {
49			const nested = JSON.stringify({ items: [{ id: 1, tags: ['a', 'b'] }] }, null, 2);
50
51			expect(classifyToolResult(nested)).toBe('json');
52		});
53
54		it('prefers JSON over inner markdown markers when the content starts with a brace', () => {
55			// A JSON object whose inner strings contain link syntax still
56			// reads as JSON because the leading `{` parses cleanly -
57			// `classifyToolResult` only inspects the top-level shape, not
58			// every nested line marker.
59			const jsonWithLink = '{"docs": "see [docs](https://example.com) for more"}';
60
61			expect(classifyToolResult(jsonWithLink)).toBe('json');
62		});
63	});
64
65	describe('markdown', () => {
66		it('classifies an ATX header line', () => {
67			expect(classifyToolResult('# Title\n\nSome text below.')).toBe('markdown');
68		});
69
70		it('classifies a fenced code block', () => {
71			expect(classifyToolResult('```json\n{"key": "v"}\n```')).toBe('markdown');
72		});
73
74		it('classifies a tilde-fenced code block', () => {
75			expect(classifyToolResult('~~~bash\nls -la\n~~~')).toBe('markdown');
76		});
77
78		it('classifies a markdown link', () => {
79			expect(classifyToolResult('See [docs](https://example.com) for more.')).toBe('markdown');
80		});
81
82		it('classifies bold text', () => {
83			expect(classifyToolResult('This is **very important**.')).toBe('markdown');
84		});
85
86		it('classifies a bulleted list', () => {
87			expect(classifyToolResult('- item one\n- item two\n- item three')).toBe('markdown');
88		});
89
90		it('classifies an ordered list', () => {
91			expect(classifyToolResult('1. first step\n2. second step\n3. third step')).toBe('markdown');
92		});
93
94		it('classifies a blockquote', () => {
95			expect(classifyToolResult('> quoted text\n> second line')).toBe('markdown');
96		});
97
98		it('classifies a markdown table', () => {
99			const table = '| a | b |\n| - | - |\n| 1 | 2 |';
100
101			expect(classifyToolResult(table)).toBe('markdown');
102		});
103
104		it('classifies a markdown table with alignment markers', () => {
105			const table = '| left | center | right |\n| :--- | :---: | ---: |\n| a | b | c |';
106
107			expect(classifyToolResult(table)).toBe('markdown');
108		});
109
110		it('classifies nested markdown headings', () => {
111			expect(classifyToolResult('## Section\n\n### Subsection\n')).toBe('markdown');
112		});
113
114		it('classifies combined markdown markers in one document', () => {
115			const md = [
116				'# Heading',
117				'',
118				'A paragraph with a [link](https://example.com) and **bold text**.',
119				'',
120				'- bullet item',
121				'- another bullet',
122				'',
123				'| col1 | col2 |',
124				'| ----- | ----- |',
125				'| a     | b     |'
126			].join('\n');
127
128			expect(classifyToolResult(md)).toBe('markdown');
129		});
130	});
131
132	describe('precedence', () => {
133		it('prefers JSON over markdown when both signals are present', () => {
134			// Starts with `[`, parses as JSON - markdown check is skipped.
135			const arr = '[1, 2, "# not-a-heading", "**not-bold**"]';
136
137			expect(classifyToolResult(arr)).toBe('json');
138		});
139	});
140});