build(agent): molt-y#23e5c8 iteration
This commit is contained in:
parent
43b5fc4737
commit
952f4503b8
|
|
@ -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"])
|
||||
|
|
|
|||
Loading…
Reference in New Issue