import { App, Button, Form, Input, Modal, Upload, type UploadFile } from "antd"; import { Select } from "@/components/ui/base/select"; import { Switch } from "@/components/ui/base/switch"; import { SegmentedControl } from "@/components/ui/base/segmented-control"; import { FileArchive, FileText, GitBranch, UploadCloud } from "lucide-react"; import { useEffect, useState } from "react"; import { fallbackSkillCategories } from "@/pages/skills/skill-catalog"; import { installGitHubSkill, installSkillUpload, type Skill } from "@/services/api/skills"; type InstallMode = "markdown" | "zip" | "github"; type InstallFormValues = { name?: string; description?: string; tag: string; is_public: boolean; url?: string; ref?: string; subdir?: string; autoUpdate: boolean; }; const modeOptions = [ { value: "markdown", label: Markdown }, { value: "zip", label: ZIP 技能包 }, { value: "github", label: GitHub }, ]; export function SkillInstallModal({ open, onClose, onInstalled, onManualCreate }: { open: boolean; onClose: () => void; onInstalled: (skill: Skill) => void; onManualCreate: () => void }) { const { message } = App.useApp(); const [form] = Form.useForm(); const [mode, setMode] = useState("markdown"); const [fileList, setFileList] = useState([]); const [installing, setInstalling] = useState(false); useEffect(() => { if (!open) return; setMode("markdown"); setFileList([]); form.setFieldsValue({ tag: "creative", is_public: true, autoUpdate: true, name: "", description: "", url: "", ref: "", subdir: "" }); }, [form, open]); const install = async () => { const values = await form.validateFields(); const file = fileList[0]?.originFileObj; if (mode !== "github" && !file) { message.warning(`请选择一个 ${mode === "zip" ? "ZIP 技能包" : "Markdown 文件"}`); return; } setInstalling(true); try { const result = mode === "github" ? await installGitHubSkill({ url: values.url || "", ref: values.ref || undefined, subdir: values.subdir || undefined, tag: values.tag, isPrivate: !values.is_public, autoUpdate: values.autoUpdate, }) : await installSkillUpload({ file: file as File, sourceType: mode, name: values.name || undefined, description: values.description || undefined, tag: values.tag, isPrivate: !values.is_public, }); message.success("技能已安装"); onInstalled(result.skill); } catch (error) { message.error(error instanceof Error ? error.message : "技能安装失败"); } finally { setInstalling(false); } }; return (
)} >

支持标准 SKILL.md、包含多层目录的 ZIP 技能包,或公开 GitHub 仓库。名称和简介会优先从技能入口自动读取。

{ setMode(value as InstallMode); setFileList([]); }} />
{mode === "github" ? ( <> } placeholder="https://github.com/owner/repository" />
) : ( <> { if (file.size > 20 * 1024 * 1024) { message.error("技能文件不能超过 20MB"); return Upload.LIST_IGNORE; } return false; }} onChange={({ fileList: next }) => setFileList(next.slice(-1))} onRemove={() => { setFileList([]); return true; }} >
拖入或选择 {mode === "zip" ? "ZIP 技能包" : "Markdown 文件"}
{mode === "zip" ? "根目录或唯一子目录中必须包含 SKILL.md" : "普通 .md 会作为技能入口 SKILL.md 安装"}
)}