mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-11-26 23:29:34 +00:00
fix:- Misc. bug: Settings/Tools is lying about tool picks inside a ch… (#32223)
* fix:- Misc. bug: Settings/Tools is lying about tool picks inside a chat #32214 * checks run lint error --------- Co-authored-by: Developer <dev@example.com>
This commit is contained in:
parent
7804be0634
commit
e8698ac163
2 changed files with 72 additions and 16 deletions
|
|
@ -5,7 +5,7 @@
|
|||
import * as Collapsible from '$lib/components/ui/collapsible';
|
||||
import { ICON_CLASS_DEFAULT } from '$lib/constants';
|
||||
import { ToolSource } from '$lib/enums/tools.enums';
|
||||
import { mcpStore, permissionsStore, toolsStore } from '$lib/stores';
|
||||
import { conversationsStore, mcpStore, permissionsStore, toolsStore } from '$lib/stores';
|
||||
import { getToolUi } from '$lib/utils';
|
||||
import { SvelteSet } from 'svelte/reactivity';
|
||||
|
||||
|
|
@ -26,7 +26,11 @@
|
|||
{:else}
|
||||
<div class="space-y-2">
|
||||
<p class="text-sm text-muted-foreground">
|
||||
Applies to new conversations. Tool picks inside a chat only affect that chat.
|
||||
{#if conversationsStore.activeConversation}
|
||||
Applies to this conversation.
|
||||
{:else}
|
||||
Applies to new conversations. Tool picks inside a chat only affect that chat.
|
||||
{/if}
|
||||
</p>
|
||||
|
||||
{#each groups as group (group.key)}
|
||||
|
|
@ -41,19 +45,9 @@
|
|||
<ChevronRight class="h-3.5 w-3.5 shrink-0" />
|
||||
{/if}
|
||||
|
||||
{@const groupToggleKey =
|
||||
group.source === ToolSource.MCP && group.serverId
|
||||
? toolsStore.getMcpServerToolsKey(group.serverId)
|
||||
: null}
|
||||
|
||||
<Checkbox
|
||||
checked={groupToggleKey
|
||||
? toolsStore.isToolEnabled(groupToggleKey)
|
||||
: toolsStore.isCategoryEnabled(group.source)}
|
||||
onCheckedChange={() =>
|
||||
groupToggleKey
|
||||
? toolsStore.toggleTool(groupToggleKey)
|
||||
: toolsStore.toggleCategory(group.source)}
|
||||
checked={conversationsStore.preferences.isGroupChecked(group)}
|
||||
onCheckedChange={() => void conversationsStore.preferences.toggleGroup(group)}
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
/>
|
||||
|
||||
|
|
@ -97,7 +91,7 @@
|
|||
: null}
|
||||
{@const displayLabel = toolUi?.label ?? toolName}
|
||||
{@const IconComponent = toolUi?.icon ?? null}
|
||||
{@const isEnabled = toolsStore.isToolEnabled(entry.key)}
|
||||
{@const isEnabled = conversationsStore.preferences.isToolEnabled(entry.key)}
|
||||
{@const permissionKey = entry.key}
|
||||
{@const isAlwaysAllowed = permissionsStore.hasTool(permissionKey)}
|
||||
|
||||
|
|
@ -114,7 +108,8 @@
|
|||
<Checkbox
|
||||
checked={isEnabled}
|
||||
class={ICON_CLASS_DEFAULT}
|
||||
onCheckedChange={() => toolsStore.toggleTool(entry.key)}
|
||||
onCheckedChange={() =>
|
||||
void conversationsStore.preferences.toggleTool(entry.key)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
61
tools/ui/tests/client/settings-tools-policy.svelte.test.ts
Normal file
61
tools/ui/tests/client/settings-tools-policy.svelte.test.ts
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
// Settings > Tools must edit the active conversation policy, not the defaults for future chats.
|
||||
|
||||
import SettingsChatToolsTab from '$lib/components/app/settings/SettingsChat/SettingsChatToolsTab.svelte';
|
||||
import { DatabaseService } from '$lib/services/database.service';
|
||||
import { conversationsStore } from '$lib/stores/conversations/index.svelte';
|
||||
import { toolsStore } from '$lib/stores/tools.svelte';
|
||||
import type { DatabaseConversation, OpenAIToolDefinition } from '$lib/types';
|
||||
import { tick } from 'svelte';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { render } from 'vitest-browser-svelte';
|
||||
|
||||
const TOOL_KEY = 'server:test_tool';
|
||||
const TOOL: OpenAIToolDefinition = {
|
||||
function: { description: '', name: 'test_tool', parameters: {} },
|
||||
type: 'function'
|
||||
};
|
||||
|
||||
function setServerTools(definitions: OpenAIToolDefinition[]) {
|
||||
(toolsStore as unknown as { _serverTools: OpenAIToolDefinition[] })._serverTools = definitions;
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
conversationsStore.clearActiveConversation();
|
||||
conversationsStore.conversations = [];
|
||||
setServerTools([]);
|
||||
toolsStore.setToolEnabled(TOOL_KEY, true);
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('SettingsChatToolsTab', () => {
|
||||
it('keeps a tool change in the active conversation', async () => {
|
||||
vi.spyOn(DatabaseService, 'updateConversation').mockResolvedValue(undefined);
|
||||
const conversation: DatabaseConversation = {
|
||||
currNode: null,
|
||||
id: 'conversation-1',
|
||||
lastModified: 0,
|
||||
name: 'Conversation'
|
||||
};
|
||||
|
||||
conversationsStore.activeConversation = conversation;
|
||||
conversationsStore.conversations = [conversation];
|
||||
setServerTools([TOOL]);
|
||||
const screen = render(SettingsChatToolsTab);
|
||||
const trigger = screen.container.querySelector<HTMLElement>(
|
||||
'[data-slot="collapsible-trigger"]'
|
||||
);
|
||||
|
||||
if (!trigger) throw new Error('tool group trigger not found');
|
||||
|
||||
await trigger.click();
|
||||
await tick();
|
||||
|
||||
const checkboxes = screen.container.querySelectorAll<HTMLElement>('[role="checkbox"]');
|
||||
|
||||
await checkboxes[1].click();
|
||||
await tick();
|
||||
|
||||
expect(conversationsStore.activeConversation?.disabledTools).toEqual([TOOL_KEY]);
|
||||
expect(toolsStore.isToolEnabled(TOOL_KEY)).toBe(true);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue