(self, data: Any)
| 324 | ) from exc |
| 325 | |
| 326 | def toggle_tool(self, data: Any) -> str: |
| 327 | try: |
| 328 | tool_name = data.get("name") |
| 329 | action = data.get("activate") |
| 330 | |
| 331 | if not tool_name or action is None: |
| 332 | raise ToolsServiceError("Missing required parameters: name or activate") |
| 333 | |
| 334 | if self.tool_mgr.is_builtin_tool(tool_name): |
| 335 | raise ToolsServiceError( |
| 336 | "Builtin tools are read-only and cannot be toggled." |
| 337 | ) |
| 338 | |
| 339 | if action: |
| 340 | try: |
| 341 | ok = self.tool_mgr.activate_llm_tool(tool_name, star_map=star_map) |
| 342 | except ValueError as exc: |
| 343 | raise ToolsServiceError( |
| 344 | f"Failed to activate tool: {exc!s}" |
| 345 | ) from exc |
| 346 | else: |
| 347 | ok = self.tool_mgr.deactivate_llm_tool(tool_name) |
| 348 | |
| 349 | if ok: |
| 350 | return "Operation successful." |
| 351 | raise ToolsServiceError( |
| 352 | f"Tool {tool_name} does not exist or the operation failed." |
| 353 | ) |
| 354 | except ToolsServiceError: |
| 355 | raise |
| 356 | except Exception as exc: |
| 357 | logger.error(traceback.format_exc()) |
| 358 | raise ToolsServiceError(f"Failed to operate tool: {exc!s}") from exc |
| 359 | |
| 360 | async def sync_provider(self, data: Any) -> str: |
| 361 | try: |
no test coverage detected