Skip to content

Commit b3320d9

Browse files
committed
feat: enhance telemetry and tool management with improved file handling and boolean coercion
1 parent 8c9583d commit b3320d9

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

Server/src/core/telemetry.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,17 @@ def get_package_version() -> str:
4848
except Exception:
4949
# Fallback for development: read from pyproject.toml
5050
try:
51-
pyproject_path = Path(__file__).parent / "pyproject.toml"
52-
with open(pyproject_path, "rb") as f:
51+
pyproject_path: Path | None = None
52+
current = Path(__file__).resolve()
53+
for parent in current.parents:
54+
candidate = parent / "pyproject.toml"
55+
if candidate.exists():
56+
pyproject_path = candidate
57+
break
58+
if pyproject_path is None:
59+
raise FileNotFoundError("pyproject.toml not found in ancestors")
60+
61+
with pyproject_path.open("rb") as f:
5362
data = tomli.load(f)
5463
return data["project"]["version"]
5564
except Exception:

Server/src/services/custom_tool_service.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ def _register_tool(self, project_id: str, definition: ToolDefinitionModel) -> No
146146
self._project_tools.setdefault(project_id, {})[
147147
definition.name] = definition
148148

149+
def get_project_id_for_hash(self, project_hash: str | None) -> str | None:
150+
if not project_hash:
151+
return None
152+
return self._hash_to_project.get(project_hash.lower())
153+
149154
async def _poll_until_complete(
150155
self,
151156
tool_name: str,
@@ -317,8 +322,16 @@ def resolve_project_id_for_unity_instance(unity_instance: str | None) -> str | N
317322
hash_part = unity_instance
318323

319324
if hash_part:
320-
# Return the hash directly as the identifier for WebSocket tools
321-
return hash_part.lower()
325+
lowered = hash_part.lower()
326+
mapped: Optional[str] = None
327+
try:
328+
service = CustomToolService.get_instance()
329+
mapped = service.get_project_id_for_hash(lowered)
330+
except RuntimeError:
331+
mapped = None
332+
if mapped:
333+
return mapped
334+
return lowered
322335
except Exception:
323336
logger.debug(
324337
f"Failed to resolve project id via plugin hub for {unity_instance}")

Server/src/services/tools/manage_prefabs.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,38 @@ async def manage_prefabs(
2929
# Get active instance from session state
3030
# Removed session_state import
3131
unity_instance = get_unity_instance_from_context(ctx)
32+
33+
def _coerce_bool(value, default=None):
34+
if value is None:
35+
return default
36+
if isinstance(value, bool):
37+
return value
38+
if isinstance(value, str):
39+
v = value.strip().lower()
40+
if v in ("true", "1", "yes", "on"):
41+
return True
42+
if v in ("false", "0", "no", "off"):
43+
return False
44+
return bool(value)
45+
3246
try:
3347
params: dict[str, Any] = {"action": action}
3448

3549
if prefab_path:
3650
params["prefabPath"] = prefab_path
3751
if mode:
3852
params["mode"] = mode
39-
if save_before_close is not None:
40-
params["saveBeforeClose"] = bool(save_before_close)
53+
save_before_close_val = _coerce_bool(save_before_close)
54+
if save_before_close_val is not None:
55+
params["saveBeforeClose"] = save_before_close_val
4156
if target:
4257
params["target"] = target
43-
if allow_overwrite is not None:
44-
params["allowOverwrite"] = bool(allow_overwrite)
45-
if search_inactive is not None:
46-
params["searchInactive"] = bool(search_inactive)
58+
allow_overwrite_val = _coerce_bool(allow_overwrite)
59+
if allow_overwrite_val is not None:
60+
params["allowOverwrite"] = allow_overwrite_val
61+
search_inactive_val = _coerce_bool(search_inactive)
62+
if search_inactive_val is not None:
63+
params["searchInactive"] = search_inactive_val
4764
response = await send_with_unity_instance(async_send_command_with_retry, unity_instance, "manage_prefabs", params)
4865

4966
if isinstance(response, dict) and response.get("success"):

Server/src/services/tools/script_apply_edits.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ def error_with_hint(message: str, expected: dict[str, Any], suggestion: dict[str
600600
return _with_norm(resp_struct if isinstance(resp_struct, dict) else {"success": False, "message": str(resp_struct)}, normalized_for_echo, routing="structured")
601601

602602
# 1) read from Unity
603-
read_resp = async_send_command_with_retry("manage_script", {
603+
read_resp = await async_send_command_with_retry("manage_script", {
604604
"action": "read",
605605
"name": name,
606606
"path": path,

0 commit comments

Comments
 (0)