Spaces:
Running
Running
Download core/tools/preview.py from Aynkhn/WorkPilot-AI: direct link, hf CLI and curl.
- Browser
- Download file 652 Bytes
-
https://huggingface.co/spaces/Aynkhn/WorkPilot-AI/resolve/main/core/tools/preview.py
- Command line
-
hf download hf://spaces/Aynkhn/WorkPilot-AI/core/tools/preview.py
-
curl -L -o preview.py https://huggingface.co/spaces/Aynkhn/WorkPilot-AI/resolve/main/core/tools/preview.py
652 Bytes
| """Canonical hashing used for previews, approvals and idempotency.""" | |
| from __future__ import annotations | |
| import hashlib | |
| import json | |
| from typing import Any | |
| def canonical_json(value: Any) -> str: | |
| return json.dumps(value, sort_keys=True, separators=(",", ":"), default=str) | |
| def sha256_hex(text: str) -> str: | |
| return hashlib.sha256(text.encode("utf-8")).hexdigest() | |
| def preview_hash(effect: Any) -> str: | |
| """Hash of a would-be effect. Handlers return this from dry runs; the gateway checks that | |
| the effect at execution time still matches the one a human approved.""" | |
| return sha256_hex(canonical_json(effect)) | |