nvs-runtime 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nvs_runtime/__init__.py +29 -0
- nvs_runtime/__version__.py +3 -0
- nvs_runtime/config/__init__.py +3 -0
- nvs_runtime/config/settings.py +26 -0
- nvs_runtime/core/__init__.py +6 -0
- nvs_runtime/core/clock.py +32 -0
- nvs_runtime/core/composition.py +92 -0
- nvs_runtime/core/errors.py +69 -0
- nvs_runtime/core/hext.py +43 -0
- nvs_runtime/core/models.py +151 -0
- nvs_runtime/core/protocols.py +77 -0
- nvs_runtime/core/runtime.py +373 -0
- nvs_runtime/events/__init__.py +4 -0
- nvs_runtime/events/bus.py +50 -0
- nvs_runtime/events/types.py +35 -0
- nvs_runtime/executors/__init__.py +2 -0
- nvs_runtime/governance/__init__.py +4 -0
- nvs_runtime/governance/engine.py +58 -0
- nvs_runtime/governance/quota.py +48 -0
- nvs_runtime/graph/__init__.py +3 -0
- nvs_runtime/graph/capability_graph.py +100 -0
- nvs_runtime/hidden_trajectory/__init__.py +62 -0
- nvs_runtime/hidden_trajectory/_gate_child.py +375 -0
- nvs_runtime/hidden_trajectory/adapter_loader.py +70 -0
- nvs_runtime/hidden_trajectory/canonical.py +22 -0
- nvs_runtime/hidden_trajectory/capture_archive.py +204 -0
- nvs_runtime/hidden_trajectory/capture_chain.py +319 -0
- nvs_runtime/hidden_trajectory/cli.py +765 -0
- nvs_runtime/hidden_trajectory/envelope.py +303 -0
- nvs_runtime/hidden_trajectory/formal_save.py +499 -0
- nvs_runtime/hidden_trajectory/formal_writer.py +590 -0
- nvs_runtime/hidden_trajectory/gate_client.py +460 -0
- nvs_runtime/hidden_trajectory/item_set.py +317 -0
- nvs_runtime/hidden_trajectory/k_measure.py +145 -0
- nvs_runtime/hidden_trajectory/model_catalog.py +56 -0
- nvs_runtime/hidden_trajectory/payload.py +382 -0
- nvs_runtime/hidden_trajectory/phase2/__init__.py +3 -0
- nvs_runtime/hidden_trajectory/phase2/evaluate.py +319 -0
- nvs_runtime/hidden_trajectory/phase2/geometry.py +80 -0
- nvs_runtime/hidden_trajectory/phase2/labels.py +72 -0
- nvs_runtime/hidden_trajectory/phase4/__init__.py +3 -0
- nvs_runtime/hidden_trajectory/phase4/normalize.py +171 -0
- nvs_runtime/hidden_trajectory/phase4/summary.py +270 -0
- nvs_runtime/hidden_trajectory/phase4b/__init__.py +3 -0
- nvs_runtime/hidden_trajectory/phase4b/load.py +46 -0
- nvs_runtime/hidden_trajectory/phase4b/metrics.py +96 -0
- nvs_runtime/hidden_trajectory/phase4b/scan.py +33 -0
- nvs_runtime/hidden_trajectory/record.py +334 -0
- nvs_runtime/hidden_trajectory/record_schema.py +781 -0
- nvs_runtime/hidden_trajectory/replay/__init__.py +6 -0
- nvs_runtime/hidden_trajectory/replay/risk_control.py +196 -0
- nvs_runtime/hidden_trajectory/rerun.py +302 -0
- nvs_runtime/hidden_trajectory/rsa/__init__.py +6 -0
- nvs_runtime/hidden_trajectory/rsa/analysis.py +248 -0
- nvs_runtime/hidden_trajectory/rsa/calibration.py +659 -0
- nvs_runtime/hidden_trajectory/rsa/compare.py +714 -0
- nvs_runtime/hidden_trajectory/rsa/readout.py +192 -0
- nvs_runtime/hidden_trajectory/run.py +362 -0
- nvs_runtime/hidden_trajectory/token_temporal.py +368 -0
- nvs_runtime/hidden_trajectory/window.py +344 -0
- nvs_runtime/integrations/__init__.py +4 -0
- nvs_runtime/integrations/hekb_formal.py +169 -0
- nvs_runtime/integrations/hekb_vnext.py +302 -0
- nvs_runtime/metrics/__init__.py +3 -0
- nvs_runtime/metrics/collector.py +63 -0
- nvs_runtime/observability/__init__.py +3 -0
- nvs_runtime/observability/store.py +44 -0
- nvs_runtime/planner/__init__.py +3 -0
- nvs_runtime/planner/planner.py +158 -0
- nvs_runtime/providers/__init__.py +19 -0
- nvs_runtime/providers/base.py +43 -0
- nvs_runtime/providers/edge.py +165 -0
- nvs_runtime/providers/grpc.py +58 -0
- nvs_runtime/providers/hekb.py +77 -0
- nvs_runtime/providers/http.py +59 -0
- nvs_runtime/providers/kernel.py +67 -0
- nvs_runtime/providers/local.py +88 -0
- nvs_runtime/providers/mcp.py +84 -0
- nvs_runtime/providers/registry.py +56 -0
- nvs_runtime/providers/replay.py +138 -0
- nvs_runtime/py.typed +0 -0
- nvs_runtime/security/__init__.py +4 -0
- nvs_runtime/security/cbac.py +106 -0
- nvs_runtime/security/signer.py +20 -0
- nvs_runtime/session/__init__.py +4 -0
- nvs_runtime/session/checkpoint.py +108 -0
- nvs_runtime/session/manager.py +149 -0
- nvs_runtime/transport/__init__.py +3 -0
- nvs_runtime/transport/memory.py +36 -0
- nvs_runtime-1.0.0.dist-info/METADATA +234 -0
- nvs_runtime-1.0.0.dist-info/RECORD +94 -0
- nvs_runtime-1.0.0.dist-info/WHEEL +4 -0
- nvs_runtime-1.0.0.dist-info/entry_points.txt +2 -0
- nvs_runtime-1.0.0.dist-info/licenses/LICENSE +190 -0
nvs_runtime/__init__.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""NVS Runtime — provider-agnostic execution substrate."""
|
|
2
|
+
|
|
3
|
+
from nvs_runtime.__version__ import __version__
|
|
4
|
+
from nvs_runtime.core.composition import build_runtime
|
|
5
|
+
from nvs_runtime.core.models import (
|
|
6
|
+
CheckpointRequest,
|
|
7
|
+
DiscoverQuery,
|
|
8
|
+
ExecutionPlan,
|
|
9
|
+
InvokeRequest,
|
|
10
|
+
InvokeResult,
|
|
11
|
+
ObserveQuery,
|
|
12
|
+
PlanRequest,
|
|
13
|
+
SessionRequest,
|
|
14
|
+
)
|
|
15
|
+
from nvs_runtime.core.runtime import NVSRuntime
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"NVSRuntime",
|
|
19
|
+
"build_runtime",
|
|
20
|
+
"__version__",
|
|
21
|
+
"DiscoverQuery",
|
|
22
|
+
"PlanRequest",
|
|
23
|
+
"InvokeRequest",
|
|
24
|
+
"InvokeResult",
|
|
25
|
+
"ObserveQuery",
|
|
26
|
+
"SessionRequest",
|
|
27
|
+
"CheckpointRequest",
|
|
28
|
+
"ExecutionPlan",
|
|
29
|
+
]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Runtime configuration — applied only at the composition root."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel, Field
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class RuntimeConfig(BaseModel):
|
|
11
|
+
"""Edge configuration for NVS Runtime."""
|
|
12
|
+
|
|
13
|
+
name: str = "nvs-runtime"
|
|
14
|
+
max_concurrent: int = 32
|
|
15
|
+
max_cost_per_tenant: int = 10_000
|
|
16
|
+
default_timeout_ms: int = 5_000
|
|
17
|
+
enable_kernel: bool = False
|
|
18
|
+
enable_hekb: bool = True
|
|
19
|
+
enable_mcp: bool = False
|
|
20
|
+
metadata: dict[str, Any] = Field(default_factory=dict)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def load_config(data: dict[str, Any] | None = None) -> RuntimeConfig:
|
|
24
|
+
if not data:
|
|
25
|
+
return RuntimeConfig()
|
|
26
|
+
return RuntimeConfig.model_validate(data)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Clock utilities for deterministic testing."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def system_clock_ns() -> int:
|
|
10
|
+
"""Wall-clock nanoseconds."""
|
|
11
|
+
return time.time_ns()
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ControllableClock:
|
|
15
|
+
"""Mutable clock for offline tests."""
|
|
16
|
+
|
|
17
|
+
def __init__(self, start_ns: int = 1_700_000_000_000_000_000) -> None:
|
|
18
|
+
self._now = start_ns
|
|
19
|
+
|
|
20
|
+
def __call__(self) -> int:
|
|
21
|
+
return self._now
|
|
22
|
+
|
|
23
|
+
def advance(self, ns: int) -> int:
|
|
24
|
+
self._now += ns
|
|
25
|
+
return self._now
|
|
26
|
+
|
|
27
|
+
def set(self, ns: int) -> None:
|
|
28
|
+
self._now = ns
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def elapsed_ms(start_ns: int, clock: Callable[[], int]) -> float:
|
|
32
|
+
return max(0.0, (clock() - start_ns) / 1_000_000.0)
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""DI composition root — no module singletons."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from nvs_runtime.config.settings import RuntimeConfig, load_config
|
|
9
|
+
from nvs_runtime.core.clock import system_clock_ns
|
|
10
|
+
from nvs_runtime.core.hext import MemoryObjectStore
|
|
11
|
+
from nvs_runtime.core.protocols import ObjectStore, Signer
|
|
12
|
+
from nvs_runtime.core.runtime import NVSRuntime
|
|
13
|
+
from nvs_runtime.events.bus import EventBus
|
|
14
|
+
from nvs_runtime.governance.engine import GovernanceEngine
|
|
15
|
+
from nvs_runtime.governance.quota import QuotaEngine
|
|
16
|
+
from nvs_runtime.graph.capability_graph import CapabilityGraph
|
|
17
|
+
from nvs_runtime.metrics.collector import MetricsCollector
|
|
18
|
+
from nvs_runtime.observability.store import ObservabilityStore
|
|
19
|
+
from nvs_runtime.planner.planner import Planner
|
|
20
|
+
from nvs_runtime.providers.hekb import HekbProvider
|
|
21
|
+
from nvs_runtime.providers.http import HttpProvider
|
|
22
|
+
from nvs_runtime.providers.kernel import KernelProvider
|
|
23
|
+
from nvs_runtime.providers.local import LocalProvider
|
|
24
|
+
from nvs_runtime.providers.mcp import McpProvider
|
|
25
|
+
from nvs_runtime.providers.registry import ProviderRegistry
|
|
26
|
+
from nvs_runtime.security.cbac import CBACEngine
|
|
27
|
+
from nvs_runtime.security.signer import HmacSigner
|
|
28
|
+
from nvs_runtime.session.checkpoint import CheckpointManager
|
|
29
|
+
from nvs_runtime.session.manager import SessionManager
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def build_runtime(
|
|
33
|
+
*,
|
|
34
|
+
config: RuntimeConfig | dict[str, Any] | None = None,
|
|
35
|
+
clock: Callable[[], int] | None = None,
|
|
36
|
+
signer: Signer | None = None,
|
|
37
|
+
store: ObjectStore | None = None,
|
|
38
|
+
register_defaults: bool = True,
|
|
39
|
+
) -> NVSRuntime:
|
|
40
|
+
"""Compose a fully wired NVSRuntime.
|
|
41
|
+
|
|
42
|
+
Deterministic by default: injectable clock, in-memory store, offline providers.
|
|
43
|
+
"""
|
|
44
|
+
cfg = (
|
|
45
|
+
config
|
|
46
|
+
if isinstance(config, RuntimeConfig)
|
|
47
|
+
else load_config(config if isinstance(config, dict) else None)
|
|
48
|
+
)
|
|
49
|
+
clock_fn = clock or system_clock_ns
|
|
50
|
+
signer_impl = signer or HmacSigner()
|
|
51
|
+
object_store = store or MemoryObjectStore()
|
|
52
|
+
|
|
53
|
+
registry = ProviderRegistry()
|
|
54
|
+
graph = CapabilityGraph()
|
|
55
|
+
events = EventBus(clock=clock_fn)
|
|
56
|
+
cbac = CBACEngine(signer=signer_impl, clock=clock_fn)
|
|
57
|
+
quota = QuotaEngine(
|
|
58
|
+
max_concurrent=cfg.max_concurrent,
|
|
59
|
+
max_cost_per_tenant=cfg.max_cost_per_tenant,
|
|
60
|
+
)
|
|
61
|
+
governance = GovernanceEngine(store=object_store, quota=quota)
|
|
62
|
+
planner = Planner(graph=graph, governance=governance, cbac=cbac)
|
|
63
|
+
sessions = SessionManager(clock=clock_fn)
|
|
64
|
+
checkpoints = CheckpointManager(store=object_store, clock=clock_fn)
|
|
65
|
+
metrics = MetricsCollector()
|
|
66
|
+
observability = ObservabilityStore()
|
|
67
|
+
|
|
68
|
+
runtime = NVSRuntime(
|
|
69
|
+
providers=registry,
|
|
70
|
+
graph=graph,
|
|
71
|
+
planner=planner,
|
|
72
|
+
sessions=sessions,
|
|
73
|
+
checkpoints=checkpoints,
|
|
74
|
+
governance=governance,
|
|
75
|
+
metrics_collector=metrics,
|
|
76
|
+
observability=observability,
|
|
77
|
+
events=events,
|
|
78
|
+
cbac=cbac,
|
|
79
|
+
clock=clock_fn,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
if register_defaults:
|
|
83
|
+
runtime.register_provider(LocalProvider())
|
|
84
|
+
runtime.register_provider(HttpProvider())
|
|
85
|
+
if cfg.enable_hekb:
|
|
86
|
+
runtime.register_provider(HekbProvider(store=object_store))
|
|
87
|
+
if cfg.enable_kernel:
|
|
88
|
+
runtime.register_provider(KernelProvider(available=False))
|
|
89
|
+
if cfg.enable_mcp:
|
|
90
|
+
runtime.register_provider(McpProvider())
|
|
91
|
+
|
|
92
|
+
return runtime
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Runtime error hierarchy."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class RuntimeError(Exception):
|
|
7
|
+
"""Base error for NVS Runtime."""
|
|
8
|
+
|
|
9
|
+
def __init__(self, message: str, *, code: str = "RUNTIME_ERROR") -> None:
|
|
10
|
+
super().__init__(message)
|
|
11
|
+
self.message = message
|
|
12
|
+
self.code = code
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ProviderError(RuntimeError):
|
|
16
|
+
"""Provider invocation or lifecycle failure."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, message: str, *, code: str = "PROVIDER_ERROR") -> None:
|
|
19
|
+
super().__init__(message, code=code)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ProviderNotFoundError(ProviderError):
|
|
23
|
+
def __init__(self, provider_id: str) -> None:
|
|
24
|
+
super().__init__(f"unknown provider: {provider_id}", code="PROVIDER_NOT_FOUND")
|
|
25
|
+
self.provider_id = provider_id
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class CapabilityNotFoundError(RuntimeError):
|
|
29
|
+
def __init__(self, capability_id: str) -> None:
|
|
30
|
+
super().__init__(
|
|
31
|
+
f"unknown capability: {capability_id}",
|
|
32
|
+
code="CAPABILITY_NOT_FOUND",
|
|
33
|
+
)
|
|
34
|
+
self.capability_id = capability_id
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class PlanError(RuntimeError):
|
|
38
|
+
def __init__(self, message: str, *, code: str = "PLAN_ERROR") -> None:
|
|
39
|
+
super().__init__(message, code=code)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class GovernanceError(RuntimeError):
|
|
43
|
+
def __init__(self, message: str, *, code: str = "GOVERNANCE_ERROR") -> None:
|
|
44
|
+
super().__init__(message, code=code)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class SessionError(RuntimeError):
|
|
48
|
+
def __init__(self, message: str, *, code: str = "SESSION_ERROR") -> None:
|
|
49
|
+
super().__init__(message, code=code)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class CheckpointError(RuntimeError):
|
|
53
|
+
def __init__(self, message: str, *, code: str = "CHECKPOINT_ERROR") -> None:
|
|
54
|
+
super().__init__(message, code=code)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class AuthorizationError(RuntimeError):
|
|
58
|
+
def __init__(self, message: str, *, code: str = "UNAUTHORIZED") -> None:
|
|
59
|
+
super().__init__(message, code=code)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class TransportError(RuntimeError):
|
|
63
|
+
def __init__(self, message: str, *, code: str = "TRANSPORT_ERROR") -> None:
|
|
64
|
+
super().__init__(message, code=code)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class ShutdownError(RuntimeError):
|
|
68
|
+
def __init__(self, message: str = "runtime is shut down") -> None:
|
|
69
|
+
super().__init__(message, code="SHUTDOWN")
|
nvs_runtime/core/hext.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""HEXT interface adapters — runtime never imports HEXT internals."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
from uuid import uuid4
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel, Field
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class HextObject(BaseModel):
|
|
12
|
+
"""Minimal Semantic Object conforming to the HEXT interface."""
|
|
13
|
+
|
|
14
|
+
object_id: str = Field(default_factory=lambda: f"hext_{uuid4().hex[:16]}")
|
|
15
|
+
object_type: str = "object"
|
|
16
|
+
payload: dict[str, Any] = Field(default_factory=dict)
|
|
17
|
+
labels: dict[str, str] = Field(default_factory=dict)
|
|
18
|
+
|
|
19
|
+
def to_dict(self) -> dict[str, Any]:
|
|
20
|
+
return self.model_dump(mode="json")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class MemoryObjectStore:
|
|
24
|
+
"""In-process ObjectStore for offline / deterministic operation."""
|
|
25
|
+
|
|
26
|
+
def __init__(self) -> None:
|
|
27
|
+
self._objects: dict[str, dict[str, Any]] = {}
|
|
28
|
+
|
|
29
|
+
def put_object(self, data: dict[str, Any], *, labels: dict[str, str] | None = None) -> str:
|
|
30
|
+
obj = HextObject(
|
|
31
|
+
object_type=str(data.get("type") or data.get("object_type") or "object"),
|
|
32
|
+
payload=dict(data),
|
|
33
|
+
labels=dict(labels or {}),
|
|
34
|
+
)
|
|
35
|
+
stored = obj.to_dict()
|
|
36
|
+
self._objects[obj.object_id] = stored
|
|
37
|
+
return obj.object_id
|
|
38
|
+
|
|
39
|
+
def get_object(self, object_id: str) -> dict[str, Any] | None:
|
|
40
|
+
return self._objects.get(object_id)
|
|
41
|
+
|
|
42
|
+
def list_ids(self) -> list[str]:
|
|
43
|
+
return list(self._objects.keys())
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"""Domain models for the stable Runtime API."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from enum import StrEnum
|
|
6
|
+
from typing import Any
|
|
7
|
+
from uuid import uuid4
|
|
8
|
+
|
|
9
|
+
from pydantic import BaseModel, Field
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Placement(StrEnum):
|
|
13
|
+
LOCAL = "local"
|
|
14
|
+
REMOTE = "remote"
|
|
15
|
+
HYBRID = "hybrid"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Capability(BaseModel):
|
|
19
|
+
"""A discoverable unit of work exposed by a provider."""
|
|
20
|
+
|
|
21
|
+
id: str
|
|
22
|
+
name: str
|
|
23
|
+
provider_id: str
|
|
24
|
+
input_type: str = "any"
|
|
25
|
+
output_type: str = "any"
|
|
26
|
+
tags: list[str] = Field(default_factory=list)
|
|
27
|
+
cost_units: int = 1
|
|
28
|
+
latency_ms: int = 1
|
|
29
|
+
metadata: dict[str, Any] = Field(default_factory=dict)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class DiscoverQuery(BaseModel):
|
|
33
|
+
provider_id: str | None = None
|
|
34
|
+
tag: str | None = None
|
|
35
|
+
input_type: str | None = None
|
|
36
|
+
output_type: str | None = None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class DiscoverResult(BaseModel):
|
|
40
|
+
capabilities: list[Capability] = Field(default_factory=list)
|
|
41
|
+
providers: list[dict[str, Any]] = Field(default_factory=list)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class PlanRequest(BaseModel):
|
|
45
|
+
goal: str
|
|
46
|
+
input_type: str = "any"
|
|
47
|
+
target_outputs: list[str] = Field(default_factory=list)
|
|
48
|
+
optimization: str = "LOW_LATENCY"
|
|
49
|
+
max_cost_units: int = 100
|
|
50
|
+
max_latency_ms: int = 200
|
|
51
|
+
allow_remote: bool = True
|
|
52
|
+
constraints: dict[str, Any] = Field(default_factory=dict)
|
|
53
|
+
token: str | None = None
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class PlanStep(BaseModel):
|
|
57
|
+
capability_id: str
|
|
58
|
+
provider_id: str
|
|
59
|
+
input_type: str
|
|
60
|
+
output_type: str
|
|
61
|
+
estimated_latency_ms: int = 1
|
|
62
|
+
estimated_cost_units: int = 1
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class ExecutionPlan(BaseModel):
|
|
66
|
+
plan_id: str = Field(default_factory=lambda: f"plan_{uuid4().hex[:12]}")
|
|
67
|
+
goal: str
|
|
68
|
+
executable: bool = True
|
|
69
|
+
steps: list[PlanStep] = Field(default_factory=list)
|
|
70
|
+
placement: Placement = Placement.LOCAL
|
|
71
|
+
estimated_latency_ms: int = 0
|
|
72
|
+
estimated_cost_units: int = 0
|
|
73
|
+
error_code: str | None = None
|
|
74
|
+
detail: str | None = None
|
|
75
|
+
metadata: dict[str, Any] = Field(default_factory=dict)
|
|
76
|
+
|
|
77
|
+
def to_dict(self) -> dict[str, Any]:
|
|
78
|
+
return self.model_dump(mode="json")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class InvokeRequest(BaseModel):
|
|
82
|
+
capability_id: str | None = None
|
|
83
|
+
provider_id: str | None = None
|
|
84
|
+
plan_id: str | None = None
|
|
85
|
+
session_id: str | None = None
|
|
86
|
+
payload: dict[str, Any] = Field(default_factory=dict)
|
|
87
|
+
token: str | None = None
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class InvokeResult(BaseModel):
|
|
91
|
+
ok: bool = True
|
|
92
|
+
capability_id: str | None = None
|
|
93
|
+
provider_id: str | None = None
|
|
94
|
+
session_id: str | None = None
|
|
95
|
+
plan_id: str | None = None
|
|
96
|
+
output: dict[str, Any] = Field(default_factory=dict)
|
|
97
|
+
error_code: str | None = None
|
|
98
|
+
detail: str | None = None
|
|
99
|
+
latency_ms: float = 0.0
|
|
100
|
+
|
|
101
|
+
def to_dict(self) -> dict[str, Any]:
|
|
102
|
+
return self.model_dump(mode="json")
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class ObserveQuery(BaseModel):
|
|
106
|
+
kind: str = "timeline" # timeline | topology | statistics | sessions
|
|
107
|
+
limit: int = 50
|
|
108
|
+
session_id: str | None = None
|
|
109
|
+
plan_id: str | None = None
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class ObserveResult(BaseModel):
|
|
113
|
+
kind: str
|
|
114
|
+
items: list[dict[str, Any]] = Field(default_factory=list)
|
|
115
|
+
statistics: dict[str, Any] = Field(default_factory=dict)
|
|
116
|
+
|
|
117
|
+
def to_dict(self) -> dict[str, Any]:
|
|
118
|
+
return self.model_dump(mode="json")
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class SessionAction(StrEnum):
|
|
122
|
+
CREATE = "create"
|
|
123
|
+
GET = "get"
|
|
124
|
+
LIST = "list"
|
|
125
|
+
START = "start"
|
|
126
|
+
PAUSE = "pause"
|
|
127
|
+
RESUME = "resume"
|
|
128
|
+
CANCEL = "cancel"
|
|
129
|
+
COMPLETE = "complete"
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class SessionRequest(BaseModel):
|
|
133
|
+
action: SessionAction = SessionAction.CREATE
|
|
134
|
+
session_id: str | None = None
|
|
135
|
+
plan_id: str | None = None
|
|
136
|
+
detail: dict[str, Any] = Field(default_factory=dict)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
class CheckpointAction(StrEnum):
|
|
140
|
+
SAVE = "save"
|
|
141
|
+
RESTORE = "restore"
|
|
142
|
+
LIST = "list"
|
|
143
|
+
GET = "get"
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class CheckpointRequest(BaseModel):
|
|
147
|
+
action: CheckpointAction = CheckpointAction.SAVE
|
|
148
|
+
session_id: str | None = None
|
|
149
|
+
checkpoint_id: str | None = None
|
|
150
|
+
label: str | None = None
|
|
151
|
+
state: dict[str, Any] = Field(default_factory=dict)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Core protocols — interfaces over inheritance."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Protocol, runtime_checkable
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@runtime_checkable
|
|
9
|
+
class SemanticObject(Protocol):
|
|
10
|
+
"""HEXT Semantic Object Standard — runtime depends only on this interface."""
|
|
11
|
+
|
|
12
|
+
@property
|
|
13
|
+
def object_id(self) -> str: ...
|
|
14
|
+
|
|
15
|
+
@property
|
|
16
|
+
def object_type(self) -> str: ...
|
|
17
|
+
|
|
18
|
+
def to_dict(self) -> dict[str, Any]: ...
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@runtime_checkable
|
|
22
|
+
class ObjectStore(Protocol):
|
|
23
|
+
"""Content-addressed object store (HEKB-shaped) — adapter boundary only."""
|
|
24
|
+
|
|
25
|
+
def put_object(self, data: dict[str, Any], *, labels: dict[str, str] | None = None) -> str: ...
|
|
26
|
+
|
|
27
|
+
def get_object(self, object_id: str) -> dict[str, Any] | None: ...
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@runtime_checkable
|
|
31
|
+
class Provider(Protocol):
|
|
32
|
+
"""Uniform provider contract. No provider is privileged."""
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def provider_id(self) -> str: ...
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def kind(self) -> str: ...
|
|
39
|
+
|
|
40
|
+
def discover(self) -> list[dict[str, Any]]: ...
|
|
41
|
+
|
|
42
|
+
def capabilities(self) -> list[dict[str, Any]]: ...
|
|
43
|
+
|
|
44
|
+
async def invoke(self, capability_id: str, payload: dict[str, Any]) -> dict[str, Any]: ...
|
|
45
|
+
|
|
46
|
+
async def health(self) -> dict[str, Any]: ...
|
|
47
|
+
|
|
48
|
+
async def shutdown(self) -> None: ...
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@runtime_checkable
|
|
52
|
+
class Transport(Protocol):
|
|
53
|
+
"""Swappable message transport."""
|
|
54
|
+
|
|
55
|
+
async def send(
|
|
56
|
+
self,
|
|
57
|
+
endpoint: str,
|
|
58
|
+
packet: dict[str, Any],
|
|
59
|
+
*,
|
|
60
|
+
timeout_ms: int = 5_000,
|
|
61
|
+
) -> dict[str, Any]: ...
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@runtime_checkable
|
|
65
|
+
class Clock(Protocol):
|
|
66
|
+
"""Injectable clock — nanoseconds since epoch for deterministic tests."""
|
|
67
|
+
|
|
68
|
+
def __call__(self) -> int: ...
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@runtime_checkable
|
|
72
|
+
class Signer(Protocol):
|
|
73
|
+
"""Capability token signer — HMAC for tests, Ed25519 for production."""
|
|
74
|
+
|
|
75
|
+
def sign(self, payload: bytes) -> bytes: ...
|
|
76
|
+
|
|
77
|
+
def verify(self, payload: bytes, signature: bytes) -> bool: ...
|