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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 17x 16x 16x 16x 16x 36x 36x 36x 2x 2x 2x 2x 36x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x | 'use client';
import { zodResolver } from '@hookform/resolvers/zod';
import type { AgentUpdateParams } from '@shared/types/data';
import { sanitizeUserInput } from '@shared/utils/security';
import { useParams } from '@tanstack/react-router';
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, Settings } from 'lucide-react';
import * as React from 'react';
import { useForm } from 'react-hook-form';
import { z } from 'zod';
const EditAgentFormSchema = z
.object({
description: z
.string()
.min(25, 'Description must be at least 25 characters')
.max(10000, 'Description must be less than 10000 characters'),
})
.strict();
type EditAgentFormData = z.infer<typeof EditAgentFormSchema>;
export function EditAgentView(): React.ReactElement {
const { selectedAgent, updateAgent, isUpdating } = useAgents();
const navigate = usePermissiveNavigate();
const { agentName } = useParams({ strict: false }) as { agentName?: string };
const agentNameInputId = React.useId();
const form = useForm<EditAgentFormData>({
resolver: zodResolver(EditAgentFormSchema),
defaultValues: {
description: '',
},
});
// Update form defaults when agent data is available
React.useEffect(() => {
if (selectedAgent) {
form.reset({
description: selectedAgent.description || '',
});
}
}, [selectedAgent, form]);
const onSubmit = async (data: EditAgentFormData) => {
if (!selectedAgent) {
console.error('No agent selected');
return;
}
try {
const updateParams: AgentUpdateParams = {
description: sanitizeUserInput(data.description),
};
await updateAgent(selectedAgent.id, updateParams);
// Navigate back to agent skills list
if (agentName) {
navigate({ to: '/agents/$agentName', params: { agentName } });
} else {
navigate({ to: '/agents' });
}
} catch (error) {
console.error('Error updating agent:', error);
// Error is already handled by the agents provider
}
};
const handleBack = () => {
if (agentName) {
navigate({ to: '/agents/$agentName', params: { agentName } });
} else {
navigate({ to: '/agents' });
}
};
if (!selectedAgent) {
return (
<>
<PageHeader title="Edit Agent" description="Agent not found" />
<div className="container mx-auto py-6 max-w-2xl">
<Card className="border-yellow-200 bg-yellow-50 dark:border-yellow-800 dark:bg-yellow-900/20">
<CardContent className="p-4">
<div className="flex items-center gap-2">
<Settings className="h-5 w-5 text-yellow-600 dark:text-yellow-400" />
<div>
<h4 className="text-sm font-medium text-yellow-800 dark:text-yellow-200">
Agent not found
</h4>
<p className="text-sm text-yellow-700 dark:text-yellow-300 mt-1">
Unable to find the specified agent. Please ensure the agent
exists and try again.
</p>
</div>
</div>
</CardContent>
</Card>
</div>
</>
);
}
return (
<>
<PageHeader
title="Edit Agent"
description={`Update ${selectedAgent.name} configuration`}
onBack={handleBack}
/>
<div className="container mx-auto py-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>
Update your agent's information
</CardDescription>
</div>
</div>
</CardHeader>
<CardContent>
<Form {...form}>
<form
onSubmit={form.handleSubmit(onSubmit)}
className="space-y-6"
>
{/* Agent Name (read-only) */}
<div className="space-y-2">
<label
htmlFor={agentNameInputId}
className="text-sm font-medium text-foreground"
>
Agent Name
</label>
<Input
id={agentNameInputId}
value={selectedAgent.name}
disabled
className="h-11 bg-muted"
/>
<p className="text-xs text-muted-foreground">
Agent name cannot be changed after creation
</p>
</div>
{/* Description Field */}
<FormField
control={form.control}
name="description"
render={({ field }) => (
<FormItem>
<FormLabel className="text-base font-medium">
Description (required)
</FormLabel>
<FormDescription>
Provide a detailed description of what this agent does
and when to use it.
</FormDescription>
<FormControl>
<Textarea
placeholder="This agent helps with..."
className="min-h-[120px] resize-y"
{...field}
disabled={isUpdating}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
{/* Form Actions */}
<div className="flex items-center gap-3 pt-4 border-t">
<Button
type="submit"
disabled={isUpdating || !form.formState.isDirty}
className="w-full sm:w-auto"
>
{isUpdating ? 'Saving...' : 'Save Changes'}
</Button>
<Button
type="button"
variant="outline"
onClick={handleBack}
disabled={isUpdating}
className="w-full sm:w-auto"
>
Cancel
</Button>
</div>
</form>
</Form>
</CardContent>
</Card>
</div>
</>
);
}
|