from __future__ import annotations import json import subprocess from pathlib import Path from packages.adapters.arena import require_arena from packages.robots.profiles import get_robot_profile from packages.schemas.models import RobotCapabilityProfile class RP13EmbodimentProvider: """RP1.3 provider boundary for the Isaac worker. USD conversion and articulation validation execute only inside the Arena worker. The core environment can still inspect the capability contract without importing Isaac. """ def __init__( self, converter_command: list[str] | None = None, validator_command: list[str] | None = None, ) -> None: self.converter_command = converter_command self.validator_command = validator_command def profile(self) -> RobotCapabilityProfile: return get_robot_profile("rp1_3") def compose_robot_layer(self, output_dir: Path) -> Path: require_arena() if not self.converter_command: raise RuntimeError("RP1.3 converter command is not configured") output_dir.mkdir(parents=True, exist_ok=True) target = output_dir / "robot.usda" result = subprocess.run( [*self.converter_command, "--robot", "rp1_3", "--output", str(target)], check=False, capture_output=True, text=True, ) if result.returncode or not target.exists(): raise RuntimeError(f"RP1.3 conversion failed: {result.stderr[-2000:]}") return target def validate(self, root_usd: Path) -> dict[str, object]: require_arena() if not self.validator_command: raise RuntimeError("RP1.3 validator command is not configured") result = subprocess.run( [*self.validator_command, "--robot", "rp1_3", "--scene", str(root_usd)], check=False, capture_output=True, text=True, ) if result.returncode: raise RuntimeError(f"RP1.3 validation failed: {result.stderr[-2000:]}") report: dict[str, object] = json.loads(result.stdout) return report