Buckets:

download
raw
5.97 kB
"""Pydantic models for ClawHub API responses."""
from __future__ import annotations
from pydantic import AliasChoices, BaseModel, Field, field_validator
class VersionInfo(BaseModel):
"""Skill version metadata."""
version: str
created_at: int | None = Field(default=None, alias="createdAt")
changelog: str | None = None
class SkillStats(BaseModel):
"""Skill usage statistics."""
comments: int = 0
downloads: int = 0
installs_all_time: int = Field(default=0, alias="installsAllTime")
installs_current: int = Field(default=0, alias="installsCurrent")
stars: int = 0
versions: int = 0
class SkillSummary(BaseModel):
"""Skill summary returned by the list endpoint."""
slug: str
display_name: str = Field(alias="displayName")
summary: str = ""
tags: dict[str, str] = Field(default_factory=dict)
stats: SkillStats = Field(default_factory=SkillStats)
created_at: int | None = Field(default=None, alias="createdAt")
updated_at: int | None = Field(default=None, alias="updatedAt")
latest_version: VersionInfo | None = Field(default=None, alias="latestVersion")
model_config = {"populate_by_name": True}
@field_validator("display_name", "summary", mode="before")
@classmethod
def _none_to_empty_string(cls, v: object) -> object:
"""Some registry entries send these text fields as explicit ``null``.
A field default (e.g. ``summary: str = ""``) only applies when the key
is *absent*; when the API sends the key with value ``null``, Pydantic
still validates against the annotated type and rejects it. That single
bad record used to abort parsing of the entire listing page (up to 250
skills) since items were validated without per-item error handling —
see the enumeration-truncation root cause in the monitor sweep.
"""
return "" if v is None else v
class ModerationInfo(BaseModel):
"""The registry's own security screening result for a skill.
A live record looks like this::
{"isSuspicious": false, "isMalwareBlocked": false, "verdict": "clean",
"reasonCodes": ["review.llm_review"], "summary": "Review: ...",
"engineVersion": "v2.4.24", "updatedAt": 1779950837609}
``verdict`` is the authoritative field and the boolean flags are derived
from it, so read the verdict rather than inferring one from flags that
default False. ``isPendingScan``, ``isHiddenByMod`` and ``isRemoved`` were
not present on any record observed; they are kept because absence is not
proof they never appear, but nothing should conclude "not pending" from
their defaults.
``engine_version`` and ``updated_at`` say which screening engine last
looked and when, which is the difference between a skill the platform
cleared recently and one cleared by an engine several versions old.
"""
is_pending_scan: bool = Field(default=False, alias="isPendingScan")
is_malware_blocked: bool = Field(default=False, alias="isMalwareBlocked")
is_suspicious: bool = Field(default=False, alias="isSuspicious")
is_hidden_by_mod: bool = Field(default=False, alias="isHiddenByMod")
is_removed: bool = Field(default=False, alias="isRemoved")
reason: str | None = None
verdict: str = ""
reason_codes: list[str] = Field(default_factory=list, alias="reasonCodes")
summary: str = ""
engine_version: str = Field(default="", alias="engineVersion")
updated_at: int | None = Field(default=None, alias="updatedAt")
model_config = {"populate_by_name": True}
class OwnerInfo(BaseModel):
"""Skill owner/publisher info.
The registry calls the account name ``handle``, not ``username``. Because
pydantic ignores unknown keys by default, validating a real response against
a model expecting ``username`` succeeds and silently yields an empty string,
which is how 992 enriched skills ended up with no publisher. ``handle`` is
accepted as an alias so a rename upstream fails loudly instead of quietly.
``user_id`` is the durable key. Handles can be changed by their owner, so
clustering a campaign on one risks splitting an operator in two or merging
two operators that reused a name.
"""
username: str = Field(
default="", validation_alias=AliasChoices("username", "handle")
)
user_id: str = Field(default="", validation_alias=AliasChoices("userId", "user_id"))
display_name: str = Field(
default="", validation_alias=AliasChoices("displayName", "display_name")
)
model_config = {"populate_by_name": True}
class SkillDetail(BaseModel):
"""Full skill detail returned by the get-by-slug endpoint."""
slug: str
display_name: str = Field(alias="displayName")
summary: str = ""
tags: dict[str, str] = Field(default_factory=dict)
stats: SkillStats = Field(default_factory=SkillStats)
created_at: int | None = Field(default=None, alias="createdAt")
updated_at: int | None = Field(default=None, alias="updatedAt")
latest_version: VersionInfo | None = Field(default=None, alias="latestVersion")
owner: OwnerInfo | None = None
moderation: ModerationInfo | None = None
model_config = {"populate_by_name": True}
class SearchResult(BaseModel):
"""Single search result from the search endpoint."""
score: float = 0.0
slug: str
display_name: str = Field(alias="displayName")
summary: str = ""
version: str | None = None
updated_at: int | None = Field(default=None, alias="updatedAt")
model_config = {"populate_by_name": True}
@field_validator("display_name", "summary", mode="before")
@classmethod
def _none_to_empty_string(cls, v: object) -> object:
"""See SkillSummary._none_to_empty_string: the registry sends these
text fields as explicit null often enough that this must be tolerated.
"""
return "" if v is None else v

Xet Storage Details

Size:
5.97 kB
·
Xet hash:
90a44c96441b453070eefc8710ba323b33ac1d05365e430e8323233b686ef210

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.