♻️ 重构:删除可视化配置节点的冗余功能

This commit is contained in:
arlozen
2025-11-12 15:19:35 +08:00
parent 75f57aac08
commit 6260dbfbd2
4 changed files with 20 additions and 113 deletions
+1 -2
View File
@@ -15,7 +15,6 @@ class AIAgentsConfig:
def INPUT_TYPES(cls):
return {
"required": {
"agent_count": ("INT", {"default": 2, "min": 0, "max": 20, "step": 1}),
"default_agent": ("COMBO", {"default": ""}),
"config_data": ("STRING", {"default": "{}"}),
},
@@ -27,7 +26,7 @@ class AIAgentsConfig:
CATEGORY = "EasyToolkit/Manager"
OUTPUT_NODE = False
def run(self, agent_count, default_agent, config_data):
def run(self, default_agent, config_data):
pass
+1 -2
View File
@@ -15,7 +15,6 @@ class AIServicesConfig:
def INPUT_TYPES(cls):
return {
"required": {
"service_count": ("INT", {"default": 2, "min": 0, "max": 20, "step": 1}),
"default_service": ("COMBO", {"default": ""}),
"config_data": ("STRING", {"default": "{}"}),
},
@@ -27,7 +26,7 @@ class AIServicesConfig:
CATEGORY = "EasyToolkit/Manager"
OUTPUT_NODE = False
def run(self, service_count, default_service, config_data):
def run(self, default_service, config_data):
pass
+9 -53
View File
@@ -29,17 +29,6 @@ app.registerExtension({
// Track dynamic widgets
this.dynamicWidgets = [];
// Find the agent_count widget and add change listener
const agentCountWidget = this.widgets.find(w => w.name === "agent_count");
if (agentCountWidget) {
const originalCallback = agentCountWidget.callback;
agentCountWidget.callback = (value) => {
if (originalCallback) {
originalCallback.call(agentCountWidget, value);
}
this.updateAgentWidgets(value);
};
}
// Try to load cached configuration from field first
const configDataWidget = this.widgets.find(w => w.name === "config_data");
@@ -61,13 +50,9 @@ app.registerExtension({
this.defaultAgent = cachedConfig.defaultAgent || '';
console.log("[EasyToolkit] Loaded cached AI agents configuration:", this.agentsData.length, "agents", "default:", this.defaultAgent);
// Update agent count widget
if (agentCountWidget) {
agentCountWidget.value = this.agentsData.length;
}
// Rebuild widgets with cached data (includes action buttons)
this.updateAgentWidgets(this.agentsData.length);
this.updateAgentWidgets();
return;
}
} catch (error) {
@@ -99,14 +84,9 @@ app.registerExtension({
this.agentsData = data.agents || [];
this.defaultAgent = data.default_agent || '';
// Update agent count
const agentCountWidget = this.widgets.find(w => w.name === "agent_count");
if (agentCountWidget) {
agentCountWidget.value = this.agentsData.length;
}
// Rebuild widgets (includes action buttons)
this.updateAgentWidgets(this.agentsData.length);
this.updateAgentWidgets();
// Update cached configuration
this.saveCachedConfig();
@@ -126,33 +106,19 @@ app.registerExtension({
};
/**
* Update agent widgets based on count
* Update agent widgets based on current agents data
*/
nodeType.prototype.updateAgentWidgets = function (count) {
nodeType.prototype.updateAgentWidgets = function () {
// Remove all dynamic widgets and action buttons
this.removeDynamicWidgets();
this.removeActionButtons();
// Ensure agentsData has enough entries
while (this.agentsData.length < count) {
this.agentsData.push({
id: '',
label: '',
summary: ''
});
}
// Trim excess agents
if (this.agentsData.length > count) {
this.agentsData = this.agentsData.slice(0, count);
}
// Update default agent options
this.updateDefaultAgentOptions();
// Find insertion point (after agent_count, before buttons)
const agentCountIndex = this.widgets.findIndex(w => w.name === "agent_count");
let insertIndex = agentCountIndex + 1;
// Find insertion point (before buttons)
let insertIndex = this.widgets.length;
// Find default agent selection widget
const defaultAgentWidget = this.widgets.find(w => w.name === "default_agent");
@@ -168,7 +134,7 @@ app.registerExtension({
}
// Create widgets for each agent
for (let i = 0; i < count; i++) {
for (let i = 0; i < this.agentsData.length; i++) {
const agent = this.agentsData[i];
// Agent ID
@@ -402,14 +368,9 @@ app.registerExtension({
// Add the new agent to agentsData
this.agentsData.push(agent);
// Update agent count widget
const agentCountWidget = this.widgets.find(w => w.name === "agent_count");
if (agentCountWidget) {
agentCountWidget.value = this.agentsData.length;
}
// Rebuild widgets with updated data
this.updateAgentWidgets(this.agentsData.length);
this.updateAgentWidgets();
// Update cached configuration
this.saveCachedConfig();
@@ -493,14 +454,9 @@ app.registerExtension({
// Remove agent from local data
this.agentsData.splice(agentIndex, 1);
// Update agent count widget
const agentCountWidget = this.widgets.find(w => w.name === "agent_count");
if (agentCountWidget) {
agentCountWidget.value = this.agentsData.length;
}
// Rebuild widgets with updated data
this.updateAgentWidgets(this.agentsData.length);
this.updateAgentWidgets();
// Update cached configuration
this.saveCachedConfig();
+9 -56
View File
@@ -29,17 +29,6 @@ app.registerExtension({
// Track dynamic widgets
this.dynamicWidgets = [];
// Find the service_count widget and add change listener
const serviceCountWidget = this.widgets.find(w => w.name === "service_count");
if (serviceCountWidget) {
const originalCallback = serviceCountWidget.callback;
serviceCountWidget.callback = (value) => {
if (originalCallback) {
originalCallback.call(serviceCountWidget, value);
}
this.updateServiceWidgets(value);
};
}
// Try to load cached configuration from field first
const configDataWidget = this.widgets.find(w => w.name === "config_data");
@@ -61,13 +50,9 @@ app.registerExtension({
this.defaultService = cachedConfig.defaultService || '';
console.log("[EasyToolkit] Loaded cached AI services configuration:", this.servicesData.length, "services", "default:", this.defaultService);
// Update service count widget
if (serviceCountWidget) {
serviceCountWidget.value = this.servicesData.length;
}
// Rebuild widgets with cached data (includes action buttons)
this.updateServiceWidgets(this.servicesData.length);
this.updateServiceWidgets();
return;
}
} catch (error) {
@@ -99,14 +84,9 @@ app.registerExtension({
this.servicesData = data.services || [];
this.defaultService = data.default_service || '';
// Update service count
const serviceCountWidget = this.widgets.find(w => w.name === "service_count");
if (serviceCountWidget) {
serviceCountWidget.value = this.servicesData.length;
}
// Rebuild widgets (includes action buttons)
this.updateServiceWidgets(this.servicesData.length);
this.updateServiceWidgets();
// Update cached configuration
this.saveCachedConfig();
@@ -126,36 +106,19 @@ app.registerExtension({
};
/**
* Update service widgets based on count
* Update service widgets based on current services data
*/
nodeType.prototype.updateServiceWidgets = function (count) {
nodeType.prototype.updateServiceWidgets = function () {
// Remove all dynamic widgets and action buttons
this.removeDynamicWidgets();
this.removeActionButtons();
// Ensure servicesData has enough entries
while (this.servicesData.length < count) {
this.servicesData.push({
id: '',
label: '',
base_url: '',
api_key: '',
model: '',
timeout: 300
});
}
// Trim excess services
if (this.servicesData.length > count) {
this.servicesData = this.servicesData.slice(0, count);
}
// Update default service options
this.updateDefaultServiceOptions();
// Find insertion point (after service_count, before buttons)
const serviceCountIndex = this.widgets.findIndex(w => w.name === "service_count");
let insertIndex = serviceCountIndex + 1;
// Find insertion point (before buttons)
let insertIndex = this.widgets.length;
// Find default service selection widget
const defaultServiceWidget = this.widgets.find(w => w.name === "default_service");
@@ -171,7 +134,7 @@ app.registerExtension({
}
// Create widgets for each service
for (let i = 0; i < count; i++) {
for (let i = 0; i < this.servicesData.length; i++) {
const service = this.servicesData[i];
// Service ID
@@ -529,14 +492,9 @@ app.registerExtension({
// Add the new service to servicesData
this.servicesData.push(service);
// Update service count widget
const serviceCountWidget = this.widgets.find(w => w.name === "service_count");
if (serviceCountWidget) {
serviceCountWidget.value = this.servicesData.length;
}
// Rebuild widgets with updated data
this.updateServiceWidgets(this.servicesData.length);
this.updateServiceWidgets();
// Update cached configuration
this.saveCachedConfig();
@@ -585,14 +543,9 @@ app.registerExtension({
// Remove service from local data
this.servicesData.splice(serviceIndex, 1);
// Update service count widget
const serviceCountWidget = this.widgets.find(w => w.name === "service_count");
if (serviceCountWidget) {
serviceCountWidget.value = this.servicesData.length;
}
// Rebuild widgets with updated data
this.updateServiceWidgets(this.servicesData.length);
this.updateServiceWidgets();
// Update cached configuration
this.saveCachedConfig();