|
| 1 | +# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from pathlib import Path |
| 16 | + |
| 17 | +import frontmatter |
| 18 | + |
| 19 | +from veadk.skills.skill import Skill |
| 20 | +from veadk.utils.logger import get_logger |
| 21 | + |
| 22 | +logger = get_logger(__name__) |
| 23 | + |
| 24 | + |
| 25 | +def load_skill_from_directory(skill_directory: Path) -> Skill: |
| 26 | + logger.info(f"Load skill from {skill_directory}") |
| 27 | + skill_readme = skill_directory / "SKILL.md" |
| 28 | + skill = frontmatter.load(str(skill_readme)) |
| 29 | + |
| 30 | + skill_name = skill.get("name", "") |
| 31 | + skill_description = skill.get("description", "") |
| 32 | + |
| 33 | + if not skill_name or not skill_description: |
| 34 | + logger.error( |
| 35 | + f"Skill {skill_readme} is missing name or description. Please check the SKILL.md file." |
| 36 | + ) |
| 37 | + raise ValueError( |
| 38 | + f"Skill {skill_readme} is missing name or description. Please check the SKILL.md file." |
| 39 | + ) |
| 40 | + |
| 41 | + logger.info( |
| 42 | + f"Successfully loaded skill from {skill_readme}, name={skill['name']}, description={skill['description']}" |
| 43 | + ) |
| 44 | + return Skill( |
| 45 | + name=skill_name, # type: ignore |
| 46 | + description=skill_description, # type: ignore |
| 47 | + path=str(skill_directory), |
| 48 | + ) |
| 49 | + |
| 50 | + |
| 51 | +def load_skills_from_directory(skills_directory: Path) -> list[Skill]: |
| 52 | + skills = [] |
| 53 | + logger.info(f"Load skills from {skills_directory}") |
| 54 | + for skill_directory in skills_directory.iterdir(): |
| 55 | + if skill_directory.is_dir(): |
| 56 | + skill = load_skill_from_directory(skill_directory) |
| 57 | + skills.append(skill) |
| 58 | + return skills |
| 59 | + |
| 60 | + |
| 61 | +def load_skills_from_cloud(space_name: str) -> list[Skill]: ... |
0 commit comments