Remove debug message + code simplification

This commit is contained in:
Thiago Moretto
2026-01-28 20:27:18 -03:00
parent d4400e19f0
commit 8138ba491f
2 changed files with 25 additions and 31 deletions

View File

@@ -106,7 +106,6 @@ class ToolCommand(BaseCommand, PlusAPIMixin):
console.print("[bold blue]Extracting tool metadata...[/bold blue]")
try:
tools_metadata = extract_tools_metadata()
console.print(f"[dim]DEBUG: Extracted metadata: {tools_metadata}[/dim]")
except Exception as e:
console.print(
f"[bold red]Failed to extract tool metadata.[/bold red]\n"
@@ -116,7 +115,7 @@ class ToolCommand(BaseCommand, PlusAPIMixin):
f"* Are properly exported in __init__.py with __all__\n"
f"* Have valid Pydantic field definitions"
)
raise SystemExit()
raise SystemExit(1)
self._print_current_organization()
@@ -135,7 +134,7 @@ class ToolCommand(BaseCommand, PlusAPIMixin):
"Project build failed. Please ensure that the command `uv build --sdist` completes successfully.",
style="bold red",
)
raise SystemExit
raise SystemExit(1)
tarball_path = os.path.join(temp_build_dir, tarball_filename)
with open(tarball_path, "rb") as file:
@@ -144,7 +143,6 @@ class ToolCommand(BaseCommand, PlusAPIMixin):
encoded_tarball = base64.b64encode(tarball_contents).decode("utf-8")
console.print("[bold blue]Publishing tool to repository...[/bold blue]")
console.print(f"[dim]DEBUG: Payload (excluding encoded_file): handle={project_name}, is_public={is_public}, version={project_version}, description={project_description}, available_exports={available_exports}, tools_metadata={tools_metadata}[/dim]")
publish_response = self.plus_api_client.publish_tool(
handle=project_name,
is_public=is_public,

View File

@@ -1,5 +1,5 @@
from collections.abc import Mapping
from functools import reduce
from functools import lru_cache, reduce
import hashlib
import importlib.util
import inspect
@@ -654,21 +654,16 @@ def _extract_tool_metadata_from_init(init_file: Path) -> list[dict[str, Any]]:
try:
spec.loader.exec_module(module)
if not hasattr(module, "__all__"):
exported_names = getattr(module, "__all__", None)
if not exported_names:
return []
tools_metadata = []
for name in module.__all__:
if not hasattr(module, name):
for name in exported_names:
obj = getattr(module, name, None)
if obj is None or not (inspect.isclass(obj) and issubclass(obj, BaseTool)):
continue
obj = getattr(module, name)
if not (inspect.isclass(obj) and issubclass(obj, BaseTool)):
continue
tool_info = _extract_single_tool_metadata(obj)
if tool_info:
if tool_info := _extract_single_tool_metadata(obj):
tools_metadata.append(tool_info)
return tools_metadata
@@ -736,6 +731,7 @@ def _extract_field_default(
return default if isinstance(default, (list, str, int)) else fallback
@lru_cache(maxsize=1)
def _get_schema_generator() -> type:
"""Get a SchemaGenerator that omits non-serializable defaults."""
from pydantic.json_schema import GenerateJsonSchema
@@ -769,32 +765,32 @@ def _extract_run_params_schema(args_schema_field: dict[str, Any] | None) -> dict
return {}
_IGNORED_INIT_PARAMS = frozenset({
"name",
"description",
"env_vars",
"args_schema",
"description_updated",
"cache_function",
"result_as_answer",
"max_usage_count",
"current_usage_count",
"package_dependencies",
})
def _extract_init_params_schema(tool_class: type) -> dict[str, Any]:
"""
Extract JSON Schema for the tool's __init__ parameters, filtering out base fields.
"""
ignored_init_params = [
"name",
"description",
"env_vars",
"args_schema",
"description_updated",
"cache_function",
"result_as_answer",
"max_usage_count",
"current_usage_count",
"package_dependencies",
]
try:
json_schema = tool_class.model_json_schema(
schema_generator=_get_schema_generator(), mode="serialization"
)
json_schema["properties"] = {
key: value
for key, value in json_schema.get("properties", {}).items()
if key not in ignored_init_params
if key not in _IGNORED_INIT_PARAMS
}
return json_schema
except Exception: