35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Dict
|
|
|
|
from .contracts import LocalProblem
|
|
|
|
|
|
def to_canonical(lp: LocalProblem) -> Dict[str, object]:
|
|
"""Map a LocalProblem into a tiny canonical representation.
|
|
|
|
This is a minimal, MVP-friendly bridge primitive that preserves
|
|
the essential fields needed for cross-domain orchestration:
|
|
- type: a string tag for the canonical object
|
|
- object_id: asset_id of the local problem
|
|
- data: the payload dictionary
|
|
"""
|
|
return {
|
|
"type": "LocalProblem",
|
|
"object_id": lp.asset_id,
|
|
"data": dict(lp.payload),
|
|
}
|
|
|
|
|
|
def from_canonical(data: Dict[str, object]) -> LocalProblem:
|
|
"""Inverse of to_canonical for LocalProblem objects.
|
|
|
|
Expects a dict produced by to_canonical or a compatible canonical form.
|
|
"""
|
|
asset_id = str(data.get("object_id"))
|
|
payload = data.get("data", {})
|
|
# Safety: ensure payload is a dict
|
|
if not isinstance(payload, dict):
|
|
payload = {"payload": payload}
|
|
return LocalProblem(asset_id=asset_id, payload=payload)
|