# Copyright 2026 zhaoxi826 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from pydantic import BaseModel import viceroy from pretor.core.workflow.workflow_template_generator.workflow_template import WorkflowTemplate from pretor.utils.ray_hook import ray_actor_hook from fastapi import APIRouter, Depends from pretor.utils.access import TokenData from pretor.utils.check_user.role_check import RoleChecker from pretor.core.database.table.user import UserAuthority resource_router = APIRouter(prefix="/api/v1/resource") @resource_router.post("/workflow_template") async def create_workflow_template(workflow_template: WorkflowTemplate, _: TokenData = Depends(RoleChecker(allowed_roles=UserAuthority.USER))): global_state_machine = ray_actor_hook("global_state_machine") await global_state_machine.workflow_template_generate.remote(workflow_template) return {"message": "创建成功"} class Skill(BaseModel): repo_url: str path: str | None @resource_router.post("/skill") async def install_skill(skill: Skill, _: TokenData = Depends(RoleChecker(allowed_roles=UserAuthority.USER))): global_state_machine = ray_actor_hook("global_state_machine") # noinspection PyUnresolvedReferences await viceroy.install_skill_async(url = skill.repo_url, path = skill.path, output = "./pretor/plugin/tool_plugin") if skill.path: skill_name = skill.path.split("/")[-1] else: skill_name = skill.repo_url.split("/")[-1] await global_state_machine.skill_manager.remote("add_skill", skill_name) return {"message": "创建成功"}