feat: 将部分逻辑移到后端,简化脚本

This commit is contained in:
PKC278
2026-03-18 17:48:28 +08:00
parent b50a3b9aae
commit 78c4ec8bfe
2 changed files with 29 additions and 99 deletions

View File

@@ -149,6 +149,19 @@ class MoviePilotToolsManager:
return True
return value
@staticmethod
def _parse_array_string(value: str, key: str, item_type: str = "string") -> list:
"""
将逗号分隔的字符串解析为列表,并根据 item_type 转换元素类型
"""
trimmed = value.strip()
if not trimmed:
return []
return [
MoviePilotToolsManager._normalize_scalar_value(item_type, item.strip(), key)
for item in trimmed.split(",") if item.strip()
]
@staticmethod
def _normalize_arguments(tool_instance: Any, arguments: Dict[str, Any]) -> Dict[str, Any]:
"""
@@ -185,6 +198,12 @@ class MoviePilotToolsManager:
field_info = MoviePilotToolsManager._resolve_field_schema(properties[key])
field_type = field_info.get("type")
# 数组类型:将字符串解析为列表
if field_type == "array" and isinstance(value, str):
item_type = field_info.get("items", {}).get("type", "string")
normalized[key] = MoviePilotToolsManager._parse_array_string(value, key, item_type)
continue
# 根据类型进行转换
normalized[key] = MoviePilotToolsManager._normalize_scalar_value(field_type, value, key)