story: DGR-041 Register native Shard capabilities without redesigning Meshnet
This commit is contained in:
@@ -322,6 +322,49 @@ class BackendIdentity:
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ExecutionCapacity:
|
||||
"""Backend-neutral limits reserved for one registered capability.
|
||||
|
||||
The optional shape preserves existing Transformers reports unchanged while
|
||||
allowing a native Shard to state its measured/admitted resource envelope.
|
||||
"""
|
||||
|
||||
memory_capacity_bytes: int | None = None
|
||||
kv_capacity_tokens: int | None = None
|
||||
max_concurrent_sessions: int | None = None
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
for name in (
|
||||
"memory_capacity_bytes",
|
||||
"kv_capacity_tokens",
|
||||
"max_concurrent_sessions",
|
||||
):
|
||||
value = getattr(self, name)
|
||||
if value is not None:
|
||||
_require_int(value, f"capacity.{name}", 1)
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
"memory_capacity_bytes": self.memory_capacity_bytes,
|
||||
"kv_capacity_tokens": self.kv_capacity_tokens,
|
||||
"max_concurrent_sessions": self.max_concurrent_sessions,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: Any) -> ExecutionCapacity:
|
||||
doc = _as_mapping(data, "capacity")
|
||||
values: dict[str, int | None] = {}
|
||||
for name in (
|
||||
"memory_capacity_bytes",
|
||||
"kv_capacity_tokens",
|
||||
"max_concurrent_sessions",
|
||||
):
|
||||
value = doc.get(name)
|
||||
values[name] = None if value is None else _require_int(value, f"capacity.{name}", 1)
|
||||
return cls(**values)
|
||||
|
||||
|
||||
def _as_mapping(data: Any, field_name: str) -> Mapping[str, Any]:
|
||||
if not isinstance(data, Mapping):
|
||||
raise CapabilityReportError(
|
||||
@@ -353,6 +396,7 @@ class CapabilityReport:
|
||||
diagnostics: tuple[str, ...] = ()
|
||||
schema_version: int = CAPABILITY_SCHEMA_VERSION
|
||||
identity: ShardIdentity | None = None
|
||||
capacity: ExecutionCapacity | None = None
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
if self.status not in VALID_STATUSES:
|
||||
@@ -410,6 +454,8 @@ class CapabilityReport:
|
||||
}
|
||||
if self.identity is not None:
|
||||
doc["identity"] = self.identity.to_dict()
|
||||
if self.capacity is not None:
|
||||
doc["capacity"] = self.capacity.to_dict()
|
||||
return doc
|
||||
|
||||
def to_json(self, indent: int | None = None) -> str:
|
||||
@@ -451,6 +497,9 @@ class CapabilityReport:
|
||||
identity=(
|
||||
None if raw_identity is None else ShardIdentity.from_dict(raw_identity)
|
||||
),
|
||||
capacity=(
|
||||
None if doc.get("capacity") is None else ExecutionCapacity.from_dict(doc["capacity"])
|
||||
),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@@ -486,6 +535,7 @@ def build_capability_report(
|
||||
validated_at: float | None = None,
|
||||
environ: Mapping[str, str] | None = None,
|
||||
identity: ShardIdentity | None = None,
|
||||
capacity: ExecutionCapacity | None = None,
|
||||
) -> CapabilityReport:
|
||||
"""Assemble a report from flat validation results.
|
||||
|
||||
@@ -518,4 +568,5 @@ def build_capability_report(
|
||||
duration_ms=duration_ms,
|
||||
diagnostics=sanitize_diagnostics(diagnostics, environ),
|
||||
identity=identity,
|
||||
capacity=capacity,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user