true message

This commit is contained in:
Manus
2026-03-20 16:39:29 -04:00
parent b18e6e244f
commit 159a89a156
17 changed files with 3054 additions and 191 deletions

View File

@@ -0,0 +1,257 @@
import { useState } from "react";
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { trpc } from "@/lib/trpc";
import { toast } from "sonner";
import { Loader2, Plus } from "lucide-react";
interface AgentCreateModalProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onSuccess?: () => void;
}
const AGENT_ROLES = [
{ value: "developer", label: "Developer - Code generation & testing" },
{ value: "researcher", label: "Researcher - Data analysis & research" },
{ value: "executor", label: "Executor - Task automation" },
{ value: "monitor", label: "Monitor - System monitoring" },
];
const PROVIDERS = [
{ value: "Ollama", label: "Ollama (Local/Cloud)" },
{ value: "OpenAI", label: "OpenAI (GPT)" },
{ value: "Anthropic", label: "Anthropic (Claude)" },
];
export function AgentCreateModal({ open, onOpenChange, onSuccess }: AgentCreateModalProps) {
const [formData, setFormData] = useState({
name: "",
description: "",
role: "developer",
provider: "Ollama",
model: "deepseek-v3.2",
temperature: 0.7,
maxTokens: 2048,
systemPrompt: "",
});
const [isLoading, setIsLoading] = useState(false);
const { data: models } = trpc.ollama.models.useQuery();
const createMutation = trpc.agents.create.useMutation({
onSuccess: () => {
toast.success("Agent created successfully");
setFormData({
name: "",
description: "",
role: "developer",
provider: "Ollama",
model: "deepseek-v3.2",
temperature: 0.7,
maxTokens: 2048,
systemPrompt: "",
});
onOpenChange(false);
onSuccess?.();
},
onError: (error) => {
toast.error(`Failed to create agent: ${error.message}`);
},
});
const handleCreate = async () => {
if (!formData.name.trim()) {
toast.error("Agent name is required");
return;
}
setIsLoading(true);
try {
await createMutation.mutateAsync({
name: formData.name,
description: formData.description,
role: formData.role,
provider: formData.provider,
model: formData.model,
temperature: formData.temperature,
maxTokens: formData.maxTokens,
systemPrompt: formData.systemPrompt,
allowedTools: [],
});
} finally {
setIsLoading(false);
}
};
const availableModels = models?.models
?.filter((m: any) => m.provider === formData.provider || formData.provider === "Ollama")
.map((m: any) => m.id) || [];
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-2xl">
<DialogHeader>
<DialogTitle>Deploy New Agent</DialogTitle>
</DialogHeader>
<div className="space-y-4">
{/* Basic Info */}
<div className="space-y-2">
<Label htmlFor="name">Agent Name *</Label>
<Input
id="name"
placeholder="e.g., Code Reviewer Agent"
value={formData.name}
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
className="font-mono"
/>
</div>
<div className="space-y-2">
<Label htmlFor="description">Description</Label>
<Textarea
id="description"
placeholder="What is this agent responsible for?"
value={formData.description}
onChange={(e) => setFormData({ ...formData, description: e.target.value })}
rows={2}
className="font-mono text-sm"
/>
</div>
{/* Role & Provider */}
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="role">Role *</Label>
<Select value={formData.role} onValueChange={(value) => setFormData({ ...formData, role: value })}>
<SelectTrigger id="role" className="font-mono">
<SelectValue />
</SelectTrigger>
<SelectContent>
{AGENT_ROLES.map((role) => (
<SelectItem key={role.value} value={role.value}>
{role.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label htmlFor="provider">Provider *</Label>
<Select value={formData.provider} onValueChange={(value) => setFormData({ ...formData, provider: value, model: "" })}>
<SelectTrigger id="provider" className="font-mono">
<SelectValue />
</SelectTrigger>
<SelectContent>
{PROVIDERS.map((provider) => (
<SelectItem key={provider.value} value={provider.value}>
{provider.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
</div>
{/* Model Selection */}
<div className="space-y-2">
<Label htmlFor="model">Model *</Label>
<Select value={formData.model} onValueChange={(value) => setFormData({ ...formData, model: value })}>
<SelectTrigger id="model" className="font-mono">
<SelectValue />
</SelectTrigger>
<SelectContent>
{availableModels.length > 0 ? (
availableModels.map((model: string) => (
<SelectItem key={model} value={model}>
{model}
</SelectItem>
))
) : (
<SelectItem value="default" disabled>
No models available
</SelectItem>
)}
</SelectContent>
</Select>
</div>
{/* LLM Parameters */}
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="temperature">
Temperature: {formData.temperature.toFixed(2)}
</Label>
<Input
id="temperature"
type="range"
min="0"
max="2"
step="0.01"
value={formData.temperature}
onChange={(e) => setFormData({ ...formData, temperature: parseFloat(e.target.value) })}
className="cursor-pointer"
/>
</div>
<div className="space-y-2">
<Label htmlFor="maxTokens">Max Tokens</Label>
<Input
id="maxTokens"
type="number"
value={formData.maxTokens}
onChange={(e) => setFormData({ ...formData, maxTokens: parseInt(e.target.value) })}
className="font-mono"
/>
</div>
</div>
{/* System Prompt */}
<div className="space-y-2">
<Label htmlFor="systemPrompt">System Prompt</Label>
<Textarea
id="systemPrompt"
placeholder="Define the agent's behavior and instructions..."
value={formData.systemPrompt}
onChange={(e) => setFormData({ ...formData, systemPrompt: e.target.value })}
rows={4}
className="font-mono text-sm"
/>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button onClick={handleCreate} disabled={isLoading || createMutation.isPending || !formData.name.trim()}>
{isLoading || createMutation.isPending ? (
<>
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
Creating...
</>
) : (
<>
<Plus className="w-4 h-4 mr-2" />
Create Agent
</>
)}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}