refactor: renaming available_tools_classes by available_exports

This commit is contained in:
Lucas Gomide
2025-05-16 13:09:53 -03:00
parent c58a7134b2
commit f6399208fb
6 changed files with 46 additions and 44 deletions

View File

@@ -48,7 +48,7 @@ class PlusAPI:
version: str,
description: Optional[str],
encoded_file: str,
available_tool_classes: Optional[List[str]] = None,
available_exports: Optional[List[str]] = None,
):
params = {
"handle": handle,
@@ -56,7 +56,7 @@ class PlusAPI:
"version": version,
"file": encoded_file,
"description": description,
"available_tool_classes": available_tool_classes,
"available_exports": available_exports,
}
return self._make_request("POST", f"{self.TOOLS_RESOURCE}", json=params)

View File

@@ -11,7 +11,7 @@ from crewai.cli import git
from crewai.cli.command import BaseCommand, PlusAPIMixin
from crewai.cli.config import Settings
from crewai.cli.utils import (
extract_available_tools,
extract_available_exports,
get_project_description,
get_project_name,
get_project_version,
@@ -84,11 +84,11 @@ class ToolCommand(BaseCommand, PlusAPIMixin):
encoded_tarball = None
console.print("[bold blue]Discovering tools from your project...[/bold blue]")
available_tools = extract_available_tools()
available_exports = extract_available_exports()
if available_tools:
if available_exports:
console.print(
f"[green]Found these tools to publish: {', '.join(available_tools)}[/green]"
f"[green]Found these tools to publish: {', '.join(available_exports)}[/green]"
)
with tempfile.TemporaryDirectory() as temp_build_dir:
@@ -121,7 +121,7 @@ class ToolCommand(BaseCommand, PlusAPIMixin):
version=project_version,
description=project_description,
encoded_file=f"data:application/x-gzip;base64,{encoded_tarball}",
available_tools=available_tools,
available_exports=available_exports,
)
self._validate_response(publish_response)

View File

@@ -355,7 +355,7 @@ def is_valid_tool(obj):
return isinstance(obj, Tool)
def extract_available_tools(dir_path: str = "src"):
def extract_available_exports(dir_path: str = "src"):
"""
Extract available tool classes from the project's __init__.py files.
Only includes classes that inherit from BaseTool or functions decorated with @tool.
@@ -365,17 +365,17 @@ def extract_available_tools(dir_path: str = "src"):
"""
try:
init_files = Path(dir_path).glob("**/__init__.py")
available_tools = []
available_exports = []
for init_file in init_files:
tools = _load_tools_from_init(init_file)
available_tools.extend(tools)
available_exports.extend(tools)
if not available_tools:
if not available_exports:
_print_no_tools_warning()
raise SystemExit(1)
return available_tools
return available_exports
except Exception as e:
console.print(f"[red]Error: Could not extract tool classes: {str(e)}[/red]")
@@ -406,6 +406,7 @@ def _load_tools_from_init(init_file: Path) -> list:
)
raise SystemExit(1)
# TODO: Security check: prevent any inject malicious code, or stuff like that
return [
name
for name in module.__all__