better data models
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from collections.abc import Mapping
|
||||
from pathlib import PurePosixPath
|
||||
|
||||
import yaml
|
||||
from pydantic import Field
|
||||
from pydantic import field_validator
|
||||
|
||||
@@ -107,19 +108,31 @@ class SkillFrontmatter(StrictFrozenModel):
|
||||
return value
|
||||
|
||||
|
||||
class SkillDocumentModel(StrictFrozenModel):
|
||||
"""Structured representation of a skill markdown document."""
|
||||
|
||||
skill_id: str
|
||||
relpath: PurePosixPath
|
||||
content: str
|
||||
frontmatter: SkillFrontmatter
|
||||
|
||||
|
||||
class SkillReferenceDocumentModel(StrictFrozenModel):
|
||||
class StoredSkillReference(StrictFrozenModel):
|
||||
"""Structured representation of a skill reference markdown document."""
|
||||
|
||||
ref_id: str
|
||||
relpath: PurePosixPath
|
||||
content: str
|
||||
entry: ReferenceEntry
|
||||
|
||||
|
||||
class StoredSkill(StrictFrozenModel):
|
||||
"""Structured representation of a skill markdown document."""
|
||||
|
||||
skill_id: str
|
||||
relpath: PurePosixPath
|
||||
content: str
|
||||
frontmatter: SkillFrontmatter
|
||||
references: dict[str, StoredSkillReference] = Field(default_factory=dict)
|
||||
|
||||
@field_validator("frontmatter", mode="before")
|
||||
@classmethod
|
||||
def parse_frontmatter_yaml(cls, value: str | None):
|
||||
if value is None:
|
||||
return None
|
||||
try:
|
||||
data = yaml.safe_load(value)
|
||||
except yaml.YAMLError as e:
|
||||
raise ValueError(f"invalid YAML in frontmatter: {e}") from e
|
||||
return SkillFrontmatter.model_validate(data)
|
||||
|
||||
Reference in New Issue
Block a user