Coverage for src / lexigram / ai / relay / module.py: 100%
15 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-08 23:08 +0800
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-08 23:08 +0800
1"""Relay module for dependency injection."""
3from __future__ import annotations
5from typing import Any
7from lexigram.contracts.ai.relay.protocols import (
8 RelayConverterProtocol,
9 RelayRegistryProtocol,
10)
11from lexigram.di.module import DynamicModule, Module, module
13__all__ = ["RelayModule"]
16@module
17class RelayModule(Module):
18 """Relay protocol conversion engine module for Lexigram applications.
20 Provides the caller-owned relay registry and the public conversion
21 engine behind their contract protocols.
23 Usage::
25 from lexigram.ai.relay import RelayModule
27 @module(
28 imports=[RelayModule.configure()]
29 )
30 class AppModule(Module):
31 pass
32 """
34 @classmethod
35 def configure(cls) -> DynamicModule:
36 """Create a RelayModule with the built-in converter routes.
38 Returns:
39 A :class:`~lexigram.di.module.DynamicModule` descriptor.
40 """
41 from lexigram.ai.relay.di.provider import RelayProvider
43 return DynamicModule(
44 module=cls,
45 providers=[RelayProvider()],
46 exports=[
47 RelayConverterProtocol,
48 RelayRegistryProtocol,
49 ],
50 )
52 @classmethod
53 def stub(cls, config: Any = None) -> DynamicModule:
54 """Create a RelayModule suitable for unit and integration testing.
56 Uses the same in-memory registry and synchronous engine as
57 :meth:`configure`; no credentials or I/O are involved.
59 Args:
60 config: Optional test configuration override; the relay module
61 needs no configuration, so it is ignored.
63 Returns:
64 A :class:`~lexigram.di.module.DynamicModule` descriptor.
65 """
66 from lexigram.ai.relay.di.provider import RelayProvider
68 return DynamicModule(
69 module=cls,
70 providers=[RelayProvider()],
71 exports=[
72 RelayConverterProtocol,
73 RelayRegistryProtocol,
74 ],
75 )