'use client'; import React, { useState } from 'react'; import { Globe, GlobeLock, Download, Calendar, User, Tags, Loader2, AlertTriangle, Plus, GitBranch, Edit2, Eye } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import { useMyTemplates, useUnpublishTemplate, usePublishTemplate } from '@/hooks/react-query/secure-mcp/use-secure-mcp'; import { toast } from 'sonner'; import { getAgentAvatar } from '../../agents/_utils/get-agent-style'; import { Skeleton } from '@/components/ui/skeleton'; import Link from 'next/link'; interface PublishDialogData { templateId: string; templateName: string; currentTags: string[]; } export default function MyTemplatesPage() { const [actioningId, setActioningId] = useState(null); const [publishDialog, setPublishDialog] = useState(null); const [publishTags, setPublishTags] = useState(''); const { data: templates, isLoading, error } = useMyTemplates(); const unpublishMutation = useUnpublishTemplate(); const publishMutation = usePublishTemplate(); const handleUnpublish = async (templateId: string, templateName: string) => { try { setActioningId(templateId); await unpublishMutation.mutateAsync(templateId); toast.success(`${templateName} has been unpublished from the marketplace`); } catch (error: any) { toast.error(error.message || 'Failed to unpublish template'); } finally { setActioningId(null); } }; const openPublishDialog = (template: any) => { setPublishDialog({ templateId: template.template_id, templateName: template.name, currentTags: template.tags || [] }); setPublishTags((template.tags || []).join(', ')); }; const handlePublish = async () => { if (!publishDialog) return; try { setActioningId(publishDialog.templateId); // Parse tags from comma-separated string const tags = publishTags .split(',') .map(tag => tag.trim()) .filter(tag => tag.length > 0); await publishMutation.mutateAsync({ template_id: publishDialog.templateId, tags: tags.length > 0 ? tags : undefined }); toast.success(`${publishDialog.templateName} has been published to the marketplace`); setPublishDialog(null); setPublishTags(''); } catch (error: any) { toast.error(error.message || 'Failed to publish template'); } finally { setActioningId(null); } }; const getTemplateStyling = (template: any) => { if (template.avatar && template.avatar_color) { return { avatar: template.avatar, color: template.avatar_color, }; } return getAgentAvatar(template.template_id); }; if (error) { return (
Failed to load your templates. Please try again later.
); } return ( <>

My Templates

Manage your secure agent templates and marketplace presence

{isLoading ? (
{Array.from({ length: 8 }).map((_, i) => (
))}
) : templates?.length === 0 ? (

No templates yet

Create your first secure agent template to share with the community while keeping your credentials safe.

) : (
{templates?.map((template) => { const { avatar, color } = getTemplateStyling(template); const isActioning = actioningId === template.template_id; return (
{avatar}
{template.is_public ? ( Public ) : ( Private )}

{template.name}

{template.metadata?.source_version_name && ( {template.metadata.source_version_name} )}

{template.description || 'No description available'}

{template.tags && template.tags.length > 0 && (
{template.tags.slice(0, 2).map(tag => ( {tag} ))} {template.tags.length > 2 && ( +{template.tags.length - 2} )}
)}
Created {new Date(template.created_at).toLocaleDateString()}
{template.is_public && template.marketplace_published_at && (
Published {new Date(template.marketplace_published_at).toLocaleDateString()}
)} {template.is_public && (
{template.download_count} downloads
)}
{template.is_public ? ( <> ) : ( )}
); })}
)}
{/* Publish Dialog */} setPublishDialog(null)}> Publish Template to Marketplace Make "{publishDialog?.templateName}" available for the community to discover and install.
setPublishTags(e.target.value)} className="mt-1" />

Separate tags with commas to help users discover your template

); }