"""Generate the Worker ontology catalog from the canonical Python category/profile models.""" from __future__ import annotations import argparse import json from pathlib import Path from tessera.ontology.categories import NOUN_CATEGORIES, VERB_CATEGORIES from tessera.ontology.profiles import _PROFILE_ALIASES, CALLER_PROFILES def generated_source() -> str: catalogs = { "NOUN_CATALOG": { key: value.model_dump(mode="json") for key, value in NOUN_CATEGORIES.items() }, "VERB_CATALOG": { key: value.model_dump(mode="json") for key, value in VERB_CATEGORIES.items() }, "PROFILE_CATALOG": { key: value.model_dump(mode="json") for key, value in CALLER_PROFILES.items() }, "PROFILE_ALIASES": _PROFILE_ALIASES, } lines = ["// Generated by scripts/build_ontology_catalog.py; do not edit catalog data by hand."] for name, data in catalogs.items(): lines.append( f"export const {name} = {json.dumps(data, sort_keys=True, indent=2, ensure_ascii=False)};" ) return "\n\n".join(lines) + "\n" def main() -> int: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--check", action="store_true") args = parser.parse_args() destination = Path(__file__).resolve().parents[1] / "deploy/cloudflare/ontology_catalog.js" content = generated_source() if args.check: if not destination.exists() or destination.read_text() != content: print( "Worker ontology catalog is stale; run uv run python scripts/build_ontology_catalog.py" ) return 1 else: destination.write_text(content) return 0 if __name__ == "__main__": raise SystemExit(main())