char-fork/llama.cpp

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

Aleksander Grygierui: Refactor Built-In Tools naming (Server/Browser) (#27271)0021a77de

char/aliceai-t5-moe
2.2 KiB63 linesraw
1// Guards the @-mention picker's file_glob_search gate: when the server
2// does not expose the tool (started without --tools) or the user disabled
3// it, the picker still opens but explains why instead of firing searches
4// that would only fail with "Search failed".
5
6import ChatFormPickerMention from '$lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerMention.svelte';
7import { DISABLED_TOOL_KEYS_LOCALSTORAGE_KEY } from '$lib/constants';
8import { BuiltInTool } from '$lib/enums';
9import { toolsStore } from '$lib/stores/tools.svelte';
10import type { OpenAIToolDefinition } from '$lib/types';
11import { tick } from 'svelte';
12import { afterEach, describe, expect, it } from 'vitest';
13import { render } from 'vitest-browser-svelte';
14
15const FILE_SEARCH_DEF: OpenAIToolDefinition = {
16	function: { description: '', name: BuiltInTool.SERVER_FILE_GLOB_SEARCH, parameters: {} },
17	type: 'function'
18};
19const FILE_SEARCH_KEY = `server:${BuiltInTool.SERVER_FILE_GLOB_SEARCH}`;
20
21// The store keeps its server tool list private; tests inject it through
22// the reactive field so the derived gates recompute.
23function setServerTools(defs: OpenAIToolDefinition[]) {
24	(toolsStore as unknown as { _serverTools: OpenAIToolDefinition[] })._serverTools = defs;
25}
26
27function renderPicker() {
28	return render(ChatFormPickerMention, {
29		isOpen: true,
30		onClose: () => {},
31		onSelect: () => {},
32		query: 'main'
33	});
34}
35
36afterEach(() => {
37	setServerTools([]);
38	toolsStore.setToolEnabled(FILE_SEARCH_KEY, true);
39	localStorage.removeItem(DISABLED_TOOL_KEYS_LOCALSTORAGE_KEY);
40});
41
42describe('ChatFormPickerMention file_glob_search gate', () => {
43	it('explains that file search is unavailable when the server has no tools', async () => {
44		setServerTools([]);
45		renderPicker();
46		await tick();
47
48		expect(document.body.textContent).toContain(
49			'File search is unavailable on this server (started without --tools)'
50		);
51	});
52
53	it('explains that file search must be enabled when the user disabled it', async () => {
54		setServerTools([FILE_SEARCH_DEF]);
55		toolsStore.setToolEnabled(FILE_SEARCH_KEY, false);
56		renderPicker();
57		await tick();
58
59		expect(document.body.textContent).toContain(
60			'File search is disabled - enable "Search files" in Settings > Tools to use @-mentions'
61		);
62	});
63});