MCPcopy Create free account
hub / github.com/MemTensor/MemOS / restoreSkillBundleFromHub

Function restoreSkillBundleFromHub

packages/memos-core/src/client/skill-sync.ts:117–176  ·  view source on GitHub ↗
(
  store: SqliteStore,
  ctx: PluginContext,
  payload: SkillBundle & { skillId?: string },
)

Source from the content-addressed store, hash-verified

115}
116
117export function restoreSkillBundleFromHub(
118 store: SqliteStore,
119 ctx: PluginContext,
120 payload: SkillBundle & { skillId?: string },
121): { localSkillId: string; localName: string; dirPath: string } {
122 validateBundle(payload.bundle);
123
124 const skillsStoreDir = path.join(ctx.stateDir, "skills-store");
125 fs.mkdirSync(skillsStoreDir, { recursive: true });
126
127 const baseName = sanitizeName(payload.metadata.name) || `hub-skill-${(payload.skillId ?? payload.metadata.id).slice(0, 8)}`;
128 const resolvedName = resolveLocalSkillName(store, baseName, payload.skillId ?? payload.metadata.id);
129 const dirPath = path.join(skillsStoreDir, resolvedName);
130 fs.mkdirSync(dirPath, { recursive: true });
131 fs.writeFileSync(path.join(dirPath, "SKILL.md"), payload.bundle.skill_md, "utf8");
132
133 writeCompanionFiles(dirPath, "scripts", payload.bundle.scripts);
134 writeCompanionFiles(dirPath, "references", payload.bundle.references);
135 if (payload.bundle.evals.length > 0) {
136 const evalDir = path.join(dirPath, "evals");
137 fs.mkdirSync(evalDir, { recursive: true });
138 fs.writeFileSync(path.join(evalDir, "evals.json"), JSON.stringify({ skill_name: payload.metadata.name, evals: payload.bundle.evals }, null, 2), "utf8");
139 }
140
141 const now = Date.now();
142 const localSkillId = randomUUID();
143 const skill: Skill = {
144 id: localSkillId,
145 name: resolvedName,
146 description: payload.metadata.description,
147 version: payload.metadata.version,
148 status: "active",
149 tags: JSON.stringify(["hub-import"]),
150 sourceType: "manual",
151 dirPath,
152 installed: 0,
153 owner: "agent:main",
154 visibility: "private",
155 qualityScore: payload.metadata.qualityScore,
156 createdAt: now,
157 updatedAt: now,
158 };
159 const version: SkillVersion = {
160 id: randomUUID(),
161 skillId: localSkillId,
162 version: payload.metadata.version,
163 content: payload.bundle.skill_md,
164 changelog: "Imported from hub",
165 changeSummary: "Imported from hub",
166 upgradeType: "create",
167 sourceTaskId: null,
168 metrics: "{}",
169 qualityScore: payload.metadata.qualityScore,
170 createdAt: now,
171 };
172
173 store.insertSkill(skill);
174 store.insertSkillVersion(version);

Callers 1

Calls 7

validateBundleFunction · 0.70
sanitizeNameFunction · 0.70
resolveLocalSkillNameFunction · 0.70
writeCompanionFilesFunction · 0.70
joinMethod · 0.45
insertSkillMethod · 0.45
insertSkillVersionMethod · 0.45

Tested by

no test coverage detected