Tool with system-specific downloads and enhanced functionality
| 264 | |
| 265 | |
| 266 | class Tool(BaseModel): |
| 267 | """Tool with system-specific downloads and enhanced functionality""" |
| 268 | |
| 269 | name: str = Field(pattern=r"^[a-zA-Z0-9_.-]+$", description="Tool name") |
| 270 | version: str = Field(min_length=1, description="Tool version") |
| 271 | systems: list[SystemDownload] = Field( |
| 272 | min_length=1, description="System-specific downloads" |
| 273 | ) |
| 274 | |
| 275 | @field_validator("systems") |
| 276 | @classmethod |
| 277 | def validate_unique_systems(cls, v: list[SystemDownload]) -> list[SystemDownload]: |
| 278 | """Ensure no duplicate host systems""" |
| 279 | hosts = [system.host for system in v] |
| 280 | if len(hosts) != len(set(hosts)): |
| 281 | raise ValueError("Duplicate host systems found in tool downloads") |
| 282 | return v |
| 283 | |
| 284 | def get_system_download(self, host_pattern: str) -> Optional[SystemDownload]: |
| 285 | """Get system download matching host pattern""" |
| 286 | for system in self.systems: |
| 287 | if host_pattern in system.host: |
| 288 | return system |
| 289 | return None |
| 290 | |
| 291 | def get_compatible_systems(self) -> list[str]: |
| 292 | """Get list of compatible host systems""" |
| 293 | return [system.host for system in self.systems] |
| 294 | |
| 295 | model_config = ConfigDict( |
| 296 | json_schema_extra={ |
| 297 | "example": { |
| 298 | "name": "xtensa-esp32-elf-gcc", |
| 299 | "version": "esp-2021r2-patch5-8.4.0", |
| 300 | "systems": [ |
| 301 | { |
| 302 | "host": "x86_64-pc-linux-gnu", |
| 303 | "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch5/xtensa-esp32-elf-gcc8_4_0-esp-2021r2-patch5-linux-amd64.tar.gz", |
| 304 | "archiveFileName": "xtensa-esp32-elf-gcc8_4_0-esp-2021r2-patch5-linux-amd64.tar.gz", |
| 305 | "checksum": "SHA-256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", |
| 306 | "size": "150000000", |
| 307 | } |
| 308 | ], |
| 309 | } |
| 310 | } |
| 311 | ) |
| 312 | |
| 313 | |
| 314 | class Package(BaseModel): |