digitalkin 0.3.2.dev6__py3-none-any.whl → 0.3.2.dev8__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.
Files changed (27) hide show
  1. digitalkin/__version__.py +1 -1
  2. digitalkin/grpc_servers/module_servicer.py +0 -11
  3. digitalkin/grpc_servers/utils/utility_schema_extender.py +2 -1
  4. digitalkin/models/module/module_context.py +136 -23
  5. digitalkin/models/module/setup_types.py +168 -257
  6. digitalkin/models/module/tool_cache.py +27 -187
  7. digitalkin/models/module/tool_reference.py +42 -45
  8. digitalkin/models/services/registry.py +0 -7
  9. digitalkin/modules/_base_module.py +74 -52
  10. digitalkin/services/registry/__init__.py +1 -1
  11. digitalkin/services/registry/default_registry.py +1 -1
  12. digitalkin/services/registry/grpc_registry.py +1 -1
  13. digitalkin/services/registry/registry_models.py +1 -29
  14. digitalkin/services/registry/registry_strategy.py +1 -1
  15. {digitalkin-0.3.2.dev6.dist-info → digitalkin-0.3.2.dev8.dist-info}/METADATA +1 -1
  16. {digitalkin-0.3.2.dev6.dist-info → digitalkin-0.3.2.dev8.dist-info}/RECORD +26 -20
  17. {digitalkin-0.3.2.dev6.dist-info → digitalkin-0.3.2.dev8.dist-info}/top_level.txt +1 -0
  18. modules/archetype_with_tools_module.py +244 -0
  19. monitoring/digitalkin_observability/__init__.py +46 -0
  20. monitoring/digitalkin_observability/http_server.py +150 -0
  21. monitoring/digitalkin_observability/interceptors.py +176 -0
  22. monitoring/digitalkin_observability/metrics.py +201 -0
  23. monitoring/digitalkin_observability/prometheus.py +137 -0
  24. monitoring/tests/test_metrics.py +172 -0
  25. digitalkin/models/module/module_helpers.py +0 -189
  26. {digitalkin-0.3.2.dev6.dist-info → digitalkin-0.3.2.dev8.dist-info}/WHEEL +0 -0
  27. {digitalkin-0.3.2.dev6.dist-info → digitalkin-0.3.2.dev8.dist-info}/licenses/LICENSE +0 -0
