|
17 | 17 | import json |
18 | 18 | import os |
19 | 19 | import zipfile |
| 20 | +import frontmatter |
20 | 21 | from pathlib import Path |
21 | 22 | from datetime import datetime |
22 | 23 |
|
|
31 | 32 |
|
32 | 33 |
|
33 | 34 | def register_skills_tool( |
34 | | - skill_name: str, |
35 | | - skill_description: str, |
36 | 35 | skill_local_path: str, |
37 | 36 | tool_context: ToolContext, |
38 | 37 | ) -> str: |
39 | 38 | """Register a skill to the remote skill space by uploading its zip package to TOS and calling the CreateSkill API. |
40 | 39 |
|
41 | 40 | Args: |
42 | | - skill_name (str): The name of the skill. |
43 | | - skill_description (str): The description of the skill. |
44 | 41 | skill_local_path (str): The local path of the skill directory. |
45 | 42 | - The format of the skill directory is as follows: |
46 | 43 | skill_local_path/ |
@@ -68,6 +65,16 @@ def register_skills_tool( |
68 | 65 | logger.error(f"Skill path '{skill_path}' has no SKILL.md file.") |
69 | 66 | return f"Skill path '{skill_path}' has no SKILL.md file." |
70 | 67 |
|
| 68 | + try: |
| 69 | + skill = frontmatter.load(str(skill_readme)) |
| 70 | + skill_name = skill.get("name", "") |
| 71 | + # skill_description = skill.get("description", "") |
| 72 | + except Exception as e: |
| 73 | + logger.error( |
| 74 | + f"Failed to get skill name and description from {skill_readme}: {e}" |
| 75 | + ) |
| 76 | + return f"Failed to get skill name and description from {skill_readme}: {e}" |
| 77 | + |
71 | 78 | zip_file_path = working_dir / "outputs" / f"{skill_name}.zip" |
72 | 79 |
|
73 | 80 | with zipfile.ZipFile(zip_file_path, "w", zipfile.ZIP_DEFLATED) as zipf: |
@@ -138,13 +145,14 @@ def register_skills_tool( |
138 | 145 | x.strip() for x in skill_space_ids.split(",") if x.strip() |
139 | 146 | ] |
140 | 147 |
|
| 148 | + request_body = { |
| 149 | + "TosUrl": tos_url, |
| 150 | + "SkillSpaces": skill_space_ids_list, |
| 151 | + } |
| 152 | + logger.debug(f"CreateSkill request body: {request_body}") |
| 153 | + |
141 | 154 | response = ve_request( |
142 | | - request_body={ |
143 | | - "Name": skill_name, |
144 | | - "Description": skill_description, |
145 | | - "TosUrl": tos_url, |
146 | | - "SkillSpaces": skill_space_ids_list, |
147 | | - }, |
| 155 | + request_body=request_body, |
148 | 156 | action="CreateSkill", |
149 | 157 | ak=access_key, |
150 | 158 | sk=secret_key, |
|
0 commit comments