mirror of
https://github.com/justUmen/Bjornulf_custom_nodes.git
synced 2026-03-21 20:52:11 -03:00
0.57
This commit is contained in:
@@ -1,111 +1,192 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
import { api } from "../../../scripts/api.js";
|
||||
|
||||
app.registerExtension({
|
||||
name: "Bjornulf.LoopLinesSequential",
|
||||
async nodeCreated(node) {
|
||||
if (node.comfyClass !== "Bjornulf_LoopLinesSequential") return;
|
||||
name: "Bjornulf.LoopLinesSequential",
|
||||
async nodeCreated(node) {
|
||||
if (node.comfyClass !== "Bjornulf_LoopLinesSequential") return;
|
||||
|
||||
// Hide seed widget
|
||||
const seedWidget = node.widgets.find(w => w.name === "seed");
|
||||
if (seedWidget) {
|
||||
seedWidget.visible = false;
|
||||
}
|
||||
|
||||
// Add line number display
|
||||
const lineNumberWidget = node.addWidget("html", "Current Line: --", null, {
|
||||
callback: () => {},
|
||||
});
|
||||
|
||||
// Function to update line number display
|
||||
const updateLineNumber = () => {
|
||||
fetch('/get_current_line')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
lineNumberWidget.value = `Current Line: ${data.value}`;
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error getting line number:', error);
|
||||
});
|
||||
};
|
||||
|
||||
// Add increment button
|
||||
const incrementButton = node.addWidget("button", "+1", null, () => {
|
||||
fetch('/increment_lines_counter', {
|
||||
method: 'POST'
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
updateLineNumber();
|
||||
app.ui.toast("Counter incremented", {'duration': 3000});
|
||||
} else {
|
||||
app.ui.toast(`Failed to increment counter: ${data.error || "Unknown error"}`, {'type': 'error', 'duration': 5000});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error);
|
||||
app.ui.toast("An error occurred while incrementing the counter.", {'type': 'error', 'duration': 5000});
|
||||
});
|
||||
});
|
||||
|
||||
// Add decrement button
|
||||
const decrementButton = node.addWidget("button", "-1", null, () => {
|
||||
fetch('/decrement_lines_counter', {
|
||||
method: 'POST'
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
updateLineNumber();
|
||||
app.ui.toast("Counter decremented", {'duration': 3000});
|
||||
} else {
|
||||
app.ui.toast(`Failed to decrement counter: ${data.error || "Unknown error"}`, {'type': 'error', 'duration': 5000});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error);
|
||||
app.ui.toast("An error occurred while decrementing the counter.", {'type': 'error', 'duration': 5000});
|
||||
});
|
||||
});
|
||||
|
||||
// Add reset button
|
||||
const resetButton = node.addWidget("button", "Reset Counter", null, () => {
|
||||
fetch('/reset_lines_counter', {
|
||||
method: 'POST'
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
updateLineNumber();
|
||||
app.ui.toast("Counter reset successfully!", {'duration': 5000});
|
||||
} else {
|
||||
app.ui.toast(`Failed to reset counter: ${data.error || "Unknown error"}`, {'type': 'error', 'duration': 5000});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error);
|
||||
app.ui.toast("An error occurred while resetting the counter.", {'type': 'error', 'duration': 5000});
|
||||
});
|
||||
});
|
||||
|
||||
// Update line number periodically
|
||||
setInterval(updateLineNumber, 1000);
|
||||
|
||||
// Override the original execute function
|
||||
const originalExecute = node.execute;
|
||||
node.execute = function() {
|
||||
const result = originalExecute.apply(this, arguments);
|
||||
if (result instanceof Promise) {
|
||||
return result.catch(error => {
|
||||
if (error.message.includes("Counter has reached its limit")) {
|
||||
app.ui.toast(`Execution blocked: ${error.message}`, {'type': 'error', 'duration': 5000});
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
return result;
|
||||
};
|
||||
// Hide seed widget
|
||||
const seedWidget = node.widgets.find((w) => w.name === "seed");
|
||||
if (seedWidget) {
|
||||
seedWidget.visible = false;
|
||||
}
|
||||
});
|
||||
|
||||
// Add line number display
|
||||
const lineNumberWidget = node.addWidget("html", "Current Line: --", null, {
|
||||
callback: () => {},
|
||||
});
|
||||
|
||||
// Function to update the Reset Button text
|
||||
const updateResetButtonTextNode = () => {
|
||||
fetch("/get_current_line_number", {
|
||||
method: "POST",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (data.success) {
|
||||
const jumpWidget = node.widgets.find((w) => w.name === "jump");
|
||||
if (data.value === 0) {
|
||||
resetButton.name =
|
||||
"Reset Counter (Empty, next: " + jumpWidget.value + ")";
|
||||
} else {
|
||||
//Add to data.value, the current jump value
|
||||
let next_value = data.value + jumpWidget.value;
|
||||
// console.log(jumpWidget);
|
||||
resetButton.name = `Reset Counter (next: ${next_value})`;
|
||||
}
|
||||
} else {
|
||||
console.error("Error in context size:", data.error);
|
||||
resetButton.name = "Reset Counter (Error)";
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching context size:", error);
|
||||
resetButton.name = "Reset Counter (Error)";
|
||||
});
|
||||
};
|
||||
|
||||
// Add reset button
|
||||
const resetButton = node.addWidget("button", "Reset Counter", null, () => {
|
||||
fetch("/reset_lines_counter", {
|
||||
method: "POST",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (data.success) {
|
||||
// updateLineNumber();
|
||||
updateResetButtonTextNode();
|
||||
app.ui.toast("Counter reset successfully!", { duration: 5000 });
|
||||
} else {
|
||||
app.ui.toast(
|
||||
`Failed to reset counter: ${data.error || "Unknown error"}`,
|
||||
{ type: "error", duration: 5000 }
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error:", error);
|
||||
app.ui.toast("An error occurred while resetting the counter.", {
|
||||
type: "error",
|
||||
duration: 5000,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Add increment button
|
||||
const incrementButton = node.addWidget("button", "+1", null, () => {
|
||||
fetch("/increment_lines_counter", {
|
||||
method: "POST",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (data.success) {
|
||||
updateResetButtonTextNode();
|
||||
app.ui.toast("Counter incremented", { duration: 3000 });
|
||||
} else {
|
||||
app.ui.toast(
|
||||
`Failed to increment counter: ${data.error || "Unknown error"}`,
|
||||
{ type: "error", duration: 5000 }
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error:", error);
|
||||
app.ui.toast("An error occurred while incrementing the counter.", {
|
||||
type: "error",
|
||||
duration: 5000,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Add decrement button
|
||||
const decrementButton = node.addWidget("button", "-1", null, () => {
|
||||
fetch("/decrement_lines_counter", {
|
||||
method: "POST",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (data.success) {
|
||||
updateResetButtonTextNode();
|
||||
app.ui.toast("Counter decremented", { duration: 3000 });
|
||||
} else {
|
||||
app.ui.toast(
|
||||
`Failed to decrement counter: ${data.error || "Unknown error"}`,
|
||||
{ type: "error", duration: 5000 }
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error:", error);
|
||||
app.ui.toast("An error occurred while decrementing the counter.", {
|
||||
type: "error",
|
||||
duration: 5000,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Add reset button
|
||||
// const resetButton = node.addWidget("button", "Reset Counter", null, () => {
|
||||
// fetch("/reset_lines_counter", {
|
||||
// method: "POST",
|
||||
// })
|
||||
// .then((response) => response.json())
|
||||
// .then((data) => {
|
||||
// if (data.success) {
|
||||
// updateLineNumber();
|
||||
// app.ui.toast("Counter reset successfully!", { duration: 5000 });
|
||||
// } else {
|
||||
// app.ui.toast(
|
||||
// `Failed to reset counter: ${data.error || "Unknown error"}`,
|
||||
// { type: "error", duration: 5000 }
|
||||
// );
|
||||
// }
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// console.error("Error:", error);
|
||||
// app.ui.toast("An error occurred while resetting the counter.", {
|
||||
// type: "error",
|
||||
// duration: 5000,
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// Update line number periodically
|
||||
setTimeout(updateResetButtonTextNode, 0);
|
||||
|
||||
// Listen for node execution events
|
||||
api.addEventListener("executed", async () => {
|
||||
updateResetButtonTextNode();
|
||||
});
|
||||
|
||||
// Add a handler for the jump widget
|
||||
const waitingWidget = node.widgets.find((w) => w.name === "jump");
|
||||
if (waitingWidget) {
|
||||
const originalOnChange = waitingWidget.callback;
|
||||
waitingWidget.callback = function (v) {
|
||||
if (originalOnChange) {
|
||||
originalOnChange.call(this, v);
|
||||
}
|
||||
updateResetButtonTextNode();
|
||||
};
|
||||
}
|
||||
|
||||
// Override the original execute function
|
||||
const originalExecute = node.execute;
|
||||
node.execute = function () {
|
||||
const result = originalExecute.apply(this, arguments);
|
||||
if (result instanceof Promise) {
|
||||
return result.catch((error) => {
|
||||
if (error.message.includes("Counter has reached its limit")) {
|
||||
app.ui.toast(`Execution blocked: ${error.message}`, {
|
||||
type: "error",
|
||||
duration: 5000,
|
||||
});
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
return result;
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,65 +1,171 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
import { api } from "../../../scripts/api.js";
|
||||
|
||||
// Add CSS style for the black background button class
|
||||
const style = document.createElement("style");
|
||||
style.textContent = `
|
||||
.reset-button-exceeded {
|
||||
background-color: black !important;
|
||||
color: white !important;
|
||||
}
|
||||
`;
|
||||
|
||||
app.registerExtension({
|
||||
name: "Bjornulf.LoopIntegerSequential",
|
||||
async nodeCreated(node) {
|
||||
if (node.comfyClass !== "Bjornulf_LoopIntegerSequential") return;
|
||||
name: "Bjornulf.LoopIntegerSequential",
|
||||
async nodeCreated(node) {
|
||||
if (node.comfyClass !== "Bjornulf_LoopIntegerSequential") return;
|
||||
|
||||
// Hide seed widget
|
||||
const seedWidget = node.widgets.find(w => w.name === "seed");
|
||||
if (seedWidget) {
|
||||
seedWidget.visible = false;
|
||||
}
|
||||
|
||||
// Add get value button
|
||||
// const getValueButton = node.addWidget("button", "Get Counter Value", null, () => {
|
||||
// fetch('/get_counter_value')
|
||||
// .then(response => response.json())
|
||||
// .then(data => {
|
||||
// if (data.success) {
|
||||
// app.ui.toast(`Current counter value: ${data.value}`, {'duration': 5000});
|
||||
// } else {
|
||||
// app.ui.toast(`Failed to get counter value: ${data.error || "Unknown error"}`, {'type': 'error', 'duration': 5000});
|
||||
// }
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// console.error('Error:', error);
|
||||
// app.ui.toast("An error occurred while getting the counter value.", {'type': 'error', 'duration': 5000});
|
||||
// });
|
||||
// });
|
||||
|
||||
// Add reset button
|
||||
const resetButton = node.addWidget("button", "Reset Counter", null, () => {
|
||||
fetch('/reset_counter', {
|
||||
method: 'POST'
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
app.ui.toast("Counter reset successfully!", {'duration': 5000});
|
||||
} else {
|
||||
app.ui.toast(`Failed to reset counter: ${data.error || "Unknown error"}`, {'type': 'error', 'duration': 5000});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error);
|
||||
app.ui.toast("An error occurred while resetting the counter.", {'type': 'error', 'duration': 5000});
|
||||
});
|
||||
});
|
||||
|
||||
// Override the original execute function
|
||||
const originalExecute = node.execute;
|
||||
node.execute = function() {
|
||||
const result = originalExecute.apply(this, arguments);
|
||||
if (result instanceof Promise) {
|
||||
return result.catch(error => {
|
||||
if (error.message.includes("Counter has reached its limit")) {
|
||||
app.ui.toast(`Execution blocked: ${error.message}`, {'type': 'error', 'duration': 5000});
|
||||
}
|
||||
throw error; // Re-throw the error to stop further execution
|
||||
});
|
||||
}
|
||||
return result;
|
||||
};
|
||||
// Hide seed widget
|
||||
const seedWidget = node.widgets.find((w) => w.name === "seed");
|
||||
if (seedWidget) {
|
||||
seedWidget.visible = false;
|
||||
}
|
||||
});
|
||||
|
||||
// Function to update the Reset Button text
|
||||
const updateResetButtonTextNode = () => {
|
||||
fetch("/get_counter_value", {
|
||||
method: "POST",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (data.success) {
|
||||
const jumpWidget = node.widgets.find((w) => w.name === "jump");
|
||||
const fromThisWidget = node.widgets.find(
|
||||
(w) => w.name === "from_this"
|
||||
);
|
||||
if (data.value === 0) {
|
||||
resetButton.name =
|
||||
"Reset Counter (Empty, next: " + fromThisWidget.value + ")";
|
||||
} else {
|
||||
const toThatWidget = node.widgets.find(
|
||||
(w) => w.name === "to_that"
|
||||
);
|
||||
let next_value = data.value + jumpWidget.value - 1;
|
||||
if (next_value > toThatWidget.value) {
|
||||
resetButton.name = `Reset Counter (ABOVE MAX: ${next_value} > ${toThatWidget.value})`;
|
||||
console.log("resetButton", resetButton);
|
||||
} else {
|
||||
resetButton.name = `Reset Counter (next: ${next_value})`; // - ${toThatWidget.value}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.error("Error in context size:", data.error);
|
||||
resetButton.name = "Reset Counter (Error)";
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching context size:", error);
|
||||
resetButton.name = "Reset Counter (Error)";
|
||||
});
|
||||
};
|
||||
|
||||
// Add reset button
|
||||
const resetButton = node.addWidget("button", "Reset Counter", null, () => {
|
||||
fetch("/reset_counter", {
|
||||
method: "POST",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (data.success) {
|
||||
// updateLineNumber();
|
||||
updateResetButtonTextNode();
|
||||
app.ui.toast("Counter reset successfully!", { duration: 5000 });
|
||||
} else {
|
||||
app.ui.toast(
|
||||
`Failed to reset counter: ${data.error || "Unknown error"}`,
|
||||
{ type: "error", duration: 5000 }
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error:", error);
|
||||
app.ui.toast("An error occurred while resetting the counter.", {
|
||||
type: "error",
|
||||
duration: 5000,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Override the original execute function
|
||||
const originalExecute = node.execute;
|
||||
node.execute = function () {
|
||||
const result = originalExecute.apply(this, arguments);
|
||||
if (result instanceof Promise) {
|
||||
return result.catch((error) => {
|
||||
if (error.message.includes("Counter has reached its limit")) {
|
||||
app.ui.toast(`Execution blocked: ${error.message}`, {
|
||||
type: "error",
|
||||
duration: 5000,
|
||||
});
|
||||
}
|
||||
throw error; // Re-throw the error to stop further execution
|
||||
});
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
// Initial update of showing counter number
|
||||
setTimeout(updateResetButtonTextNode, 0);
|
||||
|
||||
// Listen for node execution events (update value when node executed)
|
||||
api.addEventListener("executed", async () => {
|
||||
updateResetButtonTextNode();
|
||||
});
|
||||
|
||||
// Add a handler for the jump widget (update value reset on change)
|
||||
const jumpWidget = node.widgets.find((w) => w.name === "jump");
|
||||
if (jumpWidget) {
|
||||
const originalOnChange = jumpWidget.callback;
|
||||
jumpWidget.callback = function (v) {
|
||||
if (originalOnChange) {
|
||||
originalOnChange.call(this, v);
|
||||
}
|
||||
updateResetButtonTextNode();
|
||||
};
|
||||
}
|
||||
// Add a handler for the to_that widget (update value reset on change)
|
||||
const toThatWidget = node.widgets.find((w) => w.name === "to_that");
|
||||
if (toThatWidget) {
|
||||
const originalOnChange = toThatWidget.callback;
|
||||
toThatWidget.callback = function (v) {
|
||||
if (originalOnChange) {
|
||||
originalOnChange.call(this, v);
|
||||
}
|
||||
updateResetButtonTextNode();
|
||||
};
|
||||
}
|
||||
// Add a handler for the to_that widget (on change from_this => reset button)
|
||||
const fromThisWidget = node.widgets.find((w) => w.name === "from_this");
|
||||
if (fromThisWidget) {
|
||||
const originalOnChange = fromThisWidget.callback;
|
||||
fromThisWidget.callback = function (v) {
|
||||
if (originalOnChange) {
|
||||
originalOnChange.call(this, v);
|
||||
}
|
||||
fetch("/reset_counter", {
|
||||
method: "POST",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (data.success) {
|
||||
// updateLineNumber();
|
||||
updateResetButtonTextNode();
|
||||
app.ui.toast("Counter reset successfully!", { duration: 5000 });
|
||||
} else {
|
||||
app.ui.toast(
|
||||
`Failed to reset counter: ${data.error || "Unknown error"}`,
|
||||
{ type: "error", duration: 5000 }
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error:", error);
|
||||
app.ui.toast("An error occurred while resetting the counter.", {
|
||||
type: "error",
|
||||
duration: 5000,
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
54
web/js/ollama_config_selector.js
Normal file
54
web/js/ollama_config_selector.js
Normal file
@@ -0,0 +1,54 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
|
||||
app.registerExtension({
|
||||
name: "Bjornulf.OllamaConfig",
|
||||
async nodeCreated(node) {
|
||||
if (node.comfyClass === "Bjornulf_OllamaConfig") {
|
||||
// Add model_list combo widget
|
||||
const modelListWidget = node.addWidget(
|
||||
"combo",
|
||||
"select_model_here",
|
||||
"",
|
||||
(v) => {
|
||||
// When model_list changes, update model_name
|
||||
const modelNameWidget = node.widgets.find(w => w.name === "model_name");
|
||||
if (modelNameWidget) {
|
||||
modelNameWidget.value = v;
|
||||
}
|
||||
},
|
||||
{ values: [] }
|
||||
);
|
||||
|
||||
// Add update button
|
||||
node.addCustomWidget({
|
||||
name: "Update model_list",
|
||||
type: "button",
|
||||
value: "Update Models",
|
||||
callback: async function() {
|
||||
try {
|
||||
const url = node.widgets.find(w => w.name === "ollama_url").value;
|
||||
const response = await fetch(`${url}/api/tags`);
|
||||
const data = await response.json();
|
||||
|
||||
if (data.models) {
|
||||
const modelNames = data.models.map(m => m.name);
|
||||
if (modelNames.length > 0) {
|
||||
// Update model_list widget
|
||||
modelListWidget.options.values = modelNames;
|
||||
modelListWidget.value = modelNames[0];
|
||||
|
||||
// Update model_name widget
|
||||
const modelNameWidget = node.widgets.find(w => w.name === "model_name");
|
||||
if (modelNameWidget) {
|
||||
modelNameWidget.value = modelNames[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error updating models:', error);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
197
web/js/ollama_talk.js
Normal file
197
web/js/ollama_talk.js
Normal file
@@ -0,0 +1,197 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
import { api } from "../../../scripts/api.js";
|
||||
|
||||
// Node-specific logic
|
||||
app.registerExtension({
|
||||
name: "Bjornulf.OllamaTalk",
|
||||
async nodeCreated(node) {
|
||||
if (node.comfyClass === "Bjornulf_OllamaTalk") {
|
||||
// Set seed widget to hidden input
|
||||
const seedWidget = node.widgets.find((w) => w.name === "seed");
|
||||
if (seedWidget) {
|
||||
seedWidget.type = "HIDDEN";
|
||||
}
|
||||
|
||||
// Function to update the Reset Button text
|
||||
const updateResetButtonTextNode = () => {
|
||||
fetch("/get_current_context_size", {
|
||||
method: "POST",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (data.success) {
|
||||
if (data.value === 0) {
|
||||
resetButton.name = "Save/Reset Context File (Empty)";
|
||||
} else {
|
||||
resetButton.name = `Save/Reset Context File (${data.value} lines)`;
|
||||
}
|
||||
} else {
|
||||
console.error("Error in context size:", data.error);
|
||||
resetButton.name = "Save/Reset Context File (Error)";
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching context size:", error);
|
||||
resetButton.name = "Save/Reset Context File (Error)";
|
||||
});
|
||||
};
|
||||
|
||||
// Add reset button
|
||||
const resetButton = node.addWidget(
|
||||
"button",
|
||||
"Save/Reset Context File",
|
||||
null,
|
||||
() => {
|
||||
fetch("/reset_lines_context", {
|
||||
method: "POST",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (data.success) {
|
||||
// updateLineNumber();
|
||||
updateResetButtonTextNode();
|
||||
app.ui.toast("Counter reset successfully!", { duration: 5000 });
|
||||
} else {
|
||||
app.ui.toast(
|
||||
`Failed to reset counter: ${data.error || "Unknown error"}`,
|
||||
{ type: "error", duration: 5000 }
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error:", error);
|
||||
app.ui.toast("An error occurred while resetting the counter.", {
|
||||
type: "error",
|
||||
duration: 5000,
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
// Add resume button
|
||||
const resumeButton = node.addWidget("button", "Resume", "Resume", () => {
|
||||
const workflow = app.graph.serialize();
|
||||
const nodeData = workflow.nodes.find((n) => n.id === node.id);
|
||||
const userPromptValue =
|
||||
nodeData.widgets_values?.[
|
||||
node.widgets.findIndex((w) => w.name === "user_prompt")
|
||||
];
|
||||
|
||||
fetch("/bjornulf_ollama_send_prompt", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
node_id: node.id,
|
||||
user_prompt: userPromptValue,
|
||||
}),
|
||||
})
|
||||
.then((response) => response.text())
|
||||
.then((data) => {
|
||||
console.log("Resume response:", data);
|
||||
})
|
||||
.catch((error) => console.error("Error:", error));
|
||||
});
|
||||
|
||||
// Function to update button visibility based on widget values
|
||||
const updateButtonVisibility = () => {
|
||||
// Check context file widget
|
||||
const contextWidget = node.widgets.find(
|
||||
(w) => w.name === "use_context_file"
|
||||
);
|
||||
const isContextFileEnabled = contextWidget
|
||||
? contextWidget.value
|
||||
: false;
|
||||
resetButton.type = isContextFileEnabled ? "button" : "HIDDEN";
|
||||
|
||||
// Check waiting for prompt widget
|
||||
const waitingWidget = node.widgets.find(
|
||||
(w) => w.name === "waiting_for_prompt"
|
||||
);
|
||||
const isWaitingForPrompt = waitingWidget ? waitingWidget.value : false;
|
||||
resumeButton.type = isWaitingForPrompt ? "button" : "HIDDEN";
|
||||
|
||||
//ALSO update reset button text node
|
||||
updateResetButtonTextNode(); // Will trigger when... toggle / refresh page
|
||||
|
||||
// Force canvas redraw to update UI
|
||||
node.setDirtyCanvas(true);
|
||||
};
|
||||
|
||||
// Add a handler for the use_context_file widget
|
||||
const contextWidget = node.widgets.find(
|
||||
(w) => w.name === "use_context_file"
|
||||
);
|
||||
if (contextWidget) {
|
||||
const originalOnChange = contextWidget.callback;
|
||||
contextWidget.callback = function (v) {
|
||||
if (originalOnChange) {
|
||||
originalOnChange.call(this, v);
|
||||
}
|
||||
updateButtonVisibility();
|
||||
};
|
||||
}
|
||||
|
||||
// Add a handler for the waiting_for_prompt widget
|
||||
const waitingWidget = node.widgets.find(
|
||||
(w) => w.name === "waiting_for_prompt"
|
||||
);
|
||||
if (waitingWidget) {
|
||||
const originalOnChange = waitingWidget.callback;
|
||||
waitingWidget.callback = function (v) {
|
||||
if (originalOnChange) {
|
||||
originalOnChange.call(this, v);
|
||||
}
|
||||
updateButtonVisibility();
|
||||
};
|
||||
}
|
||||
|
||||
// Initial update of button visibility
|
||||
setTimeout(updateButtonVisibility, 0);
|
||||
|
||||
// Listen for node execution events
|
||||
api.addEventListener("executed", async () => {
|
||||
updateResetButtonTextNode();
|
||||
});
|
||||
|
||||
//If workflow is stopped during pause, cancel the run
|
||||
const original_api_interrupt = api.interrupt;
|
||||
api.interrupt = function () {
|
||||
api.fetchApi('/bjornulf_ollama_interrupt', {
|
||||
method: 'POST'
|
||||
});
|
||||
original_api_interrupt.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// // Add listener for workflow execution
|
||||
// app.addEventListener("workflowExecuted", () => {
|
||||
// if (node.graph.isPlaying) {
|
||||
// updateContextSize();
|
||||
// }
|
||||
// });
|
||||
// app.registerExtension({
|
||||
// name: "Bjornulf.OllamaContextChat",
|
||||
// async nodeCreated(node) {
|
||||
// if (node.comfyClass === "Bjornulf_OllamaContextChat") {
|
||||
// const resumeButton = node.addWidget("button", "Resume", "Resume", () => {
|
||||
// fetch('/bjornulf_ollama_send_prompt', { method: 'GET' })
|
||||
// .then(response => response.text())
|
||||
// .then(data => {
|
||||
// console.log('Resume response:', data);
|
||||
// // You can update the UI here if needed
|
||||
// })
|
||||
// .catch(error => console.error('Error:', error));
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
// Set seed widget to hidden input
|
||||
// const seedWidget = node.widgets.find((w) => w.name === "seed");
|
||||
// if (seedWidget) {
|
||||
// seedWidget.type = "HIDDEN";
|
||||
// }
|
||||
@@ -1,76 +0,0 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
import { ComfyWidgets } from "../../../scripts/widgets.js";
|
||||
|
||||
// Styles for the text area
|
||||
const textAreaStyles = {
|
||||
readOnly: true,
|
||||
opacity: 1,
|
||||
padding: '10px',
|
||||
border: '1px solid #ccc',
|
||||
borderRadius: '5px',
|
||||
backgroundColor: '#222',
|
||||
color: 'Lime',
|
||||
fontFamily: 'Arial, sans-serif',
|
||||
fontSize: '14px',
|
||||
lineHeight: '1.4',
|
||||
resize: 'vertical',
|
||||
overflowY: 'auto',
|
||||
};
|
||||
|
||||
// Displays input text on a node
|
||||
app.registerExtension({
|
||||
name: "Bjornulf.ShowFloat",
|
||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
if (nodeData.name === "Bjornulf_ShowFloat") {
|
||||
function createStyledTextArea(text) {
|
||||
const widget = ComfyWidgets["STRING"](this, "text", ["STRING", { multiline: true }], app).widget;
|
||||
widget.inputEl.readOnly = true;
|
||||
const textArea = widget.inputEl;
|
||||
|
||||
Object.assign(textArea.style, textAreaStyles);
|
||||
textArea.classList.add('bjornulf-show-text');
|
||||
widget.value = text;
|
||||
return widget;
|
||||
}
|
||||
|
||||
function populate(text) {
|
||||
if (this.widgets) {
|
||||
for (let i = 1; i < this.widgets.length; i++) {
|
||||
this.widgets[i].onRemove?.();
|
||||
}
|
||||
this.widgets.length = 1;
|
||||
}
|
||||
|
||||
const v = Array.isArray(text) ? text : [text];
|
||||
for (const list of v) {
|
||||
if (list) {
|
||||
createStyledTextArea.call(this, list);
|
||||
}
|
||||
}
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
const sz = this.computeSize();
|
||||
if (sz[0] < this.size[0]) sz[0] = this.size[0];
|
||||
if (sz[1] < this.size[1]) sz[1] = this.size[1];
|
||||
this.onResize?.(sz);
|
||||
app.graph.setDirtyCanvas(true, false);
|
||||
});
|
||||
}
|
||||
|
||||
// When the node is executed we will be sent the input text, display this in the widget
|
||||
const onExecuted = nodeType.prototype.onExecuted;
|
||||
nodeType.prototype.onExecuted = function (message) {
|
||||
onExecuted?.apply(this, arguments);
|
||||
populate.call(this, message.text);
|
||||
};
|
||||
|
||||
const onConfigure = nodeType.prototype.onConfigure;
|
||||
nodeType.prototype.onConfigure = function () {
|
||||
onConfigure?.apply(this, arguments);
|
||||
if (this.widgets_values?.length) {
|
||||
populate.call(this, this.widgets_values);
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -1,76 +0,0 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
import { ComfyWidgets } from "../../../scripts/widgets.js";
|
||||
|
||||
// Styles for the text area
|
||||
const textAreaStyles = {
|
||||
readOnly: true,
|
||||
opacity: 1,
|
||||
padding: '10px',
|
||||
border: '1px solid #ccc',
|
||||
borderRadius: '5px',
|
||||
backgroundColor: '#222',
|
||||
color: 'Lime',
|
||||
fontFamily: 'Arial, sans-serif',
|
||||
fontSize: '14px',
|
||||
lineHeight: '1.4',
|
||||
resize: 'vertical',
|
||||
overflowY: 'auto',
|
||||
};
|
||||
|
||||
// Displays input text on a node
|
||||
app.registerExtension({
|
||||
name: "Bjornulf.ShowInt",
|
||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
if (nodeData.name === "Bjornulf_ShowInt") {
|
||||
function createStyledTextArea(text) {
|
||||
const widget = ComfyWidgets["STRING"](this, "text", ["STRING", { multiline: true }], app).widget;
|
||||
widget.inputEl.readOnly = true;
|
||||
const textArea = widget.inputEl;
|
||||
|
||||
Object.assign(textArea.style, textAreaStyles);
|
||||
textArea.classList.add('bjornulf-show-text');
|
||||
widget.value = text;
|
||||
return widget;
|
||||
}
|
||||
|
||||
function populate(text) {
|
||||
if (this.widgets) {
|
||||
for (let i = 1; i < this.widgets.length; i++) {
|
||||
this.widgets[i].onRemove?.();
|
||||
}
|
||||
this.widgets.length = 1;
|
||||
}
|
||||
|
||||
const v = Array.isArray(text) ? text : [text];
|
||||
for (const list of v) {
|
||||
if (list) {
|
||||
createStyledTextArea.call(this, list);
|
||||
}
|
||||
}
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
const sz = this.computeSize();
|
||||
if (sz[0] < this.size[0]) sz[0] = this.size[0];
|
||||
if (sz[1] < this.size[1]) sz[1] = this.size[1];
|
||||
this.onResize?.(sz);
|
||||
app.graph.setDirtyCanvas(true, false);
|
||||
});
|
||||
}
|
||||
|
||||
// When the node is executed we will be sent the input text, display this in the widget
|
||||
const onExecuted = nodeType.prototype.onExecuted;
|
||||
nodeType.prototype.onExecuted = function (message) {
|
||||
onExecuted?.apply(this, arguments);
|
||||
populate.call(this, message.text);
|
||||
};
|
||||
|
||||
const onConfigure = nodeType.prototype.onConfigure;
|
||||
nodeType.prototype.onConfigure = function () {
|
||||
onConfigure?.apply(this, arguments);
|
||||
if (this.widgets_values?.length) {
|
||||
populate.call(this, this.widgets_values);
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user