Repository navigation
feat(OMN-1732): Runtime dependency injection for zero-code nodes #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jonahgabriel
merged 2 commits into
main
from
jonah/omn-1732-feat-runtime-dependency-injection-for-zero-code-nodes
Feb 4, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/omnibase_infra/models/runtime/model_resolved_dependencies.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| # Copyright (c) 2025 OmniNode Team | ||
| """Model for resolved protocol dependencies. | ||
|
|
||
| This module provides ModelResolvedDependencies, a container for protocol | ||
| instances resolved from the container service_registry at node creation time. | ||
|
|
||
| Part of OMN-1732: Runtime dependency injection for zero-code nodes. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from pydantic import BaseModel, ConfigDict, Field | ||
|
|
||
|
|
||
| class ModelResolvedDependencies(BaseModel): | ||
| """Container for resolved protocol dependencies. | ||
|
|
||
| Holds protocol instances resolved from ModelONEXContainer.service_registry | ||
| for injection into node constructors. This model is immutable after creation. | ||
|
|
||
| The protocols dict maps protocol class names to their resolved instances: | ||
| - Key: Protocol class name (e.g., "ProtocolPostgresAdapter") | ||
| - Value: Resolved instance from container | ||
|
|
||
| Example: | ||
| >>> resolved = ModelResolvedDependencies( | ||
| ... protocols={ | ||
| ... "ProtocolPostgresAdapter": postgres_adapter, | ||
| ... "ProtocolCircuitBreakerAware": circuit_breaker, | ||
| ... } | ||
| ... ) | ||
| >>> adapter = resolved.get("ProtocolPostgresAdapter") | ||
|
|
||
| .. versionadded:: 0.x.x | ||
| Part of OMN-1732 runtime dependency injection. | ||
| """ | ||
|
|
||
| model_config = ConfigDict( | ||
| frozen=True, | ||
| extra="forbid", | ||
| arbitrary_types_allowed=True, # Required for protocol instances | ||
| ) | ||
|
|
||
| # ONEX_EXCLUDE: any_type - dict[str, Any] required for heterogeneous protocol instances | ||
| # resolved from container.service_registry. Type varies by protocol (ProtocolPostgresAdapter, | ||
| # ProtocolCircuitBreakerAware, etc.). Cannot use Union as protocols are open-ended. | ||
| protocols: dict[str, Any] = Field( | ||
| default_factory=dict, | ||
| description="Map of protocol class names to resolved instances", | ||
| ) | ||
|
|
||
| # ONEX_EXCLUDE: any_type - returns heterogeneous protocol instance from protocols dict | ||
| def get(self, protocol_name: str) -> Any: | ||
| """Get a resolved protocol by name. | ||
|
|
||
| Args: | ||
| protocol_name: The protocol class name (e.g., "ProtocolPostgresAdapter") | ||
|
|
||
| Returns: | ||
| The resolved protocol instance. | ||
|
|
||
| Raises: | ||
| KeyError: If protocol_name is not in the resolved protocols. | ||
|
|
||
| Example: | ||
| >>> adapter = resolved.get("ProtocolPostgresAdapter") | ||
| """ | ||
| if protocol_name not in self.protocols: | ||
| raise KeyError( | ||
| f"Protocol '{protocol_name}' not found in resolved dependencies. " | ||
| f"Available: {list(self.protocols.keys())}" | ||
| ) | ||
| return self.protocols[protocol_name] | ||
|
|
||
| # ONEX_EXCLUDE: any_type - returns heterogeneous protocol instance, default can be any type | ||
| def get_optional(self, protocol_name: str, default: Any = None) -> Any: | ||
| """Get a resolved protocol by name, returning default if not found. | ||
|
|
||
| Args: | ||
| protocol_name: The protocol class name | ||
| default: Value to return if protocol not found | ||
|
|
||
| Returns: | ||
| The resolved protocol instance or default. | ||
| """ | ||
| return self.protocols.get(protocol_name, default) | ||
|
|
||
| def has(self, protocol_name: str) -> bool: | ||
| """Check if a protocol is available. | ||
|
|
||
| Args: | ||
| protocol_name: The protocol class name | ||
|
|
||
| Returns: | ||
| True if protocol is resolved, False otherwise. | ||
| """ | ||
| return protocol_name in self.protocols | ||
|
|
||
| def __len__(self) -> int: | ||
| """Return number of resolved protocols.""" | ||
| return len(self.protocols) | ||
|
|
||
| def __bool__(self) -> bool: | ||
| """Return True if any protocols are resolved. | ||
|
|
||
| Warning: | ||
| **Non-standard __bool__ behavior**: Returns True only when | ||
| at least one protocol is resolved. | ||
| """ | ||
| return len(self.protocols) > 0 | ||
|
|
||
|
|
||
| __all__ = ["ModelResolvedDependencies"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: OmniNode-ai/omnibase_infra
Length of output: 1106
🏁 Script executed:
Repository: OmniNode-ai/omnibase_infra
Length of output: 2299
🏁 Script executed:
Repository: OmniNode-ai/omnibase_infra
Length of output: 756
🏁 Script executed:
Repository: OmniNode-ai/omnibase_infra
Length of output: 1749
🏁 Script executed:
Repository: OmniNode-ai/omnibase_infra
Length of output: 52
🏁 Script executed:
Repository: OmniNode-ai/omnibase_infra
Length of output: 333
Async example should await resolver.
ContractDependencyResolver.resolve()is async, so the example at line 100 must useawaitto correctly resolve the dependencies. Without it, the code would assign a coroutine object instead of the resolved dependencies.✏️ Suggested doc fix
📝 Committable suggestion
🤖 Prompt for AI Agents