diff --git a/custom_routes.py b/custom_routes.py index 28e79ef..899383d 100644 --- a/custom_routes.py +++ b/custom_routes.py @@ -218,6 +218,9 @@ bypass_upload = os.environ.get("CD_BYPASS_UPLOAD", "false").lower() == "true" logger.info(f"CD_BYPASS_UPLOAD {bypass_upload}") +create_native_run_endpoint = None +status_endpoint = None +file_upload_endpoint = None def clear_current_prompt(sid): prompt_server = server.PromptServer.instance @@ -420,11 +423,38 @@ def send_prompt(sid: str, inputs: StreamingPrompt): logger.info(f"stack trace: {stack_trace_short}") + # # Add custom logic here + # if 'prompt_id' in response: + # prompt_id = response['prompt_id'] + # if prompt_id in prompt_metadata: + # metadata = prompt_metadata[prompt_id] + + # # Add additional information to the response + # response['status_endpoint'] = metadata.status_endpoint + # response['file_upload_endpoint'] = metadata.file_upload_endpoint + + return response + + @server.PromptServer.instance.routes.post("/comfyui-deploy/run") async def comfy_deploy_run(request): # Extract the bearer token from the Authorization header data = await request.json() - + + client_id = data.get("client_id") + # We proxy the request to Comfy Deploy, this is a native run + if "is_native_run" in data: + async with aiohttp.ClientSession() as session: + pprint(data) + # headers = request.headers.copy() + # headers['Content-Type'] = 'application/json' + async with session.post(data.get("native_run_api_endpoint"), json=data, headers={ + 'Content-Type': 'application/json', + 'Authorization': request.headers.get('Authorization') + }) as response: + data = await response.json() + print(data) + if "cd_token" in data: token = data["cd_token"] else: @@ -449,7 +479,7 @@ async def comfy_deploy_run(request): prompt = { "prompt": workflow_api, - "client_id": "comfy_deploy_instance", # api.client_id + "client_id": "comfy_deploy_instance" if client_id is None else client_id, "prompt_id": prompt_id, "extra_data": {"extra_pnginfo": {"workflow": workflow}}, } diff --git a/web-plugin/index.js b/web-plugin/index.js index 38fb9f7..1246c56 100644 --- a/web-plugin/index.js +++ b/web-plugin/index.js @@ -83,6 +83,23 @@ function dispatchAPIEventData(data) { } } +const context = { + selectedWorkflowInfo: null, +}; +// let selectedWorkflowInfo = { +// workflow_id: "05da8f2b-63af-4c0c-86dd-08d01ec512b7", +// machine_id: "45ac5f85-b7b6-436f-8d97-2383b25485f3", +// native_run_api_endpoint: "http://localhost:3011/api/run", +// }; + +function getSelectedWorkflowInfo() { + return context.selectedWorkflowInfo; +} + +function setSelectedWorkflowInfo(info) { + context.selectedWorkflowInfo = info; +} + /** @typedef {import('../../../web/types/comfy.js').ComfyExtension} ComfyExtension*/ /** @type {ComfyExtension} */ const ext = { @@ -103,10 +120,10 @@ const ext = { sendEventToCD("cd_plugin_onInit"); - app.queuePrompt = ((originalFunction) => async () => { - // const prompt = await app.graphToPrompt(); - sendEventToCD("cd_plugin_onQueuePromptTrigger"); - })(app.queuePrompt); + // app.queuePrompt = ((originalFunction) => async () => { + // // const prompt = await app.graphToPrompt(); + // sendEventToCD("cd_plugin_onQueuePromptTrigger"); + // })(app.queuePrompt); // // Intercept the onkeydown event // window.addEventListener( @@ -213,7 +230,7 @@ const ext = { (v) => { this.properties.workflow_name = v; }, - { multiline: false } + { multiline: false }, ); this.addWidget( @@ -223,7 +240,7 @@ const ext = { (v) => { this.properties.workflow_id = v; }, - { multiline: false } + { multiline: false }, ); this.addWidget( @@ -233,7 +250,7 @@ const ext = { (v) => { this.properties.version = v; }, - { multiline: false } + { multiline: false }, ); this.widgets_start_y = 10; @@ -270,11 +287,14 @@ const ext = { } // Register the node type - LiteGraph.registerNodeType("ComfyDeploy", Object.assign(ComfyDeploy, { - title: "Comfy Deploy", - title_mode: LiteGraph.NORMAL_TITLE, - collapsable: true, - })); + LiteGraph.registerNodeType( + "ComfyDeploy", + Object.assign(ComfyDeploy, { + title: "Comfy Deploy", + title_mode: LiteGraph.NORMAL_TITLE, + collapsable: true, + }), + ); ComfyDeploy.category = "deploy"; }, @@ -293,6 +313,14 @@ const ext = { // This part of the code would depend on how the ComfyUI expects to receive and process the workflow data // For demonstration, let's assume there's a loadWorkflow method in the ComfyUI API if (comfyUIWorkflow && app && app.loadGraphData) { + try { + await window["app"].ui.settings.setSettingValueAsync( + "Comfy.Validation.Workflows", + false, + ); + } catch (error) { + console.warning("Error setting validation to false, is fine to ignore this", error); + } console.log("loadGraphData"); app.loadGraphData(comfyUIWorkflow); } @@ -380,6 +408,8 @@ const ext = { } animate(); + } else if (message.type === "workflow_info") { + setSelectedWorkflowInfo(message.data); } // else if (message.type === "refresh") { // sendEventToCD("cd_plugin_onRefresh"); @@ -443,10 +473,10 @@ function createDynamicUIHtml(data) {
These nodes are not found with any matching custom_nodes in the ComfyUI Manager Database
${data.missing_nodes - .map((node) => { - return `${node}
`; - }) - .join("")} + .map((node) => { + return `${node}
`; + }) + .join("")} `; } @@ -454,14 +484,17 @@ function createDynamicUIHtml(data) { Object.values(data.custom_nodes).forEach((node) => { html += `${node.hash}
- ${node.warning - ? `${node.warning}
` - : "" - } + ${ + node.warning + ? `${node.warning}
` + : "" + }${item.name}
`; }); @@ -492,8 +526,9 @@ function createDynamicUIHtml(data) { Object.entries(data.files).forEach(([section, items]) => { html += `${item.name}
`; }); @@ -1013,12 +1048,14 @@ export class LoadingDialog extends ComfyDialog { showLoading(title, message) { this.show(`