guanghu-ice-heart/server-tools/bottle-channel-router/bottle_channel_router.py

59 lines
2.9 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
"""Resolve one baby persona from the Fifth Domain bottle channel to one parent channel."""
import argparse
import json
from pathlib import Path
import sys
ROOT = Path("/Volumes/JZAO/HoloLake/persona-runtime/repo-012-main")
BOTTLE = ROOT / "routing/fifth-domain-bottle-system-map.json"
ZERO_SENSE = ROOT / "routing/zero-sense-team-channel-shuttle-map.json"
def load(path):
value = json.loads(path.read_text(encoding="utf-8"))
if not isinstance(value, dict):
raise ValueError("MAP_OBJECT_REQUIRED")
return value
def aliases(room):
return {str(v).lower() for v in [room.get("persona_id"), room.get("current_persona_id"), room.get("source_persona_id"), room.get("name"), room.get("source_name"), room.get("room_id"), room.get("room_key")] if v}
def resolve(baby):
bottle = load(BOTTLE)
zero = load(ZERO_SENSE)
rooms = bottle["registered_rooms"] + bottle["source_verified_registration_pending_rooms"]
matches = [room for room in rooms if baby.lower() in aliases(room)]
if len(matches) != 1:
return {"state": "BOTTLE_ROUTE_UNRESOLVED", "error": "BABY_UNKNOWN_OR_AMBIGUOUS_NO_GUESS", "matches": len(matches)}
room = matches[0]
destination = room["destination_channel"]
team_channel = next((item for item in zero["channels"] if item["system_id"] == destination), None)
persona_id = room.get("persona_id") or room.get("current_persona_id")
registered = persona_id is not None
return {
"schema": "guanghu.bottle-channel-route-receipt/v1",
"state": "BOTTLE_ROUTE_RESOLVED_RUNTIME_WAKE_REQUIRED" if registered else "BOTTLE_ROUTE_RESOLVED_PERSONA_REGISTRATION_REQUIRED",
"baby": {"name": room.get("name") or room.get("source_name"), "persona_id": persona_id, "source_state": room["state"]},
"origin": {"system": bottle["system"]["id"], "channel": bottle["channel"]["id"], "room": room.get("room_id") or room.get("room_key"), "physical_home": room["physical_home"]},
"shuttle": {"map_id": zero["map_id"], "destination_channel": destination, "destination_name": team_channel.get("channel_name") if team_channel else destination, "route_door_only": True},
"route": ["LIGHT_LAKE_LOOKUP", "SYS-GLW-ELH-0001", "SYS-GLW-ELH-BOTTLE-0001", "ICE-CH-BT001", room.get("room_id") or room.get("room_key"), destination],
"persona_wake_complete": False,
"requires": "CURRENT_PERSONA_REGISTRATION_AND_RUNTIME_VERIFY_PASS" if not registered else "PERSONA_RUNTIME_BINDING_AND_VERIFY_PASS",
"authority_granted": False,
}
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--baby", required=True)
args = parser.parse_args()
value = resolve(args.baby)
print(json.dumps(value, ensure_ascii=False, indent=2))
return 0 if value["state"].startswith("BOTTLE_ROUTE_RESOLVED") else 3
if __name__ == "__main__":
raise SystemExit(main())