'use client'; import React, { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Separator } from '@/components/ui/separator'; import { Clock, GitBranch, CheckCircle2, ArrowUpRight, History, Plus } from 'lucide-react'; import { formatDistanceToNow } from 'date-fns'; import { useAgentVersions, useActivateAgentVersion } from '@/lib/versioning'; import { Agent } from '@/hooks/react-query/agents/utils'; import { cn } from '@/lib/utils'; import { VersionInlineEditor } from './version-inline-editor'; interface AgentVersionManagerProps { agent: Agent; onCreateVersion?: () => void; } export function AgentVersionManager({ agent, onCreateVersion }: AgentVersionManagerProps) { const { data: versions, isLoading } = useAgentVersions(agent.agent_id); const activateVersion = useActivateAgentVersion(); const [selectedVersion, setSelectedVersion] = useState(null); if (isLoading) { return (
); } const currentVersion = versions?.find(v => v.isActive); const versionHistory = versions?.sort((a, b) => b.versionNumber.value - a.versionNumber.value) || []; const handleActivateVersion = (versionId: string) => { activateVersion.mutate({ agentId: agent.agent_id, versionId }); }; return (
Version Management Manage different versions of your agent configuration
{onCreateVersion && ( )}
Current Version Version History {currentVersion ? (
{currentVersion.versionName} Active version
Created {formatDistanceToNow(currentVersion.createdAt, { addSuffix: true })}
Tools {Object.keys(currentVersion.toolConfiguration.tools || {}).length} enabled
MCP Servers {(currentVersion.configuredMcps?.length || 0) + (currentVersion.customMcps?.length || 0)}
) : (
No version information available
)}
{versionHistory.map((version, index) => { const isActive = version.isActive; const isSelected = version.versionId.value === selectedVersion; return (
setSelectedVersion(version.versionId.value)} >
{version.versionName} {isActive && ( Current )}

Created {formatDistanceToNow(new Date(version.createdAt), { addSuffix: true })}

{!isActive && ( )}
{isSelected && (
Tools {Object.keys(version.agentpress_tools || {}).length} enabled
MCP Servers {(version.configuredMcps?.length || 0) + (version.customMcps?.length || 0)}
)}
); })} {versionHistory.length === 0 && (

No version history available

)}
); }