@@ -1,189 +0,0 @@
1
- """Module helpers for inter-module communication."""
2
-
3
- from collections.abc import AsyncGenerator, Callable, Coroutine
4
- from types import SimpleNamespace
5
- from typing import TYPE_CHECKING, Any
6
-
7
- from digitalkin.logger import logger
8
-
9
- if TYPE_CHECKING:
10
- from digitalkin.models.module.module_context import ModuleContext
11
-
12
-
13
- class ModuleHelpers(SimpleNamespace):
14
- """Helpers for module-to-module communication.
15
-
16
- Extends SimpleNamespace to allow dynamic attribute assignment
17
- while providing built-in helper methods.
18
- """
19
-
20
- def __init__(self, context: "ModuleContext", **kwargs: dict[str, Any]) -> None:
21
- """Initialize helpers with context reference.
22
-
23
- Args:
24
- context: ModuleContext providing access to services.
25
- **kwargs: Additional attributes to set on the namespace.
26
- """
27
- super().__init__(**kwargs)
28
- self._context = context
29
-
30
- async def call_module_by_id(
31
- self,
32
- module_id: str,
33
- input_data: dict,
34
- setup_id: str,
35
- mission_id: str,
36
- callback: Callable[[dict], Coroutine[Any, Any, None]] | None = None,
37
- ) -> AsyncGenerator[dict, None]:
38
- """Call a module by ID, discovering address/port from registry.
39
-
40
- Args:
41
- module_id: Module identifier to look up in registry
42
- input_data: Input data as dictionary
43
- setup_id: Setup configuration ID
44
- mission_id: Mission context ID
45
- callback: Optional callback for each response
46
-
47
- Yields:
48
- Streaming responses from module as dictionaries
49
- """
50
- module_info = self._context.registry.discover_by_id(module_id)
51
-
52
- logger.debug(
53
- "Calling module by ID",
54
- extra={
55
- "module_id": module_id,
56
- "address": module_info.address,
57
- "port": module_info.port,
58
- },
59
- )
60
-
61
- async for response in self._context.communication.call_module(
62
- module_address=module_info.address,
63
- module_port=module_info.port,
64
- input_data=input_data,
65
- setup_id=setup_id,
66
- mission_id=mission_id,
67
- callback=callback,
68
- ):
69
- yield response
70
-
71
- async def get_module_schemas_by_id(
72
- self,
73
- module_id: str,
74
- *,
75
- llm_format: bool = False,
76
- ) -> dict[str, dict]:
77
- """Get module schemas by ID, discovering address/port from registry.
78
-
79
- Args:
80
- module_id: Module identifier to look up in registry
81
- llm_format: If True, return LLM-optimized schema format
82
-
83
- Returns:
84
- Dictionary containing schemas: {"input": ..., "output": ..., "setup": ..., "secret": ...}
85
- """
86
- module_info = self._context.registry.discover_by_id(module_id)
87
-
88
- logger.debug(
89
- "Getting module schemas by ID",
90
- extra={
91
- "module_id": module_id,
92
- "address": module_info.address,
93
- "port": module_info.port,
94
- },
95
- )
96
-
97
- return await self._context.communication.get_module_schemas(
98
- module_address=module_info.address,
99
- module_port=module_info.port,
100
- llm_format=llm_format,
101
- )
102
-
103
- async def create_openai_style_tool(self, module_id: str) -> dict[str, Any] | None:
104
- """Create OpenAI-style function calling schema for a tool.
105
-
106
- Uses tool cache (fast path) with registry fallback. Fetches the tool's
107
- input schema and wraps it in OpenAI function calling format.
108
-
109
- Args:
110
- module_id: Module ID to look up (checks cache first, then registry)
111
-
112
- Returns:
113
- OpenAI-style tool schema if found:
114
- {
115
- "type": "function",
116
- "function": {
117
- "name": "...",
118
- "description": "...",
119
- "parameters": {...} # Input JSON Schema
120
- }
121
- }
122
- None if tool not found.
123
- """
124
- module_info = self._context.tool_cache.check_and_get(module_id, self._context.registry)
125
- if not module_info:
126
- return None
127
-
128
- schemas = await self._context.communication.get_module_schemas(
129
- module_address=module_info.address,
130
- module_port=module_info.port,
131
- llm_format=True,
132
- )
133
-
134
- return {
135
- "type": "function",
136
- "function": {
137
- "name": module_info.name or module_info.module_id,
138
- "description": module_info.documentation or "",
139
- "parameters": schemas["input"],
140
- },
141
- }
142
-
143
- def create_tool_function(
144
- self,
145
- module_id: str,
146
- ) -> Callable[..., AsyncGenerator[dict, None]] | None:
147
- """Create async generator function for a tool.
148
-
149
- Returns an async generator that calls the remote tool module via gRPC
150
- and yields each response as it arrives until end_of_stream or gRPC ends.
151
-
152
- Args:
153
- module_id: Module ID to look up (checks cache first, then registry)
154
-
155
- Returns:
156
- Async generator function if tool found, None otherwise.
157
- The function accepts **kwargs matching the tool's input schema
158
- and yields dict responses.
159
- """
160
- module_info = self._context.tool_cache.check_and_get(module_id, self._context.registry)
161
- if not module_info:
162
- return None
163
-
164
- # Capture references for closure
165
- communication = self._context.communication
166
- session = self._context.session
167
- address = module_info.address
168
- port = module_info.port
169
-
170
- async def tool_function(**kwargs: Any) -> AsyncGenerator[dict, None]: # noqa: ANN401
171
- """Call remote tool module and yield responses.
172
-
173
- Yields:
174
- dict: Each response from the module until end_of_stream.
175
- """
176
- wrapped_input = {"root": kwargs}
177
- async for response in communication.call_module(
178
- module_address=address,
179
- module_port=port,
180
- input_data=wrapped_input,
181
- setup_id=session.setup_id,
182
- mission_id=session.mission_id,
183
- ):
184
- yield response
185
-
186
- tool_function.__name__ = module_info.name or module_info.module_id
187
- tool_function.__doc__ = module_info.documentation or ""
188
-
189
- return tool_function