build(agent): molt-y#23e5c8 iteration
This commit is contained in:
parent
16bebe4f8b
commit
ee199e4b67
|
|
@ -12,4 +12,5 @@ PEP 517 build flow using setuptools. A minimal test suite and a tiny package sca
|
||||||
Phase 0 MVP: Protocol Skeleton
|
Phase 0 MVP: Protocol Skeleton
|
||||||
- Introduced a lightweight protocol module (protocol.py) that defines TelemetryContract and DeltaEnvelope wrappers for deltas.
|
- Introduced a lightweight protocol module (protocol.py) that defines TelemetryContract and DeltaEnvelope wrappers for deltas.
|
||||||
- Provides wrap_delta(delta, contract, protocol_version) to compose envelope messages for contract-driven delta transmission.
|
- Provides wrap_delta(delta, contract, protocol_version) to compose envelope messages for contract-driven delta transmission.
|
||||||
- Exposes TelemetryContract, DeltaEnvelope, and wrap_delta via the package root for experimentation and future adapters.
|
- Exposes TelemetryContract, DeltaEnvelope, wrap_delta, and map_delta_to_catopt via the package root for experimentation and future adapters.
|
||||||
|
- New: catopt_bridge.py mapping to a minimal CatOpt-like representation with map_delta_to_catopt.
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ This file exists to satisfy packaging/build in the MVP.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .protocol import TelemetryContract, DeltaEnvelope, wrap_delta
|
from .protocol import TelemetryContract, DeltaEnvelope, wrap_delta
|
||||||
|
from .catopt_bridge import map_delta_to_catopt
|
||||||
|
|
||||||
__all__ = ["__version__", "TelemetryContract", "DeltaEnvelope", "wrap_delta"]
|
__all__ = ["__version__", "TelemetryContract", "DeltaEnvelope", "wrap_delta", "map_delta_to_catopt"]
|
||||||
__version__ = "0.1.0"
|
__version__ = "0.1.0"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
"""Minimal CatOpt bridge for PulseMesh primitives.
|
||||||
|
|
||||||
|
This module provides a tiny, isolated mapping from PulseMesh DeltaEnvelope
|
||||||
|
objects into a canonical, CatOpt-inspired representation. It is intentionally
|
||||||
|
lightweight and pluggable to keep MVP scope small while enabling cross-domain
|
||||||
|
interoperability discussions with adapters and contracts.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Dict, Any
|
||||||
|
|
||||||
|
from .protocol import DeltaEnvelope
|
||||||
|
|
||||||
|
|
||||||
|
def map_delta_to_catopt(delta_env: DeltaEnvelope) -> Dict[str, Any]:
|
||||||
|
"""Map a PulseMesh DeltaEnvelope into a minimal CatOpt-like structure.
|
||||||
|
|
||||||
|
The goal here is not to implement a full CatOpt runtime, but to provide a
|
||||||
|
deterministic, testable representation that can serve as a contract between
|
||||||
|
PulseMesh primitives and adapters.
|
||||||
|
|
||||||
|
Returns a dictionary with a simple schema:
|
||||||
|
{
|
||||||
|
"Object": {"type": "TelemetryContext", "contract": <contract dict>},
|
||||||
|
"Morphism": {"type": "AnomalySignalChannel", "delta": <delta dict>},
|
||||||
|
"PlanDelta": <delta dict>,
|
||||||
|
"Metadata": {"protocol_version": ..., "timestamp": ...}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Serialize core payloads to dictionaries for a stable, transport-friendly shape
|
||||||
|
contract = None
|
||||||
|
if hasattr(delta_env, "contract") and delta_env.contract is not None:
|
||||||
|
c = delta_env.contract
|
||||||
|
contract = {
|
||||||
|
"contract_id": getattr(c, "contract_id", None),
|
||||||
|
"device_type": getattr(c, "device_type", None),
|
||||||
|
"metrics": getattr(c, "metrics", []),
|
||||||
|
}
|
||||||
|
result: Dict[str, Any] = {
|
||||||
|
"Object": {
|
||||||
|
"type": "TelemetryContext",
|
||||||
|
"contract_id": contract.get("contract_id") if contract else None,
|
||||||
|
"device_type": contract.get("device_type") if contract else None,
|
||||||
|
"metrics": contract.get("metrics") if contract else [],
|
||||||
|
},
|
||||||
|
"Morphism": {
|
||||||
|
"type": "AnomalySignalChannel",
|
||||||
|
"delta": delta_env.delta.to_dict() if hasattr(delta_env, "delta") else {},
|
||||||
|
},
|
||||||
|
"PlanDelta": delta_env.delta.to_dict() if hasattr(delta_env, "delta") else {},
|
||||||
|
"Metadata": {
|
||||||
|
"protocol_version": getattr(delta_env, "protocol_version", "PulseMesh/0.1.0"),
|
||||||
|
"timestamp": delta_env.delta.timestamp if hasattr(delta_env, "delta") else None,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
from pulsemesh_open_telemetry_visualization_a.delta import Delta
|
||||||
|
from pulsemesh_open_telemetry_visualization_a.protocol import TelemetryContract
|
||||||
|
from pulsemesh_open_telemetry_visualization_a.protocol import DeltaEnvelope
|
||||||
|
from pulsemesh_open_telemetry_visualization_a.catopt_bridge import map_delta_to_catopt
|
||||||
|
|
||||||
|
|
||||||
|
def _sample_contract() -> TelemetryContract:
|
||||||
|
return TelemetryContract(
|
||||||
|
contract_id="test-contract-1",
|
||||||
|
device_type="test_device",
|
||||||
|
metrics=["telemetry.sample"],
|
||||||
|
units={"telemetry.sample": "unit"},
|
||||||
|
quality_flags=["ok"],
|
||||||
|
version=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_catopt_bridge_basic_mapping():
|
||||||
|
# Build a minimal delta
|
||||||
|
delta = Delta(delta_id="d1", timestamp=time.time(), items=[{"dummy": True}])
|
||||||
|
envelope = DeltaEnvelope(protocol_version="PulseMesh/0.1.0", contract=_sample_contract(), delta=delta)
|
||||||
|
|
||||||
|
catopt = map_delta_to_catopt(envelope)
|
||||||
|
|
||||||
|
# Ensure the top-level keys exist
|
||||||
|
assert isinstance(catopt, dict)
|
||||||
|
assert "Object" in catopt and "Morphism" in catopt and "PlanDelta" in catopt
|
||||||
|
|
||||||
|
# Validate some shapes inside
|
||||||
|
obj = catopt["Object"]
|
||||||
|
assert obj["type"] == "TelemetryContext"
|
||||||
|
assert obj["contract_id"] == envelope.contract.contract_id
|
||||||
|
|
||||||
|
morph = catopt["Morphism"]
|
||||||
|
assert morph["type"] == "AnomalySignalChannel"
|
||||||
|
assert isinstance(morph["delta"], dict)
|
||||||
Loading…
Reference in New Issue