import { client } from '@/ui/api/client' import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { Code, Loader2, MoreVertical, Plus, Puzzle, Trash2, Upload, X } from 'lucide-react' import React, { useState, useRef } from 'react' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/ui/components/ui/card' import { Button } from '@/ui/components/ui/button' import { cn } from '@/ui/lib/utils' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/ui/components/ui/dialog' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/ui/components/ui/dropdown-menu' import { Input } from '@/ui/components/ui/input' import { Label } from '@/ui/components/ui/label' import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@/ui/components/ui/alert-dialog' import { SkillInfo } from '@shumai/dtos' const Github = (props: React.SVGProps) => ( ) interface SkillsConfigCardProps { teamId: string } export const SkillsConfigCard: React.FC = ({ teamId }) => { const queryClient = useQueryClient() const [isAddDialogOpen, setIsAddDialogOpen] = useState(false) const [isConfigDialogOpen, setIsConfigDialogOpen] = useState(false) const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false) const [selectedSkill, setSelectedSkill] = useState(null) // Fetch Skills const { data, isLoading } = useQuery({ queryKey: ['teams', teamId, 'skills'], queryFn: async () => { const res = await client.api.teams[':teamId'].skills.$get({ param: { teamId } }) if (!res.ok) throw new Error('Failed to fetch skills') return await res.json() }, }) // Delete Skill const deleteMutation = useMutation({ mutationFn: async (id: string) => { const res = await client.api.skills[':id'].$delete({ param: { id }, }) if (!res.ok) throw new Error('Failed to delete skill') }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'skills'] }) setIsDeleteDialogOpen(false) }, }) const skills = data?.skills || [] return (
Skills Management Extend your chatbot's capabilities with custom skills.
{isLoading ? (
) : skills.length === 0 ? (

No skills installed

Add a skill via GitHub URL or upload a ZIP file to get started.

) : (
{skills.map((skill) => ( { setSelectedSkill(skill) setIsDeleteDialogOpen(true) }} onConfigure={() => { setSelectedSkill(skill) setIsConfigDialogOpen(true) }} /> ))}
)}
{selectedSkill && ( { setIsConfigDialogOpen(open) if (!open) { // Ensure body pointer-events is restored if something stuck it setTimeout(() => { document.body.style.pointerEvents = 'auto' }, 100) } }} teamId={teamId} skill={selectedSkill} /> )} Are you absolutely sure? This action cannot be undone. This will permanently delete the skill " {selectedSkill?.name}" and all its configurations. Cancel { if (selectedSkill) { deleteMutation.mutate(selectedSkill.id) } }} > {deleteMutation.isPending ? ( ) : ( )} Delete
) } const SkillItem = ({ skill, onDelete, onConfigure, }: { skill: SkillInfo onDelete: () => void onConfigure: () => void }) => { return (

{skill.name}

e.stopPropagation()}> { e.stopPropagation() onDelete() }} className="text-red-500 focus:text-red-500 gap-2 cursor-pointer" > Delete

{skill.description || 'No description provided.'}

Updated {new Date(skill.updatedAt).toLocaleDateString()}
Installed
) } const AddSkillDialog = ({ open, onOpenChange, teamId, }: { open: boolean onOpenChange: (open: boolean) => void teamId: string }) => { const queryClient = useQueryClient() const [githubUrl, setGithubUrl] = useState('') const [isProcessing, setIsProcessing] = useState(false) const fileInputRef = useRef(null) // Need a project ID for the attachment upload const { data: projectsData } = useQuery({ queryKey: ['teams', teamId, 'projects'], queryFn: async () => { const res = await client.api.teams[':teamId'].projects.$get({ param: { teamId }, query: { first: '1' }, }) if (!res.ok) throw new Error('Failed to fetch projects') return await res.json() }, enabled: open, }) const installSkill = async (payload: { assetId?: string githubUrl?: string override?: boolean }) => { setIsProcessing(true) try { const res = await client.api.teams[':teamId'].skills.$post({ param: { teamId }, json: payload, }) if (res.status === 409) { const data = (await res.json()) as { error: string } if (window.confirm(`${data.error}\n\nDo you want to override the existing skill?`)) { await installSkill({ ...payload, override: true }) return } } else if (!res.ok) { const errorData = (await res.json().catch(() => ({}))) as { error?: string } throw new Error(errorData.error || 'Failed to install skill') } else { queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'skills'] }) onOpenChange(false) setGithubUrl('') } } catch (err: unknown) { if (err instanceof Error) { alert(err.message) } else { alert('An unknown error occurred') } } finally { setIsProcessing(false) } } const handleFileUpload = async (files: FileList | null) => { if (!files || files.length === 0) return const projectId = projectsData?.data?.[0]?.id if (!projectId) { alert('You need at least one project in your team to upload skills.') return } const fileToUpload = files[0] if (!fileToUpload.name.toLowerCase().endsWith('.zip')) { alert('Only .zip files are supported.') return } setIsProcessing(true) try { const fileName = fileToUpload.name const contentType = fileToUpload.type || 'application/zip' // 1. Get Presigned URL and Asset ID const attachRes = await client.api.projects[':projectId'].attachments.$post({ param: { projectId }, json: { fileName: fileName, size: fileToUpload.size, contentType: contentType, }, }) if (!attachRes.ok) throw new Error('Failed to get upload URL') const { id: assetId, uploadUrl } = (await attachRes.json()) as { id: string uploadUrl: string } // 2. Upload to S3 const uploadRes = await fetch(uploadUrl, { method: 'PUT', body: fileToUpload, headers: { 'Content-Type': contentType }, }) if (!uploadRes.ok) throw new Error('Failed to upload file to storage') // 3. Install Skill await installSkill({ assetId }) } catch (err: unknown) { if (err instanceof Error) { alert(err.message) } else { alert('An unknown error occurred') } } finally { setIsProcessing(false) } } return ( Add New Skill Import a skill from a local ZIP archive or a GitHub repository.
{/* File Upload Section */}
!isProcessing && fileInputRef.current?.click()} className={cn( 'group relative h-32 border-2 border-dashed rounded-xl flex flex-col items-center justify-center transition-all cursor-pointer', isProcessing ? 'opacity-50 cursor-not-allowed bg-slate-50 dark:bg-slate-900 border-slate-200 dark:border-slate-800' : 'hover:bg-blue-50/50 dark:hover:bg-blue-900/10 hover:border-blue-500/50 border-slate-200 dark:border-slate-800', )} > handleFileUpload(e.target.files)} />

