2 import { ChevronDown, ShieldQuestion } from '@lucide/svelte';
3 import { ChatMessageActionCard } from '$lib/components/app';
4 import { Button } from '$lib/components/ui/button';
5 import * as ButtonGroup from '$lib/components/ui/button-group';
6 import * as DropdownMenu from '$lib/components/ui/dropdown-menu';
7 import { ToolSource, ToolPermissionDecision } from '$lib/enums';
8 import { TOOL_SERVER_LABELS } from '$lib/constants';
9 import { toolsStore } from '$lib/stores/tools.svelte';
14 onDecision: (decision: ToolPermissionDecision) => void;
17 let { toolName, serverLabel, onDecision }: Props = $props();
20 <ChatMessageActionCard icon={ShieldQuestion}>
24 <span class="font-semibold">{toolName}</span>
27 from <span class="font-semibold">{serverLabel}</span>
36 class="overflow-hidden rounded-md bg-foreground text-white shadow-sm dark:bg-secondary dark:text-foreground"
39 class="rounded-none! shadow-none!"
41 onclick={() => onDecision(ToolPermissionDecision.ONCE)}
46 <ButtonGroup.Separator />
48 <DropdownMenu.Trigger>
49 <Button size="sm" class="rounded-none! !ps-2 shadow-none!">
50 <ChevronDown class="h-3.5 w-3.5" />
52 </DropdownMenu.Trigger>
55 <DropdownMenu.Content align="start" class="min-w-[8rem]">
56 <DropdownMenu.Item onclick={() => onDecision(ToolPermissionDecision.ALWAYS)}>
57 Always allow <pre>{toolName}</pre>
61 <DropdownMenu.Item onclick={() => onDecision(ToolPermissionDecision.ALWAYS_SERVER)}>
62 Always allow all tools from {serverLabel}
65 {@const source = toolsStore.getToolSource(toolName)}
66 {@const providerName =
67 source === ToolSource.BUILTIN
68 ? TOOL_SERVER_LABELS[ToolSource.BUILTIN]
69 : source === ToolSource.CUSTOM
70 ? TOOL_SERVER_LABELS[ToolSource.CUSTOM]
72 <DropdownMenu.Item onclick={() => onDecision(ToolPermissionDecision.ALWAYS_SERVER)}>
73 Approve all tools from {providerName}
76 </DropdownMenu.Content>
82 class="text-destructive hover:text-destructive"
83 onclick={() => onDecision(ToolPermissionDecision.DENY)}
88 </ChatMessageActionCard>