digitalkin 0.3.1.dev1__py3-none-any.whl → 0.3.2a2__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.
- base_server/server_async_insecure.py +6 -5
- base_server/server_async_secure.py +6 -5
- base_server/server_sync_insecure.py +5 -4
- base_server/server_sync_secure.py +5 -4
- digitalkin/__version__.py +1 -1
- digitalkin/core/job_manager/base_job_manager.py +1 -1
- digitalkin/core/job_manager/single_job_manager.py +78 -36
- digitalkin/core/job_manager/taskiq_broker.py +8 -7
- digitalkin/core/job_manager/taskiq_job_manager.py +9 -5
- digitalkin/core/task_manager/base_task_manager.py +3 -1
- digitalkin/core/task_manager/surrealdb_repository.py +13 -7
- digitalkin/core/task_manager/task_executor.py +27 -10
- digitalkin/core/task_manager/task_session.py +133 -101
- digitalkin/grpc_servers/module_server.py +95 -171
- digitalkin/grpc_servers/module_servicer.py +133 -27
- digitalkin/grpc_servers/utils/grpc_client_wrapper.py +36 -10
- digitalkin/grpc_servers/utils/utility_schema_extender.py +106 -0
- digitalkin/models/__init__.py +1 -1
- digitalkin/models/core/job_manager_models.py +0 -8
- digitalkin/models/core/task_monitor.py +23 -1
- digitalkin/models/grpc_servers/models.py +95 -8
- digitalkin/models/module/__init__.py +26 -13
- digitalkin/models/module/base_types.py +61 -0
- digitalkin/models/module/module_context.py +279 -13
- digitalkin/models/module/module_types.py +29 -109
- digitalkin/models/module/setup_types.py +547 -0
- digitalkin/models/module/tool_cache.py +230 -0
- digitalkin/models/module/tool_reference.py +160 -0
- digitalkin/models/module/utility.py +167 -0
- digitalkin/models/services/cost.py +22 -1
- digitalkin/models/services/registry.py +77 -0
- digitalkin/modules/__init__.py +5 -1
- digitalkin/modules/_base_module.py +253 -90
- digitalkin/modules/archetype_module.py +6 -1
- digitalkin/modules/tool_module.py +6 -1
- digitalkin/modules/triggers/__init__.py +8 -0
- digitalkin/modules/triggers/healthcheck_ping_trigger.py +45 -0
- digitalkin/modules/triggers/healthcheck_services_trigger.py +63 -0
- digitalkin/modules/triggers/healthcheck_status_trigger.py +52 -0
- digitalkin/services/__init__.py +4 -0
- digitalkin/services/communication/__init__.py +7 -0
- digitalkin/services/communication/communication_strategy.py +87 -0
- digitalkin/services/communication/default_communication.py +104 -0
- digitalkin/services/communication/grpc_communication.py +264 -0
- digitalkin/services/cost/cost_strategy.py +36 -14
- digitalkin/services/cost/default_cost.py +61 -1
- digitalkin/services/cost/grpc_cost.py +98 -2
- digitalkin/services/filesystem/grpc_filesystem.py +9 -2
- digitalkin/services/registry/__init__.py +22 -1
- digitalkin/services/registry/default_registry.py +156 -4
- digitalkin/services/registry/exceptions.py +47 -0
- digitalkin/services/registry/grpc_registry.py +382 -0
- digitalkin/services/registry/registry_models.py +15 -0
- digitalkin/services/registry/registry_strategy.py +106 -4
- digitalkin/services/services_config.py +25 -3
- digitalkin/services/services_models.py +5 -1
- digitalkin/services/setup/default_setup.py +1 -1
- digitalkin/services/setup/grpc_setup.py +1 -1
- digitalkin/services/storage/grpc_storage.py +1 -1
- digitalkin/services/user_profile/__init__.py +11 -0
- digitalkin/services/user_profile/grpc_user_profile.py +2 -2
- digitalkin/services/user_profile/user_profile_strategy.py +0 -15
- digitalkin/utils/__init__.py +40 -0
- digitalkin/utils/conditional_schema.py +260 -0
- digitalkin/utils/dynamic_schema.py +487 -0
- digitalkin/utils/schema_splitter.py +290 -0
- {digitalkin-0.3.1.dev1.dist-info → digitalkin-0.3.2a2.dist-info}/METADATA +13 -13
- digitalkin-0.3.2a2.dist-info/RECORD +144 -0
- {digitalkin-0.3.1.dev1.dist-info → digitalkin-0.3.2a2.dist-info}/WHEEL +1 -1
- {digitalkin-0.3.1.dev1.dist-info → digitalkin-0.3.2a2.dist-info}/top_level.txt +1 -0
- modules/archetype_with_tools_module.py +232 -0
- modules/cpu_intensive_module.py +1 -1
- modules/dynamic_setup_module.py +338 -0
- modules/minimal_llm_module.py +1 -1
- modules/text_transform_module.py +1 -1
- monitoring/digitalkin_observability/__init__.py +46 -0
- monitoring/digitalkin_observability/http_server.py +150 -0
- monitoring/digitalkin_observability/interceptors.py +176 -0
- monitoring/digitalkin_observability/metrics.py +201 -0
- monitoring/digitalkin_observability/prometheus.py +137 -0
- monitoring/tests/test_metrics.py +172 -0
- services/filesystem_module.py +7 -5
- services/storage_module.py +4 -2
- digitalkin/grpc_servers/registry_server.py +0 -65
- digitalkin/grpc_servers/registry_servicer.py +0 -456
- digitalkin-0.3.1.dev1.dist-info/RECORD +0 -117
- {digitalkin-0.3.1.dev1.dist-info → digitalkin-0.3.2a2.dist-info}/licenses/LICENSE +0 -0
|
@@ -14,9 +14,9 @@ class GrpcClientWrapper:
|
|
|
14
14
|
"""gRPC client shared by the different services."""
|
|
15
15
|
|
|
16
16
|
stub: Any
|
|
17
|
+
_channel: grpc.Channel | None = None
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
def _init_channel(config: ClientConfig) -> grpc.Channel:
|
|
19
|
+
def _init_channel(self, config: ClientConfig) -> grpc.Channel:
|
|
20
20
|
"""Create an appropriate channel to the registry server.
|
|
21
21
|
|
|
22
22
|
Returns:
|
|
@@ -43,9 +43,19 @@ class GrpcClientWrapper:
|
|
|
43
43
|
private_key=private_key,
|
|
44
44
|
)
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
channel = grpc.secure_channel(config.address, channel_credentials, options=config.grpc_options)
|
|
47
|
+
self._channel = channel
|
|
48
|
+
return channel
|
|
47
49
|
# Insecure channel
|
|
48
|
-
|
|
50
|
+
channel = grpc.insecure_channel(config.address, options=config.grpc_options)
|
|
51
|
+
self._channel = channel
|
|
52
|
+
return channel
|
|
53
|
+
|
|
54
|
+
def close_channel(self) -> None:
|
|
55
|
+
"""Close the gRPC channel if it exists."""
|
|
56
|
+
if self._channel is not None:
|
|
57
|
+
self._channel.close()
|
|
58
|
+
self._channel = None
|
|
49
59
|
|
|
50
60
|
def exec_grpc_query(self, query_endpoint: str, request: Any) -> Any: # noqa: ANN401
|
|
51
61
|
"""Execute a gRPC query with from the query's rpc endpoint name.
|
|
@@ -58,15 +68,31 @@ class GrpcClientWrapper:
|
|
|
58
68
|
corresponding gRPC reponse.
|
|
59
69
|
|
|
60
70
|
Raises:
|
|
61
|
-
ServerError: gRPC error catching
|
|
71
|
+
ServerError: gRPC error catching with status code and details
|
|
62
72
|
"""
|
|
73
|
+
service_name = getattr(self, "service_name", "unknown")
|
|
63
74
|
try:
|
|
64
|
-
|
|
65
|
-
|
|
75
|
+
logger.debug(
|
|
76
|
+
"Sending gRPC request to %s",
|
|
77
|
+
query_endpoint,
|
|
78
|
+
extra={"request": str(request), "service": service_name},
|
|
79
|
+
)
|
|
66
80
|
response = getattr(self.stub, query_endpoint)(request)
|
|
67
|
-
logger.debug(
|
|
81
|
+
logger.debug(
|
|
82
|
+
"Received gRPC response from %s",
|
|
83
|
+
query_endpoint,
|
|
84
|
+
extra={"response": str(response), "service": service_name},
|
|
85
|
+
)
|
|
68
86
|
except grpc.RpcError as e:
|
|
69
|
-
|
|
70
|
-
|
|
87
|
+
status_code = e.code().name if hasattr(e, "code") else "UNKNOWN"
|
|
88
|
+
details = e.details() if hasattr(e, "details") else str(e)
|
|
89
|
+
msg = f"[{status_code}] {details}"
|
|
90
|
+
logger.error(
|
|
91
|
+
"gRPC %s failed: %s",
|
|
92
|
+
query_endpoint,
|
|
93
|
+
msg,
|
|
94
|
+
extra={"service": service_name},
|
|
95
|
+
)
|
|
96
|
+
raise ServerError(msg) from e
|
|
71
97
|
else:
|
|
72
98
|
return response
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""Utility schema extender for gRPC API responses.
|
|
2
|
+
|
|
3
|
+
This module extends module schemas with SDK utility protocols for API responses.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import types
|
|
7
|
+
from typing import Annotated, Union, get_args, get_origin
|
|
8
|
+
|
|
9
|
+
from pydantic import Field, create_model
|
|
10
|
+
|
|
11
|
+
from digitalkin.models.module.module_types import DataModel
|
|
12
|
+
from digitalkin.models.module.utility import (
|
|
13
|
+
EndOfStreamOutput,
|
|
14
|
+
HealthcheckPingInput,
|
|
15
|
+
HealthcheckPingOutput,
|
|
16
|
+
HealthcheckServicesInput,
|
|
17
|
+
HealthcheckServicesOutput,
|
|
18
|
+
HealthcheckStatusInput,
|
|
19
|
+
HealthcheckStatusOutput,
|
|
20
|
+
)
|
|
21
|
+
from digitalkin.models.services.cost import CostLimit
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class UtilitySchemaExtender:
|
|
25
|
+
"""Extends module schemas with SDK utility protocols for API responses.
|
|
26
|
+
|
|
27
|
+
This class provides methods to create extended Pydantic models that include
|
|
28
|
+
both user-defined protocols and SDK utility protocols in their schemas.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
_output_protocols = (
|
|
32
|
+
EndOfStreamOutput,
|
|
33
|
+
HealthcheckPingOutput,
|
|
34
|
+
HealthcheckServicesOutput,
|
|
35
|
+
HealthcheckStatusOutput,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
_input_protocols = (
|
|
39
|
+
HealthcheckPingInput,
|
|
40
|
+
HealthcheckServicesInput,
|
|
41
|
+
HealthcheckStatusInput,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
@classmethod
|
|
45
|
+
def _extract_union_types(cls, annotation: type) -> tuple:
|
|
46
|
+
"""Extract individual types from a Union or Annotated[Union, ...] annotation.
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
A tuple of individual types contained in the Union.
|
|
50
|
+
"""
|
|
51
|
+
if get_origin(annotation) is Annotated:
|
|
52
|
+
inner_args = get_args(annotation)
|
|
53
|
+
if inner_args:
|
|
54
|
+
return cls._extract_union_types(inner_args[0])
|
|
55
|
+
if get_origin(annotation) is Union or isinstance(annotation, types.UnionType):
|
|
56
|
+
return get_args(annotation)
|
|
57
|
+
return (annotation,)
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def create_extended_output_model(cls, base_model: type[DataModel]) -> type[DataModel]:
|
|
61
|
+
"""Create an extended output model that includes utility output protocols.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
base_model: The module's output_format class (a DataModel subclass).
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
A new DataModel subclass with root typed as Union[original_types, utility_types].
|
|
68
|
+
"""
|
|
69
|
+
original_annotation = base_model.model_fields["root"].annotation
|
|
70
|
+
original_types = cls._extract_union_types(original_annotation)
|
|
71
|
+
extended_types = (*original_types, *cls._output_protocols)
|
|
72
|
+
union_type = Union[extended_types] # type: ignore[valid-type] # noqa: UP007
|
|
73
|
+
extended_root = Annotated[union_type, Field(discriminator="protocol")] # type: ignore[valid-type]
|
|
74
|
+
return create_model(
|
|
75
|
+
f"{base_model.__name__}Utilities",
|
|
76
|
+
__base__=DataModel,
|
|
77
|
+
root=(extended_root, ...),
|
|
78
|
+
annotations=(dict[str, str], Field(default={})),
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
@classmethod
|
|
82
|
+
def create_extended_input_model(cls, base_model: type[DataModel]) -> type[DataModel]:
|
|
83
|
+
"""Create an extended input model that includes utility input protocols.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
base_model: The module's input_format class (a DataModel subclass).
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
A new DataModel subclass with root typed as Union[original_types, utility_types],
|
|
90
|
+
and includes cost_limits field for cost control.
|
|
91
|
+
"""
|
|
92
|
+
original_annotation = base_model.model_fields["root"].annotation
|
|
93
|
+
original_types = cls._extract_union_types(original_annotation)
|
|
94
|
+
extended_types = (*original_types, *cls._input_protocols)
|
|
95
|
+
union_type = Union[extended_types] # type: ignore[valid-type] # noqa: UP007
|
|
96
|
+
extended_root = Annotated[union_type, Field(discriminator="protocol")] # type: ignore[valid-type]
|
|
97
|
+
return create_model(
|
|
98
|
+
f"{base_model.__name__}Utilities",
|
|
99
|
+
__base__=DataModel,
|
|
100
|
+
root=(extended_root, ...),
|
|
101
|
+
annotations=(dict[str, str], Field(default={})),
|
|
102
|
+
cost_limits=(
|
|
103
|
+
list[CostLimit] | None,
|
|
104
|
+
Field(default=None, description="Optional cost limits for this invocation"),
|
|
105
|
+
),
|
|
106
|
+
)
|
digitalkin/models/__init__.py
CHANGED
|
@@ -2,17 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
from enum import Enum
|
|
4
4
|
|
|
5
|
-
from pydantic import BaseModel
|
|
6
|
-
|
|
7
5
|
from digitalkin.core.job_manager.base_job_manager import BaseJobManager
|
|
8
6
|
|
|
9
7
|
|
|
10
|
-
class StreamCodeModel(BaseModel):
|
|
11
|
-
"""Typed error/code model."""
|
|
12
|
-
|
|
13
|
-
code: str
|
|
14
|
-
|
|
15
|
-
|
|
16
8
|
class JobManagerMode(Enum):
|
|
17
9
|
"""Job manager mode."""
|
|
18
10
|
|
|
@@ -18,7 +18,10 @@ class TaskStatus(Enum):
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
class CancellationReason(Enum):
|
|
21
|
-
"""Reason for task
|
|
21
|
+
"""Reason for task termination - helps distinguish normal completion, cleanup, and real cancellation."""
|
|
22
|
+
|
|
23
|
+
# Normal completion
|
|
24
|
+
COMPLETED = "completed" # Task finished successfully
|
|
22
25
|
|
|
23
26
|
# Cleanup cancellations (not errors)
|
|
24
27
|
SUCCESS_CLEANUP = "success_cleanup" # Main task completed, cleaning up helper tasks
|
|
@@ -55,10 +58,27 @@ class SignalMessage(BaseModel):
|
|
|
55
58
|
|
|
56
59
|
task_id: str = Field(..., description="Unique identifier for the task")
|
|
57
60
|
mission_id: str = Field(..., description="Identifier for the mission")
|
|
61
|
+
setup_id: str = Field(default="", description="Identifier for the setup")
|
|
62
|
+
setup_version_id: str = Field(default="", description="Identifier for the setup version")
|
|
58
63
|
status: TaskStatus = Field(..., description="Current status of the task")
|
|
59
64
|
action: SignalType = Field(..., description="Type of signal action")
|
|
60
65
|
timestamp: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
|
61
66
|
payload: dict[str, Any] = Field(default={}, description="Optional payload for the signal")
|
|
67
|
+
|
|
68
|
+
# Enhanced logging fields
|
|
69
|
+
cancellation_reason: CancellationReason | None = Field(
|
|
70
|
+
default=None,
|
|
71
|
+
description="Reason for cancellation if status is CANCELLED",
|
|
72
|
+
)
|
|
73
|
+
error_message: str | None = Field(
|
|
74
|
+
default=None,
|
|
75
|
+
description="Human-readable error message if task failed",
|
|
76
|
+
)
|
|
77
|
+
exception_traceback: str | None = Field(
|
|
78
|
+
default=None,
|
|
79
|
+
description="Full traceback if task failed with exception",
|
|
80
|
+
)
|
|
81
|
+
|
|
62
82
|
model_config = {"use_enum_values": True}
|
|
63
83
|
|
|
64
84
|
|
|
@@ -67,4 +87,6 @@ class HeartbeatMessage(BaseModel):
|
|
|
67
87
|
|
|
68
88
|
task_id: str = Field(..., description="Unique identifier for the task")
|
|
69
89
|
mission_id: str = Field(..., description="Identifier for the mission")
|
|
90
|
+
setup_id: str = Field(default="", description="Identifier for the setup")
|
|
91
|
+
setup_version_id: str = Field(default="", description="Identifier for the setup version")
|
|
70
92
|
timestamp: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
|
@@ -65,6 +65,42 @@ class ServerCredentials(BaseModel):
|
|
|
65
65
|
return v
|
|
66
66
|
|
|
67
67
|
|
|
68
|
+
class RetryPolicy(BaseModel):
|
|
69
|
+
"""gRPC retry policy configuration for resilient connections.
|
|
70
|
+
|
|
71
|
+
Attributes:
|
|
72
|
+
max_attempts: Maximum retry attempts including the original call
|
|
73
|
+
initial_backoff: Initial backoff duration (e.g., "0.1s")
|
|
74
|
+
max_backoff: Maximum backoff duration (e.g., "10s")
|
|
75
|
+
backoff_multiplier: Multiplier for exponential backoff
|
|
76
|
+
retryable_status_codes: gRPC status codes that trigger retry
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
max_attempts: int = Field(default=5, ge=1, le=10, description="Maximum retry attempts including the original call")
|
|
80
|
+
initial_backoff: str = Field(default="0.1s", description="Initial backoff duration (e.g., '0.1s')")
|
|
81
|
+
max_backoff: str = Field(default="10s", description="Maximum backoff duration (e.g., '10s')")
|
|
82
|
+
backoff_multiplier: float = Field(default=2.0, ge=1.0, description="Multiplier for exponential backoff")
|
|
83
|
+
retryable_status_codes: list[str] = Field(
|
|
84
|
+
default_factory=lambda: ["UNAVAILABLE", "RESOURCE_EXHAUSTED"],
|
|
85
|
+
description="gRPC status codes that trigger retry",
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
model_config = {"extra": "forbid", "frozen": True}
|
|
89
|
+
|
|
90
|
+
def to_service_config_json(self) -> str:
|
|
91
|
+
"""Serialize to gRPC service config JSON string.
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
JSON string for grpc.service_config channel option.
|
|
95
|
+
"""
|
|
96
|
+
codes = "[" + ",".join(f'"{c}"' for c in self.retryable_status_codes) + "]"
|
|
97
|
+
return (
|
|
98
|
+
f'{{"methodConfig":[{{"name":[{{}}],"retryPolicy":{{"maxAttempts":{self.max_attempts},'
|
|
99
|
+
f'"initialBackoff":"{self.initial_backoff}","maxBackoff":"{self.max_backoff}",'
|
|
100
|
+
f'"backoffMultiplier":{self.backoff_multiplier},"retryableStatusCodes":{codes}}}}}]}}'
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
68
104
|
class ClientCredentials(BaseModel):
|
|
69
105
|
"""Model for client credentials in secure mode.
|
|
70
106
|
|
|
@@ -170,15 +206,47 @@ class ClientConfig(ChannelConfig):
|
|
|
170
206
|
security: Security mode (secure/insecure)
|
|
171
207
|
credentials: Client credentials for secure mode
|
|
172
208
|
channel_options: Additional channel options
|
|
209
|
+
retry_policy: Retry policy for failed RPCs
|
|
173
210
|
"""
|
|
174
211
|
|
|
175
212
|
credentials: ClientCredentials | None = Field(None, description="Client credentials for secure mode")
|
|
213
|
+
retry_policy: RetryPolicy = Field(default_factory=lambda: RetryPolicy(), description="Retry policy for failed RPCs") # noqa: PLW0108
|
|
176
214
|
channel_options: list[tuple[str, Any]] = Field(
|
|
177
215
|
default_factory=lambda: [
|
|
178
|
-
("grpc.max_receive_message_length",
|
|
179
|
-
("grpc.max_send_message_length",
|
|
216
|
+
("grpc.max_receive_message_length", 100 * 1024 * 1024),
|
|
217
|
+
("grpc.max_send_message_length", 100 * 1024 * 1024),
|
|
218
|
+
# === DNS Re-resolution (Critical for Container Environments) ===
|
|
219
|
+
# Minimum milliseconds between DNS re-resolution attempts (500 ms)
|
|
220
|
+
# When connection fails, gRPC will re-query DNS after this interval
|
|
221
|
+
# Solves: Container restarts with new IPs causing "No route to host"
|
|
222
|
+
("grpc.dns_min_time_between_resolutions_ms", 500),
|
|
223
|
+
# Initial delay before first reconnection attempt (1 second)
|
|
224
|
+
("grpc.initial_reconnect_backoff_ms", 1000),
|
|
225
|
+
# Maximum delay between reconnection attempts (10 seconds)
|
|
226
|
+
# Prevents overwhelming the network during extended outages
|
|
227
|
+
("grpc.max_reconnect_backoff_ms", 10000),
|
|
228
|
+
# Minimum delay between reconnection attempts (500ms)
|
|
229
|
+
# Ensures rapid recovery for brief network glitches
|
|
230
|
+
("grpc.min_reconnect_backoff_ms", 500),
|
|
231
|
+
# === Keepalive Settings (Detect Dead Connections) ===
|
|
232
|
+
# Send keepalive ping every 60 seconds when connection is idle
|
|
233
|
+
# Proactively detects dead connections before RPC calls fail
|
|
234
|
+
("grpc.keepalive_time_ms", 60000),
|
|
235
|
+
# Wait 20 seconds for keepalive response before declaring connection dead
|
|
236
|
+
# Triggers reconnection (with DNS re-resolution) if pong not received
|
|
237
|
+
("grpc.keepalive_timeout_ms", 20000),
|
|
238
|
+
# Send keepalive pings even when no RPCs are in flight
|
|
239
|
+
# Essential for long-lived connections that may sit idle
|
|
240
|
+
("grpc.keepalive_permit_without_calls", True),
|
|
241
|
+
# Minimum interval between HTTP/2 pings (30 seconds)
|
|
242
|
+
# Must be >= server's grpc.http2.min_ping_interval_without_data_ms (10s)
|
|
243
|
+
("grpc.http2.min_time_between_pings_ms", 30000),
|
|
244
|
+
# === Retry Configuration ===
|
|
245
|
+
# Enable automatic retry for failed RPCs (1 = enabled)
|
|
246
|
+
# Works with retryable status codes: UNAVAILABLE, RESOURCE_EXHAUSTED
|
|
247
|
+
("grpc.enable_retries", 1),
|
|
180
248
|
],
|
|
181
|
-
description="
|
|
249
|
+
description="Resilient gRPC channel options with DNS re-resolution, keepalive, and retries",
|
|
182
250
|
)
|
|
183
251
|
|
|
184
252
|
@field_validator("credentials")
|
|
@@ -204,6 +272,15 @@ class ClientConfig(ChannelConfig):
|
|
|
204
272
|
raise ConfigurationError(msg)
|
|
205
273
|
return v
|
|
206
274
|
|
|
275
|
+
@property
|
|
276
|
+
def grpc_options(self) -> list[tuple[str, Any]]:
|
|
277
|
+
"""Get channel options with retry policy service config.
|
|
278
|
+
|
|
279
|
+
Returns:
|
|
280
|
+
Full list of gRPC channel options.
|
|
281
|
+
"""
|
|
282
|
+
return [*self.channel_options, ("grpc.service_config", self.retry_policy.to_service_config_json())]
|
|
283
|
+
|
|
207
284
|
|
|
208
285
|
class ServerConfig(ChannelConfig):
|
|
209
286
|
"""Base configuration for gRPC servers.
|
|
@@ -223,10 +300,18 @@ class ServerConfig(ChannelConfig):
|
|
|
223
300
|
credentials: ServerCredentials | None = Field(None, description="Server credentials for secure mode")
|
|
224
301
|
server_options: list[tuple[str, Any]] = Field(
|
|
225
302
|
default_factory=lambda: [
|
|
226
|
-
("grpc.max_receive_message_length",
|
|
227
|
-
("grpc.max_send_message_length",
|
|
303
|
+
("grpc.max_receive_message_length", 100 * 1024 * 1024),
|
|
304
|
+
("grpc.max_send_message_length", 100 * 1024 * 1024),
|
|
305
|
+
# === Keepalive Permission (Required for Client Keepalive) ===
|
|
306
|
+
# Allow clients to send keepalive pings without active RPCs
|
|
307
|
+
# Without this, server rejects client keepalives with GOAWAY
|
|
308
|
+
("grpc.keepalive_permit_without_calls", True),
|
|
309
|
+
# Minimum interval server allows between client pings (10 seconds)
|
|
310
|
+
# Prevents "too_many_pings" GOAWAY errors
|
|
311
|
+
# Must match or be less than client's http2.min_time_between_pings_ms
|
|
312
|
+
("grpc.http2.min_ping_interval_without_data_ms", 10000),
|
|
228
313
|
],
|
|
229
|
-
description="
|
|
314
|
+
description="gRPC server options with keepalive support",
|
|
230
315
|
)
|
|
231
316
|
enable_reflection: bool = Field(default=True, description="Enable reflection for the server")
|
|
232
317
|
enable_health_check: bool = Field(default=True, description="Enable health check service")
|
|
@@ -259,10 +344,12 @@ class ModuleServerConfig(ServerConfig):
|
|
|
259
344
|
"""Configuration for Module gRPC server.
|
|
260
345
|
|
|
261
346
|
Attributes:
|
|
262
|
-
|
|
347
|
+
advertise_host: Public hostname/IP sent to registry for discovery. Falls back to host if not set.
|
|
263
348
|
"""
|
|
264
349
|
|
|
265
|
-
|
|
350
|
+
advertise_host: str | None = Field(
|
|
351
|
+
None, description="Public hostname/IP sent to registry for discovery. Falls back to host if not set."
|
|
352
|
+
)
|
|
266
353
|
|
|
267
354
|
|
|
268
355
|
class RegistryServerConfig(ServerConfig):
|
|
@@ -1,28 +1,41 @@
|
|
|
1
1
|
"""This module contains the models for the modules."""
|
|
2
2
|
|
|
3
|
-
from digitalkin.models.module.module import Module, ModuleStatus
|
|
4
3
|
from digitalkin.models.module.module_context import ModuleContext
|
|
5
4
|
from digitalkin.models.module.module_types import (
|
|
6
5
|
DataModel,
|
|
7
6
|
DataTrigger,
|
|
8
|
-
DataTriggerT,
|
|
9
|
-
InputModelT,
|
|
10
|
-
OutputModelT,
|
|
11
|
-
SecretModelT,
|
|
12
7
|
SetupModel,
|
|
13
|
-
|
|
8
|
+
)
|
|
9
|
+
from digitalkin.models.module.tool_cache import (
|
|
10
|
+
ToolCache,
|
|
11
|
+
ToolDefinition,
|
|
12
|
+
ToolModuleInfo,
|
|
13
|
+
ToolParameter,
|
|
14
|
+
)
|
|
15
|
+
from digitalkin.models.module.tool_reference import (
|
|
16
|
+
ToolReference,
|
|
17
|
+
tool_reference_input,
|
|
18
|
+
)
|
|
19
|
+
from digitalkin.models.module.utility import (
|
|
20
|
+
EndOfStreamOutput,
|
|
21
|
+
ModuleStartInfoOutput,
|
|
22
|
+
UtilityProtocol,
|
|
23
|
+
UtilityRegistry,
|
|
14
24
|
)
|
|
15
25
|
|
|
16
26
|
__all__ = [
|
|
17
27
|
"DataModel",
|
|
18
28
|
"DataTrigger",
|
|
19
|
-
"
|
|
20
|
-
"InputModelT",
|
|
21
|
-
"Module",
|
|
29
|
+
"EndOfStreamOutput",
|
|
22
30
|
"ModuleContext",
|
|
23
|
-
"
|
|
24
|
-
"OutputModelT",
|
|
25
|
-
"SecretModelT",
|
|
31
|
+
"ModuleStartInfoOutput",
|
|
26
32
|
"SetupModel",
|
|
27
|
-
"
|
|
33
|
+
"ToolCache",
|
|
34
|
+
"ToolDefinition",
|
|
35
|
+
"ToolModuleInfo",
|
|
36
|
+
"ToolParameter",
|
|
37
|
+
"ToolReference",
|
|
38
|
+
"UtilityProtocol",
|
|
39
|
+
"UtilityRegistry",
|
|
40
|
+
"tool_reference_input",
|
|
28
41
|
]
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Base types for module models."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import datetime, timezone
|
|
6
|
+
from typing import TYPE_CHECKING, ClassVar, Generic, TypeVar
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel, Field
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from digitalkin.models.module.setup_types import SetupModel
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class DataTrigger(BaseModel):
|
|
15
|
+
"""Defines the root input/output model exposing the protocol.
|
|
16
|
+
|
|
17
|
+
The mandatory protocol is important to define the module beahvior following the user or agent input/output.
|
|
18
|
+
|
|
19
|
+
Example:
|
|
20
|
+
class MyInput(DataModel):
|
|
21
|
+
root: DataTrigger
|
|
22
|
+
user_define_data: Any
|
|
23
|
+
|
|
24
|
+
# Usage
|
|
25
|
+
my_input = MyInput(root=DataTrigger(protocol="message"))
|
|
26
|
+
print(my_input.root.protocol) # Output: message
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
protocol: ClassVar[str]
|
|
30
|
+
created_at: str = Field(
|
|
31
|
+
default_factory=lambda: datetime.now(tz=timezone.utc).isoformat(),
|
|
32
|
+
title="Created At",
|
|
33
|
+
description="Timestamp when the payload was created.",
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
DataTriggerT = TypeVar("DataTriggerT", bound=DataTrigger)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class DataModel(BaseModel, Generic[DataTriggerT]):
|
|
41
|
+
"""Base definition of input/output model showing mandatory root fields.
|
|
42
|
+
|
|
43
|
+
The Model define the Module Input/output, usually referring to multiple input/output type defined by an union.
|
|
44
|
+
|
|
45
|
+
Example:
|
|
46
|
+
class ModuleInput(DataModel):
|
|
47
|
+
root: FileInput | MessageInput
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
root: DataTriggerT
|
|
51
|
+
annotations: dict[str, str] = Field(
|
|
52
|
+
default={},
|
|
53
|
+
title="Annotations",
|
|
54
|
+
description="Additional metadata or annotations related to the output. ex {'role': 'user'}",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
InputModelT = TypeVar("InputModelT", bound=DataModel)
|
|
59
|
+
OutputModelT = TypeVar("OutputModelT", bound=DataModel)
|
|
60
|
+
SecretModelT = TypeVar("SecretModelT", bound=BaseModel)
|
|
61
|
+
SetupModelT = TypeVar("SetupModelT", bound="SetupModel")
|