Select ZIP file

Packages must contain a SKILL.md

{isProcessing && !githubUrl && (
Processing package...
)}
OR
{/* GitHub URL Section */}
setGithubUrl(e.target.value)} disabled={isProcessing} className="pl-9" />

Example: https://github.com/google/gemini-cli

) } const ConfigSkillDialog = ({ open, onOpenChange, teamId, skill, }: { open: boolean onOpenChange: (open: boolean) => void teamId: string skill: SkillInfo }) => { const queryClient = useQueryClient() const [config, setConfig] = useState({ ...(skill.config || {}), environmentVariables: skill.config?.environmentVariables || [], }) const [isSaving, setIsSaving] = useState(false) const handleEnvVarValueChange = (index: number, value: string) => { const newVars = [...config.environmentVariables] newVars[index] = { ...newVars[index], default: value } setConfig({ ...config, environmentVariables: newVars }) } const handleEnvVarNameChange = (index: number, name: string) => { const newVars = [...config.environmentVariables] newVars[index] = { ...newVars[index], name } setConfig({ ...config, environmentVariables: newVars }) } const addEnvVar = () => { setConfig({ ...config, environmentVariables: [...config.environmentVariables, { name: '', default: '' }], }) } const removeEnvVar = (index: number) => { const newVars = [...config.environmentVariables] newVars.splice(index, 1) setConfig({ ...config, environmentVariables: newVars }) } const handleSave = async () => { // Basic validation: filter out empty names const filteredVars = config.environmentVariables.filter((v) => v.name.trim() !== '') const finalConfig = { ...config, environmentVariables: filteredVars } setIsSaving(true) try { const res = await client.api.skills[':id'].config.$patch({ param: { id: skill.id }, json: { config: finalConfig }, }) if (!res.ok) { const errorData = (await res.json().catch(() => ({}))) as { error?: string } throw new Error(errorData.error || 'Failed to update config') } queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'skills'] }) onOpenChange(false) } catch (err: unknown) { if (err instanceof Error) { alert(err.message) } else { alert('An unknown error occurred') } } finally { setIsSaving(false) } } const envVars = config?.environmentVariables || [] return (
Configure Skill: {skill.name}
Manage environment variables for this skill instance.
{envVars.length === 0 ? (

No environment variables found. Click "Add Variable" to create one.

) : ( envVars.map((env: { name: string; default?: string | undefined }, index: number) => (
handleEnvVarNameChange(index, e.target.value)} placeholder="e.app. API_KEY" className="h-8 bg-white dark:bg-slate-950 border-slate-200 dark:border-slate-800 text-sm font-mono" />
handleEnvVarValueChange(index, e.target.value)} placeholder="Optional default value..." className="h-8 bg-white dark:bg-slate-950 border-slate-200 dark:border-slate-800 text-sm" />

If left empty, the value will be read from the host machine's environment.

)) )}
) }