Load tool configurations with version history from JSON. Loads basic configuration only (instance is not saved, must be created via build()). Only the latest version will be instantiated by default if auto_initialize=True. Args: file_path: File p
(self, file_path: Optional[str] = None, auto_initialize: bool = True)
| 870 | return str(file_path) |
| 871 | |
| 872 | async def load_from_json(self, file_path: Optional[str] = None, auto_initialize: bool = True) -> bool: |
| 873 | """Load tool configurations with version history from JSON. |
| 874 | |
| 875 | Loads basic configuration only (instance is not saved, must be created via build()). |
| 876 | Only the latest version will be instantiated by default if auto_initialize=True. |
| 877 | |
| 878 | Args: |
| 879 | file_path: File path to load from |
| 880 | auto_initialize: Whether to automatically create instance via build() after loading |
| 881 | |
| 882 | Returns: |
| 883 | True if loaded successfully, False otherwise |
| 884 | """ |
| 885 | |
| 886 | file_path = file_path if file_path is not None else self.save_path |
| 887 | |
| 888 | async with file_lock(file_path): |
| 889 | if not os.path.exists(file_path): |
| 890 | logger.warning(f"| ⚠️ Tool file not found: {file_path}") |
| 891 | return False |
| 892 | |
| 893 | try: |
| 894 | with open(file_path, "r", encoding="utf-8") as f: |
| 895 | load_data = json.load(f) |
| 896 | |
| 897 | tools_data = load_data.get("tools", {}) |
| 898 | loaded_count = 0 |
| 899 | |
| 900 | for tool_name, tool_data in tools_data.items(): |
| 901 | try: |
| 902 | # Expected format: multiple versions stored as a dict {version_str: config_dict} |
| 903 | versions_data = tool_data.get("versions") |
| 904 | if not isinstance(versions_data, dict): |
| 905 | logger.warning(f"| ⚠️ Tool {tool_name} has invalid format for 'versions' (expected dict), skipping") |
| 906 | continue |
| 907 | |
| 908 | current_version_str = tool_data.get("current_version") |
| 909 | |
| 910 | # Load all versions |
| 911 | version_configs = [] |
| 912 | latest_config = None |
| 913 | latest_version = None |
| 914 | |
| 915 | for version_str, config_dict in versions_data.items(): |
| 916 | # Ensure version field is present |
| 917 | if "version" not in config_dict: |
| 918 | config_dict["version"] = version_str |
| 919 | |
| 920 | try: |
| 921 | tool_config = ToolConfig.model_validate(config_dict) |
| 922 | version_configs.append(tool_config) |
| 923 | except Exception as e: |
| 924 | logger.warning(f"| ⚠️ Failed to load tool config for {tool_name}@{version_str}: {e}") |
| 925 | continue |
| 926 | |
| 927 | # Track latest version |
| 928 | if latest_config is None or ( |
| 929 | current_version_str and tool_config.version == current_version_str |
nothing calls this directly
no test coverage detected