Restore a specific version of a tool from history Args: tool_name: Name of the tool version: Version string to restore auto_initialize: Whether to automatically initialize the restored tool Returns: ToolConfig of t
(self, tool_name: str, version: str, auto_initialize: bool = True)
| 966 | return False |
| 967 | |
| 968 | async def restore(self, tool_name: str, version: str, auto_initialize: bool = True) -> Optional[ToolConfig]: |
| 969 | """Restore a specific version of a tool from history |
| 970 | |
| 971 | Args: |
| 972 | tool_name: Name of the tool |
| 973 | version: Version string to restore |
| 974 | auto_initialize: Whether to automatically initialize the restored tool |
| 975 | |
| 976 | Returns: |
| 977 | ToolConfig of the restored version, or None if not found |
| 978 | """ |
| 979 | # Look up version from dict-based history (O(1) lookup) |
| 980 | version_config = None |
| 981 | if tool_name in self._tool_history_versions: |
| 982 | version_config = self._tool_history_versions[tool_name].get(version) |
| 983 | |
| 984 | if version_config is None: |
| 985 | logger.warning(f"| ⚠️ Version {version} not found for tool {tool_name}") |
| 986 | return None |
| 987 | |
| 988 | # Create a copy to avoid modifying the history |
| 989 | restored_config = ToolConfig(**version_config.model_dump()) |
| 990 | |
| 991 | # Set as current active config |
| 992 | self._tool_configs[tool_name] = restored_config |
| 993 | |
| 994 | # Update version manager current version |
| 995 | version_history = await version_manager.get_version_history("tool", tool_name) |
| 996 | if version_history: |
| 997 | # Check if version exists in version history, if not register it |
| 998 | if version not in version_history.versions: |
| 999 | await version_manager.register_version("tool", tool_name, version) |
| 1000 | version_history.current_version = version |
| 1001 | else: |
| 1002 | # If version history doesn't exist, register the version first |
| 1003 | await version_manager.register_version("tool", tool_name, version) |
| 1004 | |
| 1005 | # Initialize if requested |
| 1006 | if auto_initialize and restored_config.cls is not None: |
| 1007 | await self.build(restored_config) |
| 1008 | |
| 1009 | # Persist to JSON (current_version changes) |
| 1010 | await self.save_to_json() |
| 1011 | |
| 1012 | logger.info(f"| 🔄 Restored tool {tool_name} to version {version}") |
| 1013 | return restored_config |
| 1014 | |
| 1015 | async def save_contract(self, tool_names: Optional[List[str]] = None): |
| 1016 | """Save the contract for a tool""" |
nothing calls this directly
no test coverage detected