(tools: List[Dict])
| 132 | |
| 133 | |
| 134 | async def ui_fetch_tools(tools: List[Dict]) -> List[Dict]: |
| 135 | lang = CONFIG.DEFAULT_LANG |
| 136 | for tool in tools: |
| 137 | if tool["type"] == ToolType.ACTION: |
| 138 | action = await action_ops.get(action_id=tool["id"]) |
| 139 | if action: |
| 140 | tool["name"] = action.name |
| 141 | |
| 142 | elif tool["type"] == ToolType.PLUGIN: |
| 143 | if "/" not in tool["id"]: |
| 144 | raise_request_validation_error(f"Invalid plugin tool ID: {tool['id']}") |
| 145 | bundle_instance_id, plugin_id = tool["id"].split("/") |
| 146 | bundle_instance: BundleInstance = await bundle_instance_ops.get(bundle_instance_id=bundle_instance_id) |
| 147 | bundle = get_bundle(bundle_id=bundle_instance.bundle_id) |
| 148 | real_bundle_name = i18n_text(bundle.bundle_id, bundle.name, lang) |
| 149 | plugin = get_plugin(bundle_id=bundle.bundle_id, plugin_id=plugin_id) |
| 150 | real_plugin_name = i18n_text(plugin.bundle_id, plugin.name, lang) |
| 151 | if bundle: |
| 152 | tool["name"] = f"{real_bundle_name} / {real_plugin_name}" |
| 153 | |
| 154 | else: |
| 155 | raise_request_validation_error(f"Invalid tool type: {tool['type']}") |
| 156 | |
| 157 | return tools |
no test coverage detected