import { mkdirSync, writeFileSync } from "node:fs"; import { homedir } from "node:os"; import { dirname, join } from "node:path"; // ── hose-use Skill 文件 ──────────────────────────────────────────────────────── import skillMain from "../../skills/hose-use/SKILL.md" with { type: "text" }; import agentOpenAi from "../../skills/hose-use/agents/openai.yaml" with { type: "text" }; import refAuth from "../../skills/hose-use/references/auth.md" with { type: "text" }; import refBill from "../../skills/hose-use/references/bill.md" with { type: "text" }; import refWorkflow from "../../skills/hose-use/references/workflow.md" with { type: "text" }; import refService from "../../skills/hose-use/references/service.md" with { type: "text" }; import refContact from "../../skills/hose-use/references/contact.md" with { type: "text" }; import refTask from "../../skills/hose-use/references/task.md" with { type: "text" }; import refMessage from "../../skills/hose-use/references/message.md" with { type: "text" }; import refDimension from "../../skills/hose-use/references/dimension.md" with { type: "text" }; import refRole from "../../skills/hose-use/references/role.md" with { type: "text" }; import refFeeType from "../../skills/hose-use/references/feetype.md" with { type: "text" }; import refStore from "../../skills/hose-use/references/store.md" with { type: "text" }; import refAssistPlatform from "../../skills/hose-use/references/assist-platform.md" with { type: "text" }; import refDocs from "../../skills/hose-use/references/docs.md" with { type: "text" }; import multiMvel from "../../skills/hose-use/multi/ekuaibao-mvel/SKILL.md" with { type: "text" }; import multiMvelAgent from "../../skills/hose-use/multi/ekuaibao-mvel/agents/openai.yaml" with { type: "text" }; import multiNodes from "../../skills/hose-use/multi/ekuaibao-nodes/SKILL.md" with { type: "text" }; import multiNodesGray from "../../skills/hose-use/multi/ekuaibao-nodes/references/gray-nodes.md" with { type: "text" }; // ── hose-aipro Skill 文件 ────────────────────────────────────────────────────── import aiproSkillMain from "../../skills/hose-aipro/SKILL.md" with { type: "text" }; import aiproAgentOpenAi from "../../skills/hose-aipro/agents/openai.yaml" with { type: "text" }; import aiproRefApproval from "../../skills/hose-aipro/references/approval.md" with { type: "text" }; import aiproRefService from "../../skills/hose-aipro/references/service.md" with { type: "text" }; import aiproRefReadme from "../../skills/hose-aipro/references/README.references.md" with { type: "text" }; export const EMBEDDED_HOSE_USE_SKILL_FILES: Record = { "SKILL.md": skillMain, "agents/openai.yaml": agentOpenAi, "references/auth.md": refAuth, "references/bill.md": refBill, "references/feetype.md": refFeeType, "references/contact.md": refContact, "references/task.md": refTask, "references/message.md": refMessage, "references/dimension.md": refDimension, "references/role.md": refRole, "references/workflow.md": refWorkflow, "references/service.md": refService, "references/store.md": refStore, "references/assist-platform.md": refAssistPlatform, "references/docs.md": refDocs, "multi/ekuaibao-mvel/SKILL.md": multiMvel, "multi/ekuaibao-mvel/agents/openai.yaml": multiMvelAgent, "multi/ekuaibao-nodes/SKILL.md": multiNodes, "multi/ekuaibao-nodes/references/gray-nodes.md": multiNodesGray, }; export const EMBEDDED_AIPRO_SKILL_FILES: Record = { "SKILL.md": aiproSkillMain, "agents/openai.yaml": aiproAgentOpenAi, "references/approval.md": aiproRefApproval, "references/service.md": aiproRefService, "references/README.references.md": aiproRefReadme, }; // 保持模块级向后兼容 export const EMBEDDED_SKILL_FILES: Record = EMBEDDED_HOSE_USE_SKILL_FILES; export function getSkillContent(): string { return EMBEDDED_HOSE_USE_SKILL_FILES["SKILL.md"] || ""; } export function getAiProSkillContent(): string { return EMBEDDED_AIPRO_SKILL_FILES["SKILL.md"] || ""; } export function getDefaultGlobalSkillDir(): string { return join(homedir(), ".agents", "skills", "hose-use"); } export function getDefaultAiProGlobalSkillDir(): string { return join(homedir(), ".agents", "skills", "hose-aipro"); } export function installHoseUseSkillFiles(targetDir: string = getDefaultGlobalSkillDir()): { targetDir: string; files: string[]; } { mkdirSync(targetDir, { recursive: true }); const installed: string[] = []; for (const [relPath, content] of Object.entries(EMBEDDED_HOSE_USE_SKILL_FILES)) { const fullPath = join(targetDir, relPath); mkdirSync(dirname(fullPath), { recursive: true }); writeFileSync(fullPath, content, "utf8"); installed.push(relPath); } return { targetDir, files: installed }; } export function installAiProSkillFiles(targetDir: string = getDefaultAiProGlobalSkillDir()): { targetDir: string; files: string[]; } { mkdirSync(targetDir, { recursive: true }); const installed: string[] = []; for (const [relPath, content] of Object.entries(EMBEDDED_AIPRO_SKILL_FILES)) { const fullPath = join(targetDir, relPath); mkdirSync(dirname(fullPath), { recursive: true }); writeFileSync(fullPath, content, "utf8"); installed.push(relPath); } return { targetDir, files: installed }; } export function installSkillFiles(targetDir: string = getDefaultGlobalSkillDir()): { targetDir: string; files: string[]; skills?: string[]; } { const defaultGlobalDir = getDefaultGlobalSkillDir(); // 当为全局默认目录时,自动同时安装两个 Skill if (targetDir === defaultGlobalDir) { const hoseRes = installHoseUseSkillFiles(defaultGlobalDir); const aiproRes = installAiProSkillFiles(getDefaultAiProGlobalSkillDir()); return { targetDir, files: [...hoseRes.files, ...aiproRes.files.map((f) => `hose-aipro/${f}`)], skills: ["hose-use", "hose-aipro"], }; } // 显式指定自定义目录时,在该目录下安装 hose-use 文件 return installHoseUseSkillFiles(targetDir); } export function syncGlobalSkillIfPresent(): { synced: boolean; targetDir?: string; targetDirs: string[] } { const hoseDir = getDefaultGlobalSkillDir(); const aiproDir = getDefaultAiProGlobalSkillDir(); installHoseUseSkillFiles(hoseDir); installAiProSkillFiles(aiproDir); return { synced: true, targetDir: hoseDir, targetDirs: [hoseDir, aiproDir] }; }