2 import { ChevronDown, ShieldQuestion } from '@lucide/svelte';
3 import { ChatMessageActionCard } from '$lib/components/app';
4 import { Button, buttonVariants } from '$lib/components/ui/button';
5 import * as ButtonGroup from '$lib/components/ui/button-group';
6 import { cn } from '$lib/components/ui/utils';
7 import * as DropdownMenu from '$lib/components/ui/dropdown-menu';
8 import { ToolSource, ToolPermissionDecision } from '$lib/enums';
9 import { TOOL_SERVER_LABELS } from '$lib/constants';
10 import { toolsStore } from '$lib/stores/tools.svelte';
15 onDecision: (decision: ToolPermissionDecision) => void;
18 let { toolName, serverLabel, onDecision }: Props = $props();
21 <ChatMessageActionCard icon={ShieldQuestion}>
23 Allow use of <span class="font-semibold">{toolName}</span>{#if serverLabel}
24 from <span class="font-semibold">{serverLabel}</span>{/if}?
29 <ButtonGroup.Root class="overflow-hidden rounded-md shadow-sm">
33 class="!rounded-r-none !shadow-none"
34 onclick={() => onDecision(ToolPermissionDecision.ONCE)}
39 <ButtonGroup.Separator />
43 buttonVariants({ variant: 'secondary', size: 'sm' }),
44 'inline-flex cursor-pointer items-center !rounded-l-none !shadow-none !px-2'
46 aria-label="More allow options"
48 <ChevronDown class="h-3.5 w-3.5" />
49 </DropdownMenu.Trigger>
52 <DropdownMenu.Content align="start" class="min-w-[8rem]">
53 <DropdownMenu.Item onclick={() => onDecision(ToolPermissionDecision.ALWAYS)}>
54 Always allow <pre>{toolName}</pre>
58 <DropdownMenu.Item onclick={() => onDecision(ToolPermissionDecision.ALWAYS_SERVER)}>
59 Always allow all tools from {serverLabel}
62 {@const source = toolsStore.getToolSource(toolName)}
63 {@const providerName =
64 source === ToolSource.BUILTIN
65 ? TOOL_SERVER_LABELS[ToolSource.BUILTIN]
66 : source === ToolSource.CUSTOM
67 ? TOOL_SERVER_LABELS[ToolSource.CUSTOM]
69 <DropdownMenu.Item onclick={() => onDecision(ToolPermissionDecision.ALWAYS_SERVER)}>
70 Approve all tools from {providerName}
73 </DropdownMenu.Content>
76 <Button variant="destructive" size="sm" onclick={() => onDecision(ToolPermissionDecision.DENY)}>
80 </ChatMessageActionCard>