From 952f4503b82c83190e0555956652c628d2f691ad Mon Sep 17 00:00:00 2001 From: agent-23e5c897f40fd19e Date: Thu, 16 Apr 2026 22:26:58 +0200 Subject: [PATCH] build(agent): molt-y#23e5c8 iteration --- gridverse/bridge_energia.py | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/gridverse/bridge_energia.py b/gridverse/bridge_energia.py index b9bef57..a195908 100644 --- a/gridverse/bridge_energia.py +++ b/gridverse/bridge_energia.py @@ -16,6 +16,12 @@ from __future__ import annotations from dataclasses import dataclass, field from typing import Any, Dict +# Lightweight import to avoid circular imports at module import time. +try: + from gridverse.registry import GraphContractRegistry +except Exception: # pragma: no cover + GraphContractRegistry = object # type: ignore + @dataclass class CanonicalBundle: """Canonical representation that adapters can consume/emit. @@ -82,3 +88,62 @@ def from_canonical(bundle: CanonicalBundle) -> Dict[str, Any]: __all__ = ["CanonicalBundle", "to_canonical", "from_canonical"] + + +def bootstrap_contracts(registry: "GraphContractRegistry") -> None: + """Register a minimal set of contract schemas into the provided registry. + + This function is intended as an MVP bootstrap helper so adapters can rely on + a versioned, conformance-checked contract namespace without requiring a + full deployment environment. It registers a LocalProblem, SharedVariables, + and PlanDelta contract skeletons that adapters can reference during + development and testing. + + Note: The input registry might be a thin in-process registry or a remote + service; this function only uses a simple interface: register_contract. If + GraphContractRegistry is not available at import time, this function is a no-op. + """ + # Be resilient to environments where a concrete registry class isn't wired up + # yet. If the registry exposes a simple 'register_contract' method, use it. + if not hasattr(registry, "register_contract"): + return + + # Example schema shapes. They are intentionally small and self-describing. + local_problem_schema = { + "name": "LocalProblem", + "version": "0.1.0", + "schema": { + "type": "object", + "properties": { + "site_id": {"type": "string"}, + "description": {"type": "string"}, + "variables": {"type": "object"}, + }, + "required": ["site_id", "description"], + }, + } + shared_variables_schema = { + "name": "SharedVariables", + "version": "0.1.0", + "schema": { + "type": "object", + "properties": { + "signals": {"type": "object"}, + }, + }, + } + plan_delta_schema = { + "name": "PlanDelta", + "version": "0.1.0", + "schema": { + "type": "object", + "properties": { + "delta_id": {"type": "string"}, + "changes": {"type": "object"}, + }, + }, + } + + registry.register_contract("LocalProblem", local_problem_schema["version"], local_problem_schema["schema"]) + registry.register_contract("SharedVariables", shared_variables_schema["version"], shared_variables_schema["schema"]) + registry.register_contract("PlanDelta", plan_delta_schema["version"], plan_delta_schema["schema"])