"""Hash pinned public WorldinWorld source documents without installing or running the model."""

import hashlib
import json
import urllib.request

SOURCE_REVISION = "3933f142f4a312f211cea7159c13e2909718dcf6"
MODEL_REVISION = "5c33dd40b213598c418fd25bff30fdbd23fd38a7"
BASE = f"https://raw.githubusercontent.com/Westlake-AGI-Lab/WorldinWorld/{SOURCE_REVISION}"
MODEL = f"https://huggingface.co/robbyant/lingbot-world-v2-14b-causal-fast/resolve/{MODEL_REVISION}"
DOCUMENTS = {
    "README.md": f"{BASE}/README.md",
    "wiw/prep.py": f"{BASE}/wiw/prep.py",
    "wiw/config.py": f"{BASE}/wiw/config.py",
    "wiw/bullet.py": f"{BASE}/wiw/bullet.py",
    "wiw/traj.py": f"{BASE}/wiw/traj.py",
    "wiw/depth.py": f"{BASE}/wiw/depth.py",
    "wiw/generate.py": f"{BASE}/wiw/generate.py",
    "LICENSE": f"{BASE}/LICENSE",
    "model/README.md": f"{MODEL}/README.md",
}


def audit():
    result = []
    for name, url in DOCUMENTS.items():
        request = urllib.request.Request(url, headers={"User-Agent": "CloutSourceAudit/1.0"})
        with urllib.request.urlopen(request, timeout=30) as response:
            data = response.read()
        result.append(
            {"name": name, "bytes": len(data), "sha256": hashlib.sha256(data).hexdigest()}
        )
    return {"sourceRevision": SOURCE_REVISION, "modelRevision": MODEL_REVISION, "documents": result}


if __name__ == "__main__":
    print(json.dumps(audit(), indent=2))
