migrate to data models for all routes

This commit is contained in:
bymyself 2025-06-12 18:40:14 -07:00
parent 3afafdb884
commit 0be0a2e6d7
5 changed files with 640 additions and 704 deletions

View File

@ -42,7 +42,13 @@ from .generated_models import (
ManagerPackInstallType,
ManagerPack,
InstallPackParams,
UpdatePackParams,
UpdateAllPacksParams,
UpdateComfyUIParams,
FixPackParams,
UninstallPackParams,
DisablePackParams,
EnablePackParams,
QueueStatus,
ManagerMappings,
ModelMetadata,
@ -91,7 +97,13 @@ __all__ = [
"ManagerPackInstallType",
"ManagerPack",
"InstallPackParams",
"UpdatePackParams",
"UpdateAllPacksParams",
"UpdateComfyUIParams",
"FixPackParams",
"UninstallPackParams",
"DisablePackParams",
"EnablePackParams",
"QueueStatus",
"ManagerMappings",
"ModelMetadata",

View File

@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
# timestamp: 2025-06-08T08:07:38+00:00
# timestamp: 2025-06-13T00:37:21+00:00
from __future__ import annotations
@ -23,12 +23,6 @@ class Kind(str, Enum):
install_model = 'install-model'
class QueueTaskItem(BaseModel):
ui_id: str = Field(..., description='Unique identifier for the task')
client_id: str = Field(..., description='Client identifier that initiated the task')
kind: Kind = Field(..., description='Type of task being performed')
class StatusStr(str, Enum):
success = 'success'
error = 'error'
@ -154,6 +148,49 @@ class UpdateAllPacksParams(BaseModel):
ui_id: Optional[str] = Field(None, description='Task ID - generated internally')
class UpdatePackParams(BaseModel):
node_name: str = Field(..., description='Name of the node package to update')
node_ver: Optional[str] = Field(
None, description='Current version of the node package'
)
class UpdateComfyUIParams(BaseModel):
is_stable: Optional[bool] = Field(
True,
description='Whether to update to stable version (true) or nightly (false)',
)
target_version: Optional[str] = Field(
None,
description='Specific version to switch to (for version switching operations)',
)
class FixPackParams(BaseModel):
node_name: str = Field(..., description='Name of the node package to fix')
node_ver: str = Field(..., description='Version of the node package')
class UninstallPackParams(BaseModel):
node_name: str = Field(..., description='Name of the node package to uninstall')
is_unknown: Optional[bool] = Field(
False, description='Whether this is an unknown/unregistered package'
)
class DisablePackParams(BaseModel):
node_name: str = Field(..., description='Name of the node package to disable')
is_unknown: Optional[bool] = Field(
False, description='Whether this is an unknown/unregistered package'
)
class EnablePackParams(BaseModel):
cnr_id: str = Field(
..., description='ComfyUI Node Registry ID of the package to enable'
)
class QueueStatus(BaseModel):
total_count: int = Field(
..., description='Total number of tasks (pending + running)'
@ -358,6 +395,23 @@ class BatchExecutionRecord(BaseModel):
)
class QueueTaskItem(BaseModel):
ui_id: str = Field(..., description='Unique identifier for the task')
client_id: str = Field(..., description='Client identifier that initiated the task')
kind: Kind = Field(..., description='Type of task being performed')
params: Union[
InstallPackParams,
UpdatePackParams,
UpdateAllPacksParams,
UpdateComfyUIParams,
FixPackParams,
UninstallPackParams,
DisablePackParams,
EnablePackParams,
ModelMetadata,
]
class TaskHistoryItem(BaseModel):
ui_id: str = Field(..., description='Unique identifier for the task')
client_id: str = Field(..., description='Client identifier that initiated the task')

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
import locale
import sys
import re
def handle_stream(stream, prefix):
@ -19,3 +20,41 @@ def handle_stream(stream, prefix):
print(prefix, msg, end="", file=sys.stderr)
else:
print(prefix, msg, end="")
def convert_markdown_to_html(input_text):
pattern_a = re.compile(r"\[a/([^]]+)]\(([^)]+)\)")
pattern_w = re.compile(r"\[w/([^]]+)]")
pattern_i = re.compile(r"\[i/([^]]+)]")
pattern_bold = re.compile(r"\*\*([^*]+)\*\*")
pattern_white = re.compile(r"%%([^*]+)%%")
def replace_a(match):
return f"<a href='{match.group(2)}' target='blank'>{match.group(1)}</a>"
def replace_w(match):
return f"<p class='cm-warn-note'>{match.group(1)}</p>"
def replace_i(match):
return f"<p class='cm-info-note'>{match.group(1)}</p>"
def replace_bold(match):
return f"<B>{match.group(1)}</B>"
def replace_white(match):
return f"<font color='white'>{match.group(1)}</font>"
input_text = (
input_text.replace("\\[", "&#91;")
.replace("\\]", "&#93;")
.replace("<", "&lt;")
.replace(">", "&gt;")
)
result_text = re.sub(pattern_a, replace_a, input_text)
result_text = re.sub(pattern_w, replace_w, result_text)
result_text = re.sub(pattern_i, replace_i, result_text)
result_text = re.sub(pattern_bold, replace_bold, result_text)
result_text = re.sub(pattern_white, replace_white, result_text)
return result_text.replace("\n", "<BR>")

View File

@ -32,7 +32,18 @@ components:
type: string
description: Type of task being performed
enum: [install, uninstall, update, update-all, update-comfyui, fix, disable, enable, install-model]
required: [ui_id, client_id, kind]
params:
oneOf:
- $ref: '#/components/schemas/InstallPackParams'
- $ref: '#/components/schemas/UpdatePackParams'
- $ref: '#/components/schemas/UpdateAllPacksParams'
- $ref: '#/components/schemas/UpdateComfyUIParams'
- $ref: '#/components/schemas/FixPackParams'
- $ref: '#/components/schemas/UninstallPackParams'
- $ref: '#/components/schemas/DisablePackParams'
- $ref: '#/components/schemas/EnablePackParams'
- $ref: '#/components/schemas/ModelMetadata'
required: [ui_id, client_id, kind, params]
TaskHistoryItem:
type: object
@ -309,6 +320,74 @@ components:
type: string
description: Task ID - generated internally
UpdatePackParams:
type: object
properties:
node_name:
type: string
description: Name of the node package to update
node_ver:
type: string
description: Current version of the node package
nullable: true
required: [node_name]
UpdateComfyUIParams:
type: object
properties:
is_stable:
type: boolean
description: Whether to update to stable version (true) or nightly (false)
default: true
target_version:
type: string
description: Specific version to switch to (for version switching operations)
nullable: true
required: []
FixPackParams:
type: object
properties:
node_name:
type: string
description: Name of the node package to fix
node_ver:
type: string
description: Version of the node package
required: [node_name, node_ver]
UninstallPackParams:
type: object
properties:
node_name:
type: string
description: Name of the node package to uninstall
is_unknown:
type: boolean
description: Whether this is an unknown/unregistered package
default: false
required: [node_name]
DisablePackParams:
type: object
properties:
node_name:
type: string
description: Name of the node package to disable
is_unknown:
type: boolean
description: Whether this is an unknown/unregistered package
default: false
required: [node_name]
EnablePackParams:
type: object
properties:
cnr_id:
type: string
description: ComfyUI Node Registry ID of the package to enable
required: [cnr_id]
# Queue Status Models
QueueStatus:
type: object
@ -689,6 +768,22 @@ components:
schema:
type: string
clientIdRequiredParam:
name: client_id
in: query
required: true
description: Required client ID that initiated the request
schema:
type: string
uiIdRequiredParam:
name: ui_id
in: query
required: true
description: Required unique task identifier
schema:
type: string
maxItemsParam:
name: max_items
in: query
@ -718,9 +813,99 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/QueueTaskItem'
examples:
install:
summary: Install a custom node
value:
ui_id: "task_123"
client_id: "client_abc"
kind: "install"
params:
id: "pythongosssss/ComfyUI-Custom-Scripts"
version: "latest"
selected_version: "latest"
mode: "remote"
channel: "default"
update:
summary: Update a custom node
value:
ui_id: "task_124"
client_id: "client_abc"
kind: "update"
params:
node_name: "ComfyUI-Custom-Scripts"
node_ver: "1.0.0"
update-all:
summary: Update all custom nodes
value:
ui_id: "task_125"
client_id: "client_abc"
kind: "update-all"
params:
mode: "remote"
update-comfyui:
summary: Update ComfyUI itself
value:
ui_id: "task_126"
client_id: "client_abc"
kind: "update-comfyui"
params:
is_stable: true
fix:
summary: Fix a custom node
value:
ui_id: "task_127"
client_id: "client_abc"
kind: "fix"
params:
node_name: "ComfyUI-Impact-Pack"
node_ver: "2.0.0"
uninstall:
summary: Uninstall a custom node
value:
ui_id: "task_128"
client_id: "client_abc"
kind: "uninstall"
params:
node_name: "ComfyUI-AnimateDiff-Evolved"
is_unknown: false
disable:
summary: Disable a custom node
value:
ui_id: "task_129"
client_id: "client_abc"
kind: "disable"
params:
node_name: "ComfyUI-Manager"
is_unknown: false
enable:
summary: Enable a custom node
value:
ui_id: "task_130"
client_id: "client_abc"
kind: "enable"
params:
cnr_id: "comfyui-manager"
install-model:
summary: Install a model
value:
ui_id: "task_131"
client_id: "client_abc"
kind: "install-model"
params:
name: "SD 1.5 Base Model"
type: "checkpoint"
base: "SD1.x"
save_path: "default"
url: "https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned.safetensors"
filename: "v1-5-pruned.safetensors"
responses:
'200':
description: Task queued successfully
'400':
description: Invalid task data
'500':
description: Internal server error
/v2/manager/queue/status:
get:
@ -776,28 +961,6 @@ paths:
'400':
description: Error retrieving history list
/v2/manager/queue/batch/{batch_id}:
get:
summary: Get batch execution record
description: Returns detailed execution record for a specific batch including before/after state snapshots and all operations performed
parameters:
- name: batch_id
in: path
required: true
description: Unique batch identifier
schema:
type: string
responses:
'200':
description: Batch record retrieved successfully
content:
application/json:
schema:
$ref: '#/components/schemas/BatchExecutionRecord'
'404':
description: Batch not found
'400':
description: Error retrieving batch record
/v2/manager/queue/start:
get:
@ -825,9 +988,13 @@ paths:
- securityLevel: []
parameters:
- $ref: '#/components/parameters/modeParam'
- $ref: '#/components/parameters/clientIdRequiredParam'
- $ref: '#/components/parameters/uiIdRequiredParam'
responses:
'200':
description: Update queued successfully
'400':
description: Missing required parameters
'401':
description: Processing already in progress
'403':
@ -837,9 +1004,14 @@ paths:
get:
summary: Update ComfyUI
description: Queues an update operation for ComfyUI itself
parameters:
- $ref: '#/components/parameters/clientIdRequiredParam'
- $ref: '#/components/parameters/uiIdRequiredParam'
responses:
'200':
description: Update queued successfully
'400':
description: Missing required parameters
/v2/manager/queue/install_model:
post:
@ -930,43 +1102,7 @@ paths:
'400':
description: No information available
/v2/customnode/install/git_url:
post:
summary: Install custom node via Git URL
description: Installs a custom node from a Git repository URL
security:
- securityLevel: []
requestBody:
required: true
content:
text/plain:
schema:
type: string
responses:
'200':
description: Installation successful or already installed
'400':
description: Installation failed
'403':
description: Security policy violation
/v2/customnode/install/pip:
post:
summary: Install custom node dependencies via pip
description: Installs Python package dependencies for custom nodes
security:
- securityLevel: []
requestBody:
required: true
content:
text/plain:
schema:
type: string
responses:
'200':
description: Installation successful
'403':
description: Security policy violation
# Snapshot Management Endpoints (v2)
/v2/snapshot/getlist:
@ -1071,35 +1207,19 @@ paths:
parameters:
- name: ver
in: query
required: true
description: Target version
schema:
type: string
- $ref: '#/components/parameters/clientIdRequiredParam'
- $ref: '#/components/parameters/uiIdRequiredParam'
responses:
'200':
description: Version switch successful
description: Version switch queued successfully
'400':
description: Error switching version
description: Missing required parameters or error switching version
# Configuration Endpoints (v2)
/v2/manager/preview_method:
get:
summary: Get or set preview method
description: Gets or sets the latent preview method
parameters:
- name: value
in: query
required: false
description: New preview method
schema:
type: string
enum: [auto, latent2rgb, taesd, none]
responses:
'200':
description: Setting updated or current value returned
content:
text/plain:
schema:
type: string
/v2/manager/db_mode:
get: