MCPcopy Create free account
hub / github.com/HKUDS/OpenSpace / upload_skill

Method upload_skill

openspace/cloud/client.py:286–377  ·  view source on GitHub ↗

Upload a local skill to the cloud (stage → diff → create record). Returns a result dict with status, record_id, etc.

(
        self,
        skill_dir: Path,
        *,
        visibility: str = "public",
        origin: str = "imported",
        parent_skill_ids: Optional[List[str]] = None,
        tags: Optional[List[str]] = None,
        created_by: str = "",
        change_summary: str = "",
    )

Source from the content-addressed store, hash-verified

284 raise CloudError(f"409 conflict: {body_text}", status_code=409, body=body_text)
285
286 def upload_skill(
287 self,
288 skill_dir: Path,
289 *,
290 visibility: str = "public",
291 origin: str = "imported",
292 parent_skill_ids: Optional[List[str]] = None,
293 tags: Optional[List[str]] = None,
294 created_by: str = "",
295 change_summary: str = "",
296 ) -> Dict[str, Any]:
297 """Upload a local skill to the cloud (stage → diff → create record).
298
299 Returns a result dict with status, record_id, etc.
300 """
301 from openspace.skill_engine.skill_utils import parse_frontmatter
302
303 skill_path = Path(skill_dir)
304 skill_file = skill_path / SKILL_FILENAME
305 if not skill_file.exists():
306 raise CloudError(f"SKILL.md not found in {skill_dir}")
307
308 content = skill_file.read_text(encoding="utf-8")
309 fm = parse_frontmatter(content)
310 name = fm.get("name", skill_path.name)
311 description = fm.get("description", "")
312
313 if not name:
314 raise CloudError("SKILL.md frontmatter missing 'name' field")
315
316 parents = parent_skill_ids or []
317 self._validate_origin_parents(origin, parents)
318
319 api_visibility = visibility
320
321 # Step 1: Stage
322 logger.info(f"upload_skill: staging files for '{name}'")
323 artifact_id, file_count = self.stage_artifact(skill_path)
324 logger.info(f"upload_skill: staged {file_count} file(s), artifact_id={artifact_id}")
325
326 # Step 2: Content diff
327 content_diff = self._compute_content_diff(skill_path, api_visibility, parents)
328
329 # Step 3: Create record
330 record_id = f"{name}__clo_{uuid.uuid4().hex[:8]}"
331 payload: Dict[str, Any] = {
332 "record_id": record_id,
333 "artifact_id": artifact_id,
334 # name/description are NOT sent — the server extracts them
335 # from SKILL.md YAML frontmatter (Task 4+F4 change).
336 "origin": origin,
337 "visibility": api_visibility,
338 "parent_skill_ids": parents,
339 "tags": tags or [],
340 "level": "workflow",
341 }
342 if created_by:
343 payload["created_by"] = created_by

Callers 1

mainFunction · 0.95

Calls 8

stage_artifactMethod · 0.95
_compute_content_diffMethod · 0.95
create_recordMethod · 0.95
parse_frontmatterFunction · 0.90
CloudErrorClass · 0.85
getMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected