From 15c7d7f60cca307daea09685e57087f4e1a9627b Mon Sep 17 00:00:00 2001 From: shanexi Date: Thu, 24 Oct 2024 21:41:17 +0800 Subject: [PATCH 01/12] Optimize number input convert --- web/shellagent.js | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/web/shellagent.js b/web/shellagent.js index e21a7d1..cee0476 100644 --- a/web/shellagent.js +++ b/web/shellagent.js @@ -93,7 +93,7 @@ app.registerExtension({ try { arr = JSON.parse(widget.value) } catch { } - } else if(Array.isArray(widget.value)) { + } else if (Array.isArray(widget.value)) { arr = widget.value } @@ -191,25 +191,32 @@ app.registerExtension({ }) } if (["number"].indexOf(w.type) > -1) { - toInput.push({ - content: `${w.name} <- Input Interger`, - callback: () => { - this.convertWidgetToInput(w); - const node = addNode("ShellAgentPluginInputInteger", this, { before: true }); - const dvn = node.widgets.find(w => w.name === 'default_value') - dvn.value = w.value; - node.connect(0, this, this.inputs.length - 1); - } - }) toInput.push({ - content: `${w.name} <- Input Float`, - callback: () => { - this.convertWidgetToInput(w); - const node = addNode("ShellAgentPluginInputFloat", this, { before: true }); - const dvn = node.widgets.find(w => w.name === 'default_value') - dvn.value = w.value; - node.connect(0, this, this.inputs.length - 1); + content: w.name, + submenu: { + options: [ + { + content: 'Input Interger', + callback: () => { + this.convertWidgetToInput(w); + const node = addNode("ShellAgentPluginInputInteger", this, { before: true }); + const dvn = node.widgets.find(w => w.name === 'default_value') + dvn.value = w.value; + node.connect(0, this, this.inputs.length - 1); + } + }, + { + content: 'Input Float', + callback: () => { + this.convertWidgetToInput(w); + const node = addNode("ShellAgentPluginInputFloat", this, { before: true }); + const dvn = node.widgets.find(w => w.name === 'default_value') + dvn.value = w.value; + node.connect(0, this, this.inputs.length - 1); + } + } + ] } }) } From d2cfd99a334b38602c1415a4b334a71de3cc248a Mon Sep 17 00:00:00 2001 From: shanexi Date: Thu, 24 Oct 2024 22:33:38 +0800 Subject: [PATCH 02/12] Ouput convert --- web/shellagent.js | 92 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 12 deletions(-) diff --git a/web/shellagent.js b/web/shellagent.js index cee0476..bd289ae 100644 --- a/web/shellagent.js +++ b/web/shellagent.js @@ -176,22 +176,40 @@ app.registerExtension({ addMenuHandler(nodeType, function (_, options) { if (this.widgets) { let toInput = []; - for (const w of this.widgets) { + // todo: combo need to remove and convert back + // if (w.type === 'combo' && w.name === 'image') { + // toInput.push({ + // content: `${w.name} <- Input Image`, + // callback: () => { + // this.convertWidgetToInput(w); + // const node = addNode("ShellAgentPluginInputImage", this, { before: true }); + // const dvn = node.widgets.find(w => w.name === 'default_value') + // dvn.value = w.value; + // node.connect(0, this, 0); + // } + // }) + // } if (["customtext"].indexOf(w.type) > -1) { toInput.push({ - content: `${w.name} <- Input Text`, - callback: () => { - this.convertWidgetToInput(w); - const node = addNode("ShellAgentPluginInputText", this, { before: true }); - const dvn = node.widgets.find(w => w.name === 'default_value') - dvn.value = w.value; - node.connect(0, this, this.inputs.length - 1); - } + content: w.name, + submenu: { + options: [ + { + content: 'Input Text', + callback: () => { + this.convertWidgetToInput(w); + const node = addNode("ShellAgentPluginInputText", this, { before: true }); + const dvn = node.widgets.find(w => w.name === 'default_value') + dvn.value = w.value; + node.connect(0, this, this.inputs.length - 1); + } + } + ] + }, }) } if (["number"].indexOf(w.type) > -1) { - toInput.push({ content: w.name, submenu: { @@ -221,16 +239,66 @@ app.registerExtension({ }) } } - if (toInput.length) { options.unshift({ - content: "Convert to ShellAgent", + content: "Convert to ShellAgent (Input)", submenu: { options: toInput } }) } } + + if (this.outputs) { + let toOutput = []; + for (const o of this.outputs) { + if (o.type === 'IMAGE') { + toOutput.push({ + content: o.name, + submenu: { + options: [ + { + content: 'Save Image', + callback: () => { + const node = addNode("ShellAgentPluginSaveImage", this); + this.connect(0, node, 0); + } + }, + { + content: 'Save Images', + callback: () => { + const node = addNode("ShellAgentPluginSaveImages", this); + this.connect(0, node, 0); + } + } + ] + } + + }) + } + + if (o.type === 'STRING') { + toOutput.push({ + content: `${o.name} -> Output Text`, + callback: () => { + const node = addNode("ShellAgentPluginOutputText", this); + this.connect(0, node, 0); + } + }) + } + + } + + if (toOutput.length) { + options.unshift({ + content: "Convert to ShellAgent (Output)", + submenu: { + options: toOutput + } + }) + } + + } }) } }, From 4fb799112a391f2283f9ad5ffc89ebdb2fe2a388 Mon Sep 17 00:00:00 2001 From: shanexi Date: Sun, 27 Oct 2024 09:42:31 +0800 Subject: [PATCH 03/12] Convert to save video --- web/shellagent.js | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/web/shellagent.js b/web/shellagent.js index bd289ae..dc57a62 100644 --- a/web/shellagent.js +++ b/web/shellagent.js @@ -279,14 +279,37 @@ app.registerExtension({ if (o.type === 'STRING') { toOutput.push({ - content: `${o.name} -> Output Text`, - callback: () => { - const node = addNode("ShellAgentPluginOutputText", this); - this.connect(0, node, 0); + content: o.name, + submenu: { + options: [ + { + content: `Output Text`, + callback: () => { + const node = addNode("ShellAgentPluginOutputText", this); + this.connect(0, node, 0); + } + } + ] } }) } + if (o.type === "VHS_FILENAMES") { + toOutput.push({ + content: o.name, + submenu: { + options: [ + { + content: `Save Video - VHS`, + callback: () => { + const node = addNode("ShellAgentPluginSaveVideoVHS", this); + this.connect(0, node, 0); + } + } + ] + } + }) + } } if (toOutput.length) { From 9417b644584f50e710ee010af52f76b39e0e6701 Mon Sep 17 00:00:00 2001 From: shanexi Date: Sun, 27 Oct 2024 15:23:13 +0800 Subject: [PATCH 04/12] No need to connect image combo --- web/shellagent.js | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/web/shellagent.js b/web/shellagent.js index dc57a62..e113910 100644 --- a/web/shellagent.js +++ b/web/shellagent.js @@ -174,22 +174,10 @@ app.registerExtension({ if (nodeData.name.indexOf('ShellAgentPlugin') === -1) { addMenuHandler(nodeType, function (_, options) { + if (this.widgets) { let toInput = []; for (const w of this.widgets) { - // todo: combo need to remove and convert back - // if (w.type === 'combo' && w.name === 'image') { - // toInput.push({ - // content: `${w.name} <- Input Image`, - // callback: () => { - // this.convertWidgetToInput(w); - // const node = addNode("ShellAgentPluginInputImage", this, { before: true }); - // const dvn = node.widgets.find(w => w.name === 'default_value') - // dvn.value = w.value; - // node.connect(0, this, 0); - // } - // }) - // } if (["customtext"].indexOf(w.type) > -1) { toInput.push({ content: w.name, From 710104d709d4d85d7fc95cfc8adebce47e5f1e6f Mon Sep 17 00:00:00 2001 From: shanexi Date: Sun, 27 Oct 2024 16:02:48 +0800 Subject: [PATCH 05/12] Image input --- web/shellagent.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/web/shellagent.js b/web/shellagent.js index e113910..d59ef83 100644 --- a/web/shellagent.js +++ b/web/shellagent.js @@ -313,6 +313,12 @@ app.registerExtension({ }) } }, + + afterConfigureGraph(missingNodeTypes, app) { + const type = 'IMAGE' + const nodeId = 'ShellAgentPluginInputImage' + LiteGraph.slot_types_default_in[type].unshift(nodeId) + } }); function addMenuHandler(nodeType, cb) { From ae8ed607674294b8fab5ff096c9c909723d80c57 Mon Sep 17 00:00:00 2001 From: shanexi Date: Mon, 28 Oct 2024 09:52:28 +0800 Subject: [PATCH 06/12] Save Image(s) on output connect pop menu --- web/shellagent.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web/shellagent.js b/web/shellagent.js index d59ef83..38df820 100644 --- a/web/shellagent.js +++ b/web/shellagent.js @@ -302,7 +302,7 @@ app.registerExtension({ if (toOutput.length) { options.unshift({ - content: "Convert to ShellAgent (Output)", + content: "Connect to ShellAgent (Output)", submenu: { options: toOutput } @@ -315,9 +315,9 @@ app.registerExtension({ }, afterConfigureGraph(missingNodeTypes, app) { - const type = 'IMAGE' - const nodeId = 'ShellAgentPluginInputImage' - LiteGraph.slot_types_default_in[type].unshift(nodeId) + LiteGraph.slot_types_default_in['IMAGE'].unshift('ShellAgentPluginInputImage') + LiteGraph.slot_types_default_out['IMAGE'].unshift('ShellAgentPluginSaveImage') + LiteGraph.slot_types_default_out['IMAGE'].unshift('ShellAgentPluginSaveImages') } }); From b825b62a96816d5a13126d2347bcba3bcdfef557 Mon Sep 17 00:00:00 2001 From: shanexi Date: Mon, 28 Oct 2024 10:09:38 +0800 Subject: [PATCH 07/12] Drag to connect output text float integer --- web/shellagent.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/web/shellagent.js b/web/shellagent.js index 38df820..e6ae1e6 100644 --- a/web/shellagent.js +++ b/web/shellagent.js @@ -37,11 +37,15 @@ app.registerExtension({ }); }, async beforeRegisterNodeDef(nodeType, nodeData, app) { + if (["ShellAgentPluginOutputText", "ShellAgentPluginOutputFloat", "ShellAgentPluginOutputInteger"].indexOf(nodeData.name) > -1) { + chainCallback(nodeType.prototype, "onNodeCreated", function () { + this.convertWidgetToInput(this.widgets[0]) + }) + } if (["ShellAgentPluginInputText", "ShellAgentPluginInputFloat", "ShellAgentPluginInputInteger"].indexOf(nodeData.name) > -1) { chainCallback(nodeType.prototype, "onNodeCreated", function () { const widget = this.widgets.find(w => w.name === 'choices') - this.addWidget('button', 'manage choices', null, () => { const container = document.createElement("div"); Object.assign(container.style, { @@ -318,6 +322,10 @@ app.registerExtension({ LiteGraph.slot_types_default_in['IMAGE'].unshift('ShellAgentPluginInputImage') LiteGraph.slot_types_default_out['IMAGE'].unshift('ShellAgentPluginSaveImage') LiteGraph.slot_types_default_out['IMAGE'].unshift('ShellAgentPluginSaveImages') + + LiteGraph.slot_types_default_out['STRING'].unshift('ShellAgentPluginOutputFloat') + LiteGraph.slot_types_default_out['STRING'].unshift('ShellAgentPluginOutputInteger') + LiteGraph.slot_types_default_out['STRING'].unshift('ShellAgentPluginOutputText') } }); From cbd714d9ea8753f7e82ddd55814fcbe6f5c1617a Mon Sep 17 00:00:00 2001 From: shanexi Date: Mon, 28 Oct 2024 11:02:18 +0800 Subject: [PATCH 08/12] Replace Load Image with ShellAgent Input Image --- web/shellagent.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/web/shellagent.js b/web/shellagent.js index e6ae1e6..1389d9a 100644 --- a/web/shellagent.js +++ b/web/shellagent.js @@ -141,6 +141,22 @@ app.registerExtension({ }) } + if (['LoadImage', 'LoadImageMask'].indexOf(nodeData.name) > -1) { + addMenuHandler(nodeType, function (_, options) { + options.unshift({ + content: "Replace with ShellAgent Input Image", + callback: () => { + const node = addNode("ShellAgentPluginInputImage", this, { before: true }); + app.graph.links.filter(l => l != null) + .forEach(l => { + const tn = app.graph._nodes_by_id[l.target_id] + node.connect(0, tn, 0) + }) + } + }) + }) + } + if (nodeData.name === "ShellAgentPluginInputImage") { if ( nodeData?.input?.required?.default_value?.[1]?.image_upload === true @@ -155,7 +171,6 @@ app.registerExtension({ if (nodeData.name === "ShellAgentPluginInputVideo") { addUploadWidget(nodeType, nodeData, "default_value"); chainCallback(nodeType.prototype, "onNodeCreated", function () { - // const pathWidget = this.widgets.find((w) => w.name === "video"); const pathWidget = this.widgets.find((w) => w.name === "default_value"); chainCallback(pathWidget, "callback", (value) => { if (!value) { From f9a3ce43f52a90aa937802aaed6d483b4fa5fb99 Mon Sep 17 00:00:00 2001 From: shanexi Date: Mon, 28 Oct 2024 11:09:29 +0800 Subject: [PATCH 09/12] Replace and remove --- web/shellagent.js | 1 + 1 file changed, 1 insertion(+) diff --git a/web/shellagent.js b/web/shellagent.js index 1389d9a..1754953 100644 --- a/web/shellagent.js +++ b/web/shellagent.js @@ -152,6 +152,7 @@ app.registerExtension({ const tn = app.graph._nodes_by_id[l.target_id] node.connect(0, tn, 0) }) + app.graph.remove(this); } }) }) From 20fcbb2e48c1880d1da00ad5bc7d74cc64eb9166 Mon Sep 17 00:00:00 2001 From: shanexi Date: Mon, 28 Oct 2024 11:14:05 +0800 Subject: [PATCH 10/12] Fix duplicated drag menu item --- web/shellagent.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/web/shellagent.js b/web/shellagent.js index 1754953..629773d 100644 --- a/web/shellagent.js +++ b/web/shellagent.js @@ -335,13 +335,24 @@ app.registerExtension({ }, afterConfigureGraph(missingNodeTypes, app) { - LiteGraph.slot_types_default_in['IMAGE'].unshift('ShellAgentPluginInputImage') - LiteGraph.slot_types_default_out['IMAGE'].unshift('ShellAgentPluginSaveImage') - LiteGraph.slot_types_default_out['IMAGE'].unshift('ShellAgentPluginSaveImages') + function addIn(type, nodeId) { + if (LiteGraph.slot_types_default_in[type].indexOf(nodeId) === -1) { + LiteGraph.slot_types_default_in[type].unshift(nodeId) + } + } - LiteGraph.slot_types_default_out['STRING'].unshift('ShellAgentPluginOutputFloat') - LiteGraph.slot_types_default_out['STRING'].unshift('ShellAgentPluginOutputInteger') - LiteGraph.slot_types_default_out['STRING'].unshift('ShellAgentPluginOutputText') + function addOut(type, nodeId) { + if (LiteGraph.slot_types_default_out[type].indexOf(nodeId) === -1) { + LiteGraph.slot_types_default_out[type].unshift(nodeId) + } + } + + addIn('IMAGE', 'ShellAgentPluginInputImage') + addOut('IMAGE', 'ShellAgentPluginSaveImage') + addOut('IMAGE', 'ShellAgentPluginSaveImages') + addOut('STRING', 'ShellAgentPluginOutputFloat') + addOut('STRING', 'ShellAgentPluginOutputInteger') + addOut('STRING', 'ShellAgentPluginOutputText') } }); From fffc29fc2b62990a81ce5fffbb749e278e885511 Mon Sep 17 00:00:00 2001 From: shanexi Date: Mon, 28 Oct 2024 11:15:39 +0800 Subject: [PATCH 11/12] Add missing convert output --- web/shellagent.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/web/shellagent.js b/web/shellagent.js index 629773d..6504ae7 100644 --- a/web/shellagent.js +++ b/web/shellagent.js @@ -296,6 +296,20 @@ app.registerExtension({ const node = addNode("ShellAgentPluginOutputText", this); this.connect(0, node, 0); } + }, + { + content: `Output Float`, + callback: () => { + const node = addNode("ShellAgentPluginOutputFloat", this); + this.connect(0, node, 0); + } + }, + { + content: `Output Integer`, + callback: () => { + const node = addNode("ShellAgentPluginOutputInteger", this); + this.connect(0, node, 0); + } } ] } @@ -350,8 +364,8 @@ app.registerExtension({ addIn('IMAGE', 'ShellAgentPluginInputImage') addOut('IMAGE', 'ShellAgentPluginSaveImage') addOut('IMAGE', 'ShellAgentPluginSaveImages') - addOut('STRING', 'ShellAgentPluginOutputFloat') addOut('STRING', 'ShellAgentPluginOutputInteger') + addOut('STRING', 'ShellAgentPluginOutputFloat') addOut('STRING', 'ShellAgentPluginOutputText') } }); From f28c2c6b31994bd5c0842f12b9e8ccc5741bb917 Mon Sep 17 00:00:00 2001 From: shanexi Date: Mon, 28 Oct 2024 11:20:03 +0800 Subject: [PATCH 12/12] Replace with default value assigned --- web/shellagent.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/web/shellagent.js b/web/shellagent.js index 6504ae7..79be03e 100644 --- a/web/shellagent.js +++ b/web/shellagent.js @@ -147,6 +147,10 @@ app.registerExtension({ content: "Replace with ShellAgent Input Image", callback: () => { const node = addNode("ShellAgentPluginInputImage", this, { before: true }); + + const dvn = node.widgets.find(w => w.name === 'default_value') + dvn.value = this.widgets.find(w => w.name === 'image')?.value + app.graph.links.filter(l => l != null) .forEach(l => { const tn = app.graph._nodes_by_id[l.target_id]