MCPcopy
hub / github.com/1Panel-dev/MaxKB / to_tool

Method to_tool

apps/tools/serializers/tool.py:920–949  ·  view source on GitHub ↗
(tool, workspace_id, user_id, folder_id)

Source from the content-addressed store, hash-verified

918
919 @staticmethod
920 def to_tool(tool, workspace_id, user_id, folder_id):
921 # 如果是技能类型的工具,需要将code保存为文件
922 code = tool.get("code")
923 if tool.get("tool_type") == ToolType.SKILL:
924 skill_file_id = uuid.uuid7()
925 skill_file = File(
926 id=skill_file_id,
927 file_name=f"{tool.get('name')}.zip",
928 source_type=FileSourceType.TOOL,
929 source_id=tool.get("id"),
930 meta={},
931 )
932 skill_file.save(base64.b64decode(code))
933 tool["code"] = skill_file_id
934 return Tool(
935 id=tool.get("id"),
936 user_id=user_id,
937 name=tool.get("name"),
938 code=tool.get("code"),
939 template_id=tool.get("template_id"),
940 input_field_list=tool.get("input_field_list"),
941 init_field_list=tool.get("init_field_list"),
942 is_active=False
943 if (len((tool.get("init_field_list") or [])) > 0 or tool.get("tool_type") == ToolType.WORKFLOW)
944 else tool.get("is_active"),
945 tool_type=tool.get("tool_type", "CUSTOM") or "CUSTOM",
946 scope=ToolScope.SHARED if workspace_id == "None" else ToolScope.WORKSPACE,
947 folder_id=folder_id if folder_id else "default" if workspace_id == "None" else workspace_id,
948 workspace_id=workspace_id,
949 )
950
951 def import_workflow_tools(self, tool, workspace_id, user_id, folder_id, new_child_policy):
952 """

Callers 1

import_workflow_toolsMethod · 0.95

Calls 4

saveMethod · 0.95
FileClass · 0.90
ToolClass · 0.90
getMethod · 0.45

Tested by

no test coverage detected