Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | 'use client'; import { zodResolver } from '@hookform/resolvers/zod'; import type { AgentCreateParams } from '@shared/types/data'; import { sanitizeUserInput } from '@shared/utils/security'; import { Button } from '@web/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from '@web/components/ui/card'; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from '@web/components/ui/form'; import { Input } from '@web/components/ui/input'; import { PageHeader } from '@web/components/ui/page-header'; import { Textarea } from '@web/components/ui/textarea'; import { usePermissiveNavigate } from '@web/hooks/use-permissive-navigate'; import { useAgents } from '@web/providers/agents'; import { Bot, Sparkles } from 'lucide-react'; import type * as React from 'react'; import { useForm } from 'react-hook-form'; import { z } from 'zod'; const CreateAgentFormSchema = z .object({ name: z .string() .min(3, 'Agent name must be at least 3 characters') .max(100, 'Agent name must be less than 100 characters') .regex(/^[a-z0-9_-]+$/, { message: 'Agent name must only contain lowercase letters, numbers, underscores, and hyphens', }) .refine((name) => name !== 'super-agents', { message: 'The name "super-agents" is reserved for internal system use. Please choose a different name.', }), description: z .string() .min(25, 'Description must be at least 25 characters') .max(10000, 'Description must be less than 10000 characters'), }) .strict(); type CreateAgentFormData = z.infer<typeof CreateAgentFormSchema>; export function CreateAgentView(): React.ReactElement { const { createAgent, isCreating } = useAgents(); const navigate = usePermissiveNavigate(); const form = useForm<CreateAgentFormData>({ resolver: zodResolver(CreateAgentFormSchema), defaultValues: { name: '', description: '', }, }); const onSubmit = async (data: CreateAgentFormData) => { try { const agentParams: AgentCreateParams = { name: data.name, description: sanitizeUserInput(data.description), metadata: {}, }; const newAgent = await createAgent(agentParams); // Reset form after successful creation form.reset(); // Navigate to the agent's skills page, replacing history to prevent back button going to create page navigate({ to: '/agents/$agentName', params: { agentName: newAgent.name }, replace: true, }); } catch (error) { console.error('Error creating agent:', error); // Error is already handled by the agents provider } }; const handleBack = () => { navigate({ to: '/agents' }); }; return ( <> <PageHeader title="Create New Agent" description="Build a new AI agent to help with your tasks" onBack={handleBack} /> <div className="container mx-auto px-2 pt-6 pb-6 max-w-2xl"> {/* Main Form Card */} <Card className="shadow-lg"> <CardHeader className="pb-6"> <div className="flex items-center gap-3"> <Bot className="h-5 w-5 text-primary" /> <div> <CardTitle>Agent Configuration</CardTitle> <CardDescription> Define your agent's basic information and purpose </CardDescription> </div> </div> </CardHeader> <CardContent> <Form {...form}> <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6" > <FormField control={form.control} name="name" render={({ field }) => ( <FormItem> <FormLabel className="text-base font-medium"> Agent Name </FormLabel> <FormDescription> Choose a descriptive name using only lowercase letters, numbers, underscores, and hyphens. </FormDescription> <FormControl> <Input placeholder="e.g., customer-support-bot, content_writer, data-analyst" className="h-11" pattern="[a-z0-9_-]+" title="Only lowercase letters, numbers, underscores, and hyphens are allowed" {...field} onChange={(e) => { field.onChange(e); // Trigger validation on every change form.trigger('name'); }} disabled={isCreating} /> </FormControl> <FormMessage /> </FormItem> )} /> <FormField control={form.control} name="description" render={({ field }) => ( <FormItem> <FormLabel className="text-base font-medium"> Description (required) </FormLabel> <FormDescription> Provide additional context about the agent's purpose, capabilities, and expected behavior (minimum 25 characters). This description is{' '} <span className="font-bold">crucial</span> for generating accurate system prompts and evaluations for each of the agent's skills. </FormDescription> <FormControl> <Textarea placeholder="Describe what this agent will do, its capabilities, and how it should behave. For example: 'A helpful customer support agent that can answer questions about our products, handle basic troubleshooting, and escalate complex issues to human agents.'" className="resize-none min-h-[120px]" {...field} disabled={isCreating} /> </FormControl> <FormMessage /> </FormItem> )} /> {/* Action Buttons */} <div className="flex gap-3 pt-4"> <Button type="button" variant="outline" size="lg" onClick={handleBack} disabled={isCreating} className="flex-1" > Cancel </Button> <Button type="submit" size="lg" disabled={isCreating} className="flex-1" > {isCreating ? ( <> <Bot className="mr-2 h-4 w-4 animate-pulse" /> Creating Agent... </> ) : ( <> <Sparkles className="mr-2 h-4 w-4" /> Create Agent </> )} </Button> </div> </form> </Form> </CardContent> </Card> {/* Tips Card */} <Card className="mt-6 border-primary/20 bg-primary/5"> <CardHeader className="pb-4"> <CardTitle className="text-lg flex items-center gap-2"> <Bot className="h-5 w-5 text-primary" /> Tips for Creating Effective Agents </CardTitle> </CardHeader> <CardContent className="space-y-3"> <div className="text-sm space-y-2"> <p className="flex items-start gap-2"> <span className="text-primary font-medium">•</span> <span> Use clear, specific names that describe the agent's primary function </span> </p> <p className="flex items-start gap-2"> <span className="text-primary font-medium">•</span> <span> Include context about the agent's role, expertise, and communication style in the description </span> </p> <p className="flex items-start gap-2"> <span className="text-primary font-medium">•</span> <span> You can always edit these details later from the agents management page </span> </p> </div> </CardContent> </Card> </div> </> ); } |