IEngine
What it is
- Defines the core engine interface/container for:
- A set of shared services (
IEngine.Services) - A registry of loaded modules (
modules)
- A set of shared services (
- Provides a small wiring mechanism to let services reference each other when they implement a known protocol (
ServicesAware).
Public API
ServicesAware (Protocol)
set_services(self, services: IEngine.Services) -> None- Implement on a service to receive the engine’s
Servicescontainer.
- Implement on a service to receive the engine’s
IEngine
services: IEngine.Services(property)- Returns the engine service container.
modules: Dict[str, BaseModule](property)- Returns the module registry keyed by module name.
IEngine.Services
Container for optional engine services, with guarded accessors.
Constructor
Services(object_storage=None, triple_store=None, vector_store=None, secret=None, bus=None, kv=None)
Service accessors (raise AssertionError if missing)
kv -> KeyValueServiceobject_storage -> ObjectStorageServicetriple_store -> TripleStoreServicevector_store -> VectorStoreServicesecret -> Secretbus -> BusService
Other methods/properties
triple_store_available() -> bool- Returns
Trueif a triple store service was provided.
- Returns
all -> List[Union[...]]- Returns a list of all service instances (including
Noneentries) in a fixed order.
- Returns a list of all service instances (including
wire_services() -> None- For each non-
Noneservice inall, if it implementsServicesAware, callsservice.set_services(self).
- For each non-
Configuration/Dependencies
- Depends on service types from
naas_abi_core.services.*:ObjectStorageService,TripleStoreService,VectorStoreService,Secret,BusService,KeyValueService
BaseModuleis only imported for typing (TYPE_CHECKING) fromnaas_abi_core.module.Module.
Usage
from naas_abi_core.engine.IEngine import IEngine, ServicesAware
class MyService(ServicesAware):
def set_services(self, services: IEngine.Services) -> None:
# Can now access other services via `services`
if services.triple_store_available():
_ = services.triple_store
# Provide service instances as available in your environment
services = IEngine.Services(
object_storage=None,
triple_store=None,
vector_store=None,
secret=None,
bus=None,
kv=None,
)
# Wire cross-service references (no-op unless services implement ServicesAware)
services.wire_services()Caveats
- Accessing a missing service via its property (e.g.,
services.kv) raisesAssertionErrorwith a clear message. wire_services()only callsset_servicesfor services that are runtime-checkable instances ofServicesAware.