(filename: str)
| 70 | |
| 71 | @router.get("/api/workflows/{filename}/args") |
| 72 | async def get_workflow_args(filename: str): |
| 73 | print(str) |
| 74 | try: |
| 75 | safe_filename = validate_workflow_filename(filename, require_yaml_extension=True) |
| 76 | print(safe_filename) |
| 77 | file_path = YAML_DIR / safe_filename |
| 78 | |
| 79 | if not file_path.exists() or not file_path.is_file(): |
| 80 | raise ResourceNotFoundError( |
| 81 | "Workflow file not found", |
| 82 | resource_type="workflow", |
| 83 | resource_id=safe_filename, |
| 84 | ) |
| 85 | |
| 86 | # Load and validate YAML content |
| 87 | raw_content = file_path.read_text(encoding="utf-8") |
| 88 | _, yaml_content = validate_workflow_content(safe_filename, raw_content) |
| 89 | |
| 90 | args: list[dict[str, Any]] = [] |
| 91 | if isinstance(yaml_content, dict): |
| 92 | graph = yaml_content.get("graph") or {} |
| 93 | if isinstance(graph, dict): |
| 94 | raw_args = graph.get("args") or [] |
| 95 | if isinstance(raw_args, list): |
| 96 | if len(raw_args) == 0: |
| 97 | raise ResourceNotFoundError( |
| 98 | "Workflow file does not have args", |
| 99 | resource_type="workflow", |
| 100 | resource_id=safe_filename, |
| 101 | ) |
| 102 | for item in raw_args: |
| 103 | # Each item is expected to be like: { arg_name: [ {key: value}, ... ] } |
| 104 | if not isinstance(item, dict) or len(item) != 1: |
| 105 | continue |
| 106 | (arg_name, spec_list), = item.items() |
| 107 | if not isinstance(arg_name, str): |
| 108 | continue |
| 109 | |
| 110 | arg_info: dict[str, Any] = {"name": arg_name} |
| 111 | if isinstance(spec_list, list): |
| 112 | for spec in spec_list: |
| 113 | if isinstance(spec, dict): |
| 114 | for key, value in spec.items(): |
| 115 | # Later entries override earlier ones if duplicated |
| 116 | arg_info[str(key)] = value |
| 117 | args.append(arg_info) |
| 118 | |
| 119 | logger = get_server_logger() |
| 120 | logger.info( |
| 121 | "Workflow args retrieved", |
| 122 | log_type=LogType.WORKFLOW, |
| 123 | filename=safe_filename, |
| 124 | args_count=len(args), |
| 125 | ) |
| 126 | |
| 127 | return {"args": args} |
| 128 | except ValidationError as exc: |
| 129 | # 参数或文件名等校验错误 |
nothing calls this directly
no test coverage detected