| 1 | # Copyright (C) 2025 AIDC-AI |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | # See the License for the specific language governing permissions and |
| 11 | # limitations under the License. |
| 12 | |
| 13 | """ |
| 14 | Workflow Path Resolver |
| 15 | |
| 16 | Standardized workflow path resolution for all ComfyUI services. |
| 17 | Convention: {source}/{service}.json |
| 18 | |
| 19 | Examples: |
| 20 | - Image analysis: selfhost/analyse_image.json, runninghub/analyse_image.json |
| 21 | - Image generation: selfhost/image.json, runninghub/image.json |
| 22 | - Video generation: selfhost/video.json, runninghub/video.json |
| 23 | - TTS: selfhost/tts.json, runninghub/tts.json |
| 24 | """ |
| 25 | |
| 26 | from typing import Literal |
| 27 | |
| 28 | WorkflowSource = Literal['runninghub', 'selfhost'] |
| 29 | |
| 30 | |
| 31 | def resolve_workflow_path( |
| 32 | service_name: str, |
| 33 | source: WorkflowSource = 'runninghub' |
| 34 | ) -> str: |
| 35 | """ |
| 36 | Resolve workflow path using standardized naming convention |
| 37 | |
| 38 | Convention: workflows/{source}/{service_name}.json |
| 39 | |
| 40 | Args: |
| 41 | service_name: Service identifier (e.g., "analyse_image", "image", "video", "tts") |
| 42 | source: Workflow source - 'runninghub' (default) or 'selfhost' |
| 43 | |
| 44 | Returns: |
| 45 | Workflow path in format: "{source}/{service_name}.json" |
| 46 | |
| 47 | Examples: |
| 48 | >>> resolve_workflow_path("analyse_image", "runninghub") |
| 49 | 'runninghub/analyse_image.json' |
| 50 | |
| 51 | >>> resolve_workflow_path("analyse_image", "selfhost") |
| 52 | 'selfhost/analyse_image.json' |
| 53 | |
| 54 | >>> resolve_workflow_path("image") # defaults to runninghub |
| 55 | 'runninghub/image.json' |
| 56 | """ |
| 57 | return f"{source}/{service_name}.json" |
| 58 | |
| 59 | |
| 60 | def get_default_source() -> WorkflowSource: |
| 61 | """ |
| 62 | Get default workflow source |
| 63 | |
| 64 | Returns: |
| 65 | 'runninghub' - Cloud-first approach, better for beginners |
| 66 | """ |
| 67 | return 'runninghub' |
| 68 |