Extract module name

This commit is contained in:
Thiago Moretto
2026-01-28 21:31:41 -03:00
parent 028db9dbbc
commit 7c29545afb
4 changed files with 15 additions and 2 deletions

View File

@@ -69,7 +69,7 @@ class PlusAPI:
"file": encoded_file,
"description": description,
"available_exports": available_exports,
"tools_metadata": {"tools": tools_metadata} if tools_metadata else None,
"tools_metadata": {"package": handle, "tools": tools_metadata} if tools_metadata else None,
}
return self._make_request("POST", f"{self.TOOLS_RESOURCE}", json=params)

View File

@@ -260,6 +260,8 @@ class ToolCommand(BaseCommand, PlusAPIMixin):
for tool in tools_metadata:
console.print(f" [bold cyan]{tool.get('name', 'Unknown')}[/bold cyan]")
if tool.get("module"):
console.print(f" Module: {tool.get('module')}")
console.print(f" Name: {tool.get('humanized_name', 'N/A')}")
console.print(f" Description: {tool.get('description', 'N/A')[:80]}{'...' if len(tool.get('description', '')) > 80 else ''}")

View File

@@ -591,8 +591,19 @@ def _extract_single_tool_metadata(tool_class: type) -> dict[str, Any] | None:
schema = _unwrap_schema(core_schema)
fields = schema.get("schema", {}).get("fields", {})
try:
file_path = inspect.getfile(tool_class)
relative_path = Path(file_path).relative_to(Path.cwd())
module_path = relative_path.with_suffix("")
if module_path.parts[0] == "src":
module_path = Path(*module_path.parts[1:])
module = ".".join(module_path.parts)
except (TypeError, ValueError):
module = tool_class.__module__
return {
"name": tool_class.__name__,
"module": module,
"humanized_name": _extract_field_default(
fields.get("name"), fallback=tool_class.__name__
),

View File

@@ -261,7 +261,7 @@ class TestPlusAPI(unittest.TestCase):
"file": encoded_file,
"description": description,
"available_exports": available_exports,
"tools_metadata": {"tools": tools_metadata},
"tools_metadata": {"package": handle, "tools": tools_metadata},
}
mock_make_request.assert_called_once_with(
"POST", "/crewai_plus/api/v1/tools", json=params