diff --git a/frontend/src/components/settings/AddMcpServerDialog.tsx b/frontend/src/components/settings/AddMcpServerDialog.tsx index 213806a7..d052c442 100644 --- a/frontend/src/components/settings/AddMcpServerDialog.tsx +++ b/frontend/src/components/settings/AddMcpServerDialog.tsx @@ -5,6 +5,7 @@ import { Label } from '@/components/ui/label' import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { Loader2 } from 'lucide-react' +import { Switch } from '@/components/ui/switch' import { settingsApi } from '@/api/settings' import { useMutation, useQueryClient } from '@tanstack/react-query' @@ -126,7 +127,7 @@ onSuccess: async () => { return ( - + Add MCP Server @@ -134,8 +135,8 @@ onSuccess: async () => { -
-
+
+
{

-
+
{

) : ( -
+
{ )} {serverType === 'local' && ( -
+
{environment.map((env, index) => ( @@ -237,7 +239,7 @@ onSuccess: async () => {
)} -
+
{
- setEnabled(e.target.checked)} - className="rounded" + onCheckedChange={setEnabled} />
diff --git a/frontend/src/components/settings/AgentDialog.tsx b/frontend/src/components/settings/AgentDialog.tsx new file mode 100644 index 00000000..62033824 --- /dev/null +++ b/frontend/src/components/settings/AgentDialog.tsx @@ -0,0 +1,480 @@ +import { useForm } from 'react-hook-form' +import { zodResolver } from '@hookform/resolvers/zod' +import { z } from 'zod' +import { Button } from '@/components/ui/button' +import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog' +import { Input } from '@/components/ui/input' +import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form' +import { Textarea } from '@/components/ui/textarea' +import { Switch } from '@/components/ui/switch' +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' + +const agentFormSchema = z.object({ + name: z.string().min(1, 'Agent name is required').regex(/^[a-z0-9-]+$/, 'Must be lowercase letters, numbers, and hyphens only'), + description: z.string().optional(), + prompt: z.string().min(1, 'Prompt is required'), + mode: z.enum(['subagent', 'primary', 'all']), + temperature: z.number().min(0).max(2), + topP: z.number().min(0).max(1), + modelId: z.string().optional(), + providerId: z.string().optional(), + write: z.boolean(), + edit: z.boolean(), + bash: z.boolean(), + webfetch: z.boolean(), + editPermission: z.enum(['ask', 'allow', 'deny']), + bashPermission: z.enum(['ask', 'allow', 'deny']), + webfetchPermission: z.enum(['ask', 'allow', 'deny']), + disable: z.boolean() +}) + +type AgentFormValues = z.infer + +interface Agent { + prompt?: string + description?: string + mode?: 'subagent' | 'primary' | 'all' + temperature?: number + topP?: number + model?: { + modelID: string + providerID: string + } + tools?: Record + permission?: { + edit?: 'ask' | 'allow' | 'deny' + bash?: 'ask' | 'allow' | 'deny' | Record + webfetch?: 'ask' | 'allow' | 'deny' + } + disable?: boolean + [key: string]: unknown +} + +interface AgentDialogProps { + open: boolean + onOpenChange: (open: boolean) => void + onSubmit: (name: string, agent: Agent) => void + editingAgent?: { name: string; agent: Agent } | null +} + +export function AgentDialog({ open, onOpenChange, onSubmit, editingAgent }: AgentDialogProps) { + const form = useForm({ + resolver: zodResolver(agentFormSchema), + defaultValues: { + name: editingAgent?.name || '', + description: editingAgent?.agent.description || '', + prompt: editingAgent?.agent.prompt || '', + mode: editingAgent?.agent.mode || 'subagent', + temperature: editingAgent?.agent.temperature ?? 0.7, + topP: editingAgent?.agent.topP ?? 1, + modelId: editingAgent?.agent.model?.modelID || '', + providerId: editingAgent?.agent.model?.providerID || '', + write: editingAgent?.agent.tools?.write ?? true, + edit: editingAgent?.agent.tools?.edit ?? true, + bash: editingAgent?.agent.tools?.bash ?? true, + webfetch: editingAgent?.agent.tools?.webfetch ?? true, + editPermission: editingAgent?.agent.permission?.edit ?? 'allow', + bashPermission: typeof editingAgent?.agent.permission?.bash === 'string' ? editingAgent.agent.permission.bash : 'allow', + webfetchPermission: editingAgent?.agent.permission?.webfetch ?? 'allow', + disable: editingAgent?.agent.disable ?? false + } + }) + + const handleSubmit = (values: AgentFormValues) => { + const agent: Agent = { + prompt: values.prompt, + description: values.description || undefined, + mode: values.mode, + temperature: values.temperature, + topP: values.topP, + disable: values.disable, + tools: { + write: values.write, + edit: values.edit, + bash: values.bash, + webfetch: values.webfetch + }, + permission: { + edit: values.editPermission, + bash: values.bashPermission, + webfetch: values.webfetchPermission + } + } + + if (values.modelId || values.providerId) { + agent.model = { + modelID: values.modelId || '', + providerID: values.providerId || '' + } + } + + onSubmit(values.name, agent) + form.reset() + onOpenChange(false) + } + + const handleOpenChange = (isOpen: boolean) => { + if (!isOpen) { + form.reset() + } + onOpenChange(isOpen) + } + + return ( + + + + {editingAgent ? 'Edit Agent' : 'Create Agent'} + + +
+ + ( + + Agent Name + + + + + Use lowercase letters, numbers, and hyphens only + + + + )} + /> + + ( + + Description + +