fix: address bot review feedback on tool metadata

- Use `is not None` instead of truthiness check so empty tools list
  is sent to the API rather than being silently dropped as None
- Strip __init__ suffix from module path for tools in __init__.py files
- Extend _unwrap_schema to handle function-before, function-wrap, and
  definitions wrapper types
This commit is contained in:
Thiago Moretto
2026-03-26 11:27:38 -03:00
parent c9e8e05cd7
commit 190430da08
2 changed files with 10 additions and 2 deletions

View File

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

View File

@@ -708,6 +708,8 @@ def _extract_single_tool_metadata(tool_class: type) -> dict[str, Any] | None:
module_path = relative_path.with_suffix("")
if module_path.parts[0] == "src":
module_path = Path(*module_path.parts[1:])
if module_path.name == "__init__":
module_path = module_path.parent
module = ".".join(module_path.parts)
except (TypeError, ValueError):
module = tool_class.__module__
@@ -735,7 +737,13 @@ def _unwrap_schema(schema: Mapping[str, Any] | dict[str, Any]) -> dict[str, Any]
Unwrap nested schema structures to get to the actual schema definition.
"""
result: dict[str, Any] = dict(schema)
while result.get("type") in {"function-after", "default"} and "schema" in result:
while (
result.get("type")
in {"function-after", "function-before", "function-wrap", "default"}
and "schema" in result
):
result = dict(result["schema"])
if result.get("type") == "definitions" and "schema" in result:
result = dict(result["schema"])
return result