bizydraft 0.1.30__py3-none-any.whl → 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of bizydraft might be problematic. Click here for more details.
- bizydraft/block_nodes.py +35 -0
- bizydraft/env.py +11 -0
- bizydraft/hijack_nodes.py +66 -6
- bizydraft/hijack_routes.py +87 -184
- bizydraft/oss_utils.py +227 -0
- bizydraft/patch_handlers.py +150 -0
- bizydraft/postload.py +26 -8
- bizydraft/static/js/aiAppHandler.js +540 -0
- bizydraft/static/js/freezeModeHandler.js +490 -0
- bizydraft/static/js/handleStyle.js +6 -0
- bizydraft/static/js/hookLoadImage.js +121 -81
- bizydraft/static/js/hookLoadModel.js +152 -0
- bizydraft/static/js/main.js +0 -1
- bizydraft/static/js/nodeFocusHandler.js +153 -0
- bizydraft/static/js/nodeParamsFilter.js +136 -0
- bizydraft/static/js/postEvent.js +291 -61
- bizydraft/static/js/tool.js +60 -0
- bizydraft/workflow_io.py +2 -2
- {bizydraft-0.1.30.dist-info → bizydraft-0.2.0.dist-info}/METADATA +1 -1
- bizydraft-0.2.0.dist-info/RECORD +28 -0
- bizydraft-0.1.30.dist-info/RECORD +0 -19
- {bizydraft-0.1.30.dist-info → bizydraft-0.2.0.dist-info}/WHEEL +0 -0
- {bizydraft-0.1.30.dist-info → bizydraft-0.2.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
import { app } from "../../scripts/app.js";
|
|
2
|
+
import { setNodeParams, filterNodeWidgets, isConfigurableNode } from "./nodeParamsFilter.js";
|
|
3
|
+
import { processGraphOutput } from './tool.js';
|
|
4
|
+
import { focusNodeOnly, setGlobalReferences, setupCanvasClickHandler, removeCanvasClickHandler } from './nodeFocusHandler.js';
|
|
5
|
+
import { freezeWorkflow, unfreezeWorkflow, updateHighlightedNodes } from './freezeModeHandler.js';
|
|
6
|
+
// 状态变量
|
|
7
|
+
let selectedInputNodes = [];
|
|
8
|
+
let activeMode = null; // 当前活动的模式: "aiapp" 或 "export"
|
|
9
|
+
const originalNodeColors = new Map();
|
|
10
|
+
/**
|
|
11
|
+
* 切换应用模式
|
|
12
|
+
* @param {string} mode - 模式名称: "aiapp" 或 "export"
|
|
13
|
+
* @param {boolean} enable - 是否启用
|
|
14
|
+
* @param {boolean} isworkflow - 是否为工作流发布模式
|
|
15
|
+
* @returns {boolean} 操作是否成功
|
|
16
|
+
*/
|
|
17
|
+
function toggleMode(mode, enable, isworkflow = false) {
|
|
18
|
+
console.log(`${enable ? "启用" : "禁用"} ${mode} 模式`);
|
|
19
|
+
if (enable) {
|
|
20
|
+
activeMode = mode;
|
|
21
|
+
highlightInputNodes();
|
|
22
|
+
freezeWorkflow(isworkflow);
|
|
23
|
+
|
|
24
|
+
// 在进入发布模式时获取并打印工作流数据
|
|
25
|
+
if (mode === "export") {
|
|
26
|
+
// 使用 Promise 包装 graphToPrompt 调用
|
|
27
|
+
Promise.resolve().then(async () => {
|
|
28
|
+
const graphData = await app.graphToPrompt();
|
|
29
|
+
const processedOutput = processGraphOutput(graphData.output);
|
|
30
|
+
// 添加来源标识
|
|
31
|
+
const sourceInfo = { from: 'aiAppHandler_toggleMode' };
|
|
32
|
+
// 构建新的数据格式
|
|
33
|
+
const formattedData = {
|
|
34
|
+
prompt: processedOutput,
|
|
35
|
+
extra_data: {
|
|
36
|
+
extra_pnginfo: {
|
|
37
|
+
workflow: graphData.workflow
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
try {
|
|
42
|
+
const response = await fetch('/bizyair/workflow_io', {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/json'
|
|
46
|
+
},
|
|
47
|
+
body: JSON.stringify(formattedData)
|
|
48
|
+
});
|
|
49
|
+
const responseData = await response.json();
|
|
50
|
+
|
|
51
|
+
// 保存节点参数信息
|
|
52
|
+
if (responseData && responseData.data && Array.isArray(responseData.data.inputs)) {
|
|
53
|
+
// 使用新模块保存节点参数信息
|
|
54
|
+
setNodeParams(responseData.data.inputs);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 将响应发送给前端
|
|
58
|
+
window.parent.postMessage({
|
|
59
|
+
type: 'WORKFLOW_IO_RESPONSE',
|
|
60
|
+
data: responseData,
|
|
61
|
+
sourceInfo: sourceInfo
|
|
62
|
+
}, '*');
|
|
63
|
+
} catch (error) {
|
|
64
|
+
window.parent.postMessage({
|
|
65
|
+
type: 'WORKFLOW_IO_ERROR',
|
|
66
|
+
error: error.message
|
|
67
|
+
}, '*');
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// 发送模式变更通知给父窗口
|
|
72
|
+
window.parent.postMessage({
|
|
73
|
+
type: 'EXPORT_MODE_CHANGED',
|
|
74
|
+
enabled: true
|
|
75
|
+
}, '*');
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
} else {
|
|
79
|
+
activeMode = null;
|
|
80
|
+
//修复所有节点颜色
|
|
81
|
+
selectedInputNodes = [];
|
|
82
|
+
|
|
83
|
+
// 强制恢复所有节点颜色
|
|
84
|
+
if (app && app.graph && app.graph._nodes) {
|
|
85
|
+
for (const node of app.graph._nodes) {
|
|
86
|
+
if (node) {
|
|
87
|
+
// 恢复原始颜色
|
|
88
|
+
const original = originalNodeColors.get(node.id);
|
|
89
|
+
if (original) {
|
|
90
|
+
node.color = original.color || undefined;
|
|
91
|
+
node.bgcolor = original.bgcolor || undefined;
|
|
92
|
+
} else {
|
|
93
|
+
// 如果没有原始颜色,设置为undefined
|
|
94
|
+
node.color = undefined;
|
|
95
|
+
node.bgcolor = undefined;
|
|
96
|
+
}
|
|
97
|
+
delete node._aiAppHighlighted;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
originalNodeColors.clear();
|
|
101
|
+
app.canvas.setDirty(true, true);
|
|
102
|
+
} else {
|
|
103
|
+
restoreNodeColors();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
unfreezeWorkflow();
|
|
107
|
+
|
|
108
|
+
// 发送模式变更通知给父窗口
|
|
109
|
+
if (mode === "export") {
|
|
110
|
+
window.parent.postMessage({
|
|
111
|
+
type: 'EXPORT_MODE_CHANGED',
|
|
112
|
+
enabled: false
|
|
113
|
+
}, '*');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// 切换模式函数已实现通用逻辑,下面是为了兼容现有代码的别名
|
|
121
|
+
function enableAIAppMode() {
|
|
122
|
+
return toggleMode("aiapp", true);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function disableAIAppMode() {
|
|
126
|
+
return toggleMode("aiapp", false);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function toggleExportMode(params) {
|
|
130
|
+
return toggleMode("export", params.enable === true, params.isworkflow === true);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
// 高亮输入节点
|
|
140
|
+
function highlightInputNodes() {
|
|
141
|
+
if (!app || !app.graph || !app.graph._nodes) return;
|
|
142
|
+
|
|
143
|
+
// 保存原始颜色并设置高亮
|
|
144
|
+
for (const node of app.graph._nodes) {
|
|
145
|
+
// 保存原始颜色
|
|
146
|
+
if (!originalNodeColors.has(node.id)) {
|
|
147
|
+
originalNodeColors.set(node.id, {
|
|
148
|
+
color: node.color,
|
|
149
|
+
bgcolor: node.bgcolor
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 只设置已选择的节点的颜色,其他节点保持原样
|
|
154
|
+
if (selectedInputNodes.some(n => n.id === node.id)) {
|
|
155
|
+
// 已选择的节点 - 紫色
|
|
156
|
+
node.color = "#7C3AED";
|
|
157
|
+
node.bgcolor = "#7C3AED22";
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
node._aiAppHighlighted = true;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// 刷新画布
|
|
164
|
+
app.canvas.setDirty(true, true);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// 恢复节点颜色
|
|
168
|
+
function restoreNodeColors() {
|
|
169
|
+
if (!app || !app.graph || !app.graph._nodes) return;
|
|
170
|
+
|
|
171
|
+
for (const node of app.graph._nodes) {
|
|
172
|
+
if (node && node._aiAppHighlighted) {
|
|
173
|
+
// 恢复原始颜色
|
|
174
|
+
const original = originalNodeColors.get(node.id);
|
|
175
|
+
if (original) {
|
|
176
|
+
node.color = original.color || undefined;
|
|
177
|
+
node.bgcolor = original.bgcolor || undefined;
|
|
178
|
+
} else {
|
|
179
|
+
node.color = undefined;
|
|
180
|
+
node.bgcolor = undefined;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
delete node._aiAppHighlighted;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// 清空保存的颜色
|
|
188
|
+
originalNodeColors.clear();
|
|
189
|
+
|
|
190
|
+
// 刷新画布
|
|
191
|
+
app.canvas.setDirty(true, true);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// 选择节点
|
|
195
|
+
function selectInputNode(nodeId) {
|
|
196
|
+
if (!app || !app.graph) return null;
|
|
197
|
+
|
|
198
|
+
const node = app.graph.getNodeById(nodeId);
|
|
199
|
+
if (!node) return null;
|
|
200
|
+
|
|
201
|
+
// 检查节点是否已选择
|
|
202
|
+
if (selectedInputNodes.some(n => n.id === nodeId)) {
|
|
203
|
+
return null; // 节点已选择
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// 提取节点信息
|
|
207
|
+
const nodeInfo = extractNodeInfo(node);
|
|
208
|
+
|
|
209
|
+
// 添加到选中列表
|
|
210
|
+
selectedInputNodes.push(nodeInfo);
|
|
211
|
+
|
|
212
|
+
// 更新节点样式
|
|
213
|
+
node.color = "#7C3AED"; // 紫色
|
|
214
|
+
node.bgcolor = "#7C3AED22";
|
|
215
|
+
|
|
216
|
+
// 刷新画布
|
|
217
|
+
app.canvas.setDirty(true, true);
|
|
218
|
+
|
|
219
|
+
// 返回节点信息
|
|
220
|
+
return nodeInfo;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// 从选择中移除节点
|
|
224
|
+
function deselectInputNode(nodeId) {
|
|
225
|
+
// 统一 nodeId 类型为数字
|
|
226
|
+
const id = typeof nodeId === 'string' ? parseInt(nodeId, 10) : nodeId;
|
|
227
|
+
|
|
228
|
+
// 从列表中移除
|
|
229
|
+
const index = selectedInputNodes.findIndex(n => n.id === id);
|
|
230
|
+
if (index !== -1) {
|
|
231
|
+
selectedInputNodes.splice(index, 1);
|
|
232
|
+
}
|
|
233
|
+
// 恢复节点颜色,确保类型正确
|
|
234
|
+
const node = app.graph.getNodeById(id);
|
|
235
|
+
if (node) {
|
|
236
|
+
// 使用undefined而不是null,避免Zod schema验证错误
|
|
237
|
+
node.color = undefined;
|
|
238
|
+
node.bgcolor = undefined;
|
|
239
|
+
delete node._aiAppHighlighted;
|
|
240
|
+
app.canvas.setDirty(true, true);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// 提取节点信息
|
|
245
|
+
function extractNodeInfo(node) {
|
|
246
|
+
const nodeInfo = {
|
|
247
|
+
id: node.id,
|
|
248
|
+
type: node.type,
|
|
249
|
+
comfyClass: node.comfyClass,
|
|
250
|
+
title: node.title,
|
|
251
|
+
widgets: []
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
// 处理widgets
|
|
255
|
+
if (node.widgets && node.widgets.length > 0) {
|
|
256
|
+
nodeInfo.widgets = node.widgets
|
|
257
|
+
.filter(widget => widget.type !== "hidden" && !widget.disabled)
|
|
258
|
+
.map(widget => {
|
|
259
|
+
// 获取widget的值
|
|
260
|
+
const widgetValue = widget.value || "";
|
|
261
|
+
|
|
262
|
+
const widgetInfo = {
|
|
263
|
+
name: String(widget.name || ""),
|
|
264
|
+
value: widgetValue,
|
|
265
|
+
type: String(widget.type || "")
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
// 处理options属性
|
|
269
|
+
if (widget.options && widget.options.values) {
|
|
270
|
+
widgetInfo.options = { values: [] };
|
|
271
|
+
|
|
272
|
+
if (Array.isArray(widget.options.values)) {
|
|
273
|
+
widgetInfo.options.values = [...widget.options.values];
|
|
274
|
+
} else if (typeof widget.options.values === 'function') {
|
|
275
|
+
try {
|
|
276
|
+
const values = widget.options.values();
|
|
277
|
+
if (Array.isArray(values)) {
|
|
278
|
+
widgetInfo.options.values = [...values];
|
|
279
|
+
}
|
|
280
|
+
} catch (e) {
|
|
281
|
+
// 忽略错误
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return widgetInfo;
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return nodeInfo;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// 更新节点参数
|
|
294
|
+
function updateInputNodeWidget(nodeId, widgetName, newValue) {
|
|
295
|
+
if (!app || !app.graph) return false;
|
|
296
|
+
|
|
297
|
+
const node = app.graph.getNodeById(nodeId);
|
|
298
|
+
if (!node || !node.widgets) return false;
|
|
299
|
+
|
|
300
|
+
const widget = node.widgets.find(w => w.name === widgetName);
|
|
301
|
+
if (!widget) return false;
|
|
302
|
+
|
|
303
|
+
// 更新widget值
|
|
304
|
+
widget.value = newValue;
|
|
305
|
+
|
|
306
|
+
// 执行回调
|
|
307
|
+
if (typeof widget.callback === 'function') {
|
|
308
|
+
try {
|
|
309
|
+
widget.callback(newValue);
|
|
310
|
+
} catch (e) {
|
|
311
|
+
console.error(`执行widget回调出错: ${e.message}`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// 更新内部状态
|
|
316
|
+
const nodeIndex = selectedInputNodes.findIndex(n => n.id === nodeId);
|
|
317
|
+
if (nodeIndex !== -1) {
|
|
318
|
+
const widgetIndex = selectedInputNodes[nodeIndex].widgets.findIndex(w => w.name === widgetName);
|
|
319
|
+
if (widgetIndex !== -1) {
|
|
320
|
+
selectedInputNodes[nodeIndex].widgets[widgetIndex].value = newValue;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// 刷新画布
|
|
325
|
+
node.setDirtyCanvas(true, true);
|
|
326
|
+
|
|
327
|
+
return true;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// 获取所有选中的节点
|
|
331
|
+
function getSelectedInputNodes() {
|
|
332
|
+
return JSON.parse(JSON.stringify(selectedInputNodes));
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// 清空选中的节点
|
|
336
|
+
function clearSelectedInputNodes() {
|
|
337
|
+
// 恢复节点颜色
|
|
338
|
+
if (activeMode) {
|
|
339
|
+
for (const node of app.graph._nodes) {
|
|
340
|
+
if (node && selectedInputNodes.some(n => n.id === node.id)) {
|
|
341
|
+
node.color = "#7C3AED"; // 紫色
|
|
342
|
+
node.bgcolor = "#7C3AED22";
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// 清空列表
|
|
348
|
+
selectedInputNodes = [];
|
|
349
|
+
|
|
350
|
+
// 刷新画布
|
|
351
|
+
app.canvas.setDirty(true, true);
|
|
352
|
+
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
// 选中节点并手动聚焦
|
|
359
|
+
function selectNodeAndFocus(nodeId) {
|
|
360
|
+
if (!app || !app.graph) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const node = app.graph.getNodeById(parseInt(nodeId, 10));
|
|
365
|
+
if (!node) {
|
|
366
|
+
console.error('找不到节点:', nodeId);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// 设置节点的 selected 属性
|
|
371
|
+
for (const n of app.graph._nodes) {
|
|
372
|
+
n.selected = n.id === node.id;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// 设置 selected_nodes
|
|
376
|
+
if (app.canvas) {
|
|
377
|
+
app.canvas.selected_nodes = [node];
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
//使用 app.canvas.centerOnNode
|
|
381
|
+
if (app.canvas && typeof app.canvas.centerOnNode === 'function') {
|
|
382
|
+
app.canvas.centerOnNode(node);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// 刷新画布
|
|
386
|
+
if (app.canvas) {
|
|
387
|
+
app.canvas.setDirty(true, true);
|
|
388
|
+
if (typeof app.canvas.draw === 'function') {
|
|
389
|
+
app.canvas.draw(true, true);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// 保存原始节点颜色信息
|
|
397
|
+
function saveOriginalNodeColors(workflowId) {
|
|
398
|
+
if (!app || !app.graph || !app.graph._nodes) return;
|
|
399
|
+
|
|
400
|
+
const nodeColors = new Map();
|
|
401
|
+
|
|
402
|
+
// 遍历所有节点,保存原始颜色
|
|
403
|
+
for (const node of app.graph._nodes) {
|
|
404
|
+
if (node) {
|
|
405
|
+
// 确保颜色值类型正确,使用undefined而不是null
|
|
406
|
+
nodeColors.set(node.id, {
|
|
407
|
+
color: node.color || undefined,
|
|
408
|
+
bgcolor: node.bgcolor || undefined
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
// 发送颜色信息到前端
|
|
413
|
+
window.parent.postMessage({
|
|
414
|
+
type: 'ORIGINAL_NODE_COLORS_SAVED',
|
|
415
|
+
workflowId: workflowId,
|
|
416
|
+
nodeColors: Array.from(nodeColors.entries())
|
|
417
|
+
}, '*');
|
|
418
|
+
|
|
419
|
+
console.log('已保存原始节点颜色信息,节点数量:', nodeColors.size);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// 监听 window 消息,处理 centerNode
|
|
423
|
+
window.addEventListener('message', function(event) {
|
|
424
|
+
|
|
425
|
+
// 处理选中并聚焦节点
|
|
426
|
+
if (event.data && event.data.type === 'selectNodeAndFocus' && event.data.nodeId !== undefined) {
|
|
427
|
+
selectNodeAndFocus(event.data.nodeId);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// 处理保存原始节点颜色请求
|
|
431
|
+
if (event.data && event.data.type === 'saveOriginalNodeColors' && event.data.workflowId !== undefined) {
|
|
432
|
+
saveOriginalNodeColors(event.data.workflowId);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// 处理获取widget信息请求
|
|
436
|
+
if (event.data && event.data.type === 'get_widget_info') {
|
|
437
|
+
const { messageId, nodeId, widgetName } = event.data;
|
|
438
|
+
|
|
439
|
+
let widget = null;
|
|
440
|
+
let error = null;
|
|
441
|
+
|
|
442
|
+
try {
|
|
443
|
+
// 查找节点
|
|
444
|
+
const node = app && app.graph ? app.graph.getNodeById(Number(nodeId)) : null;
|
|
445
|
+
if (node && node.widgets) {
|
|
446
|
+
widget = node.widgets.find(w => String(w.name) === String(widgetName));
|
|
447
|
+
if (!widget) {
|
|
448
|
+
error = '未找到指定widget';
|
|
449
|
+
} else {
|
|
450
|
+
// 保留所有非undefined的options属性
|
|
451
|
+
const safeOptions = widget.options ?
|
|
452
|
+
Object.fromEntries(
|
|
453
|
+
Object.entries(widget.options)
|
|
454
|
+
.filter(([_, value]) => value !== undefined)
|
|
455
|
+
) :
|
|
456
|
+
{};
|
|
457
|
+
|
|
458
|
+
// 直接使用 widget.value,这是截图中显示蓝色高亮的值
|
|
459
|
+
const widgetValue = widget.value || "";
|
|
460
|
+
// 创建一个新的简化widget对象,只包含我们实际需要的属性
|
|
461
|
+
// 确保只使用可序列化的属性
|
|
462
|
+
let safeWidgetValue = "";
|
|
463
|
+
try {
|
|
464
|
+
// 测试是否可序列化
|
|
465
|
+
JSON.stringify({value: widgetValue});
|
|
466
|
+
safeWidgetValue = widgetValue;
|
|
467
|
+
} catch (e) {
|
|
468
|
+
console.error('[aiAppHandler] 值不可序列化:', e);
|
|
469
|
+
// 使用安全的字符串值
|
|
470
|
+
safeWidgetValue = String(widgetValue) || "";
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
widget = {
|
|
474
|
+
name: widget.name || "",
|
|
475
|
+
value: safeWidgetValue, // 使用安全处理后的值
|
|
476
|
+
type: widget.type || "string",
|
|
477
|
+
options: safeOptions,
|
|
478
|
+
displayName: widget.displayName || widget.label || widget.name || "",
|
|
479
|
+
node_title: node.title || "",
|
|
480
|
+
node_type: node.type || "",
|
|
481
|
+
node_comfyClass: node.comfyClass || ""
|
|
482
|
+
};
|
|
483
|
+
console.log('[aiAppHandler] 处理后的widget', widget);
|
|
484
|
+
}
|
|
485
|
+
} else {
|
|
486
|
+
error = '未找到指定节点或节点没有widgets';
|
|
487
|
+
}
|
|
488
|
+
} catch (e) {
|
|
489
|
+
console.error('[aiAppHandler] 查找节点/widget过程出错', e);
|
|
490
|
+
error = e.message;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
try {
|
|
494
|
+
// 确保只发送可序列化的数据
|
|
495
|
+
// 创建一个安全的、深度复制的对象,移除所有函数和不可序列化内容
|
|
496
|
+
const safeWidget = widget ? JSON.parse(JSON.stringify({
|
|
497
|
+
name: widget.name || "",
|
|
498
|
+
value: widget.value || "",
|
|
499
|
+
type: widget.type || "string",
|
|
500
|
+
options: widget.options || {},
|
|
501
|
+
displayName: widget.displayName || "",
|
|
502
|
+
node_title: widget.node_title || "",
|
|
503
|
+
node_type: widget.node_type || "",
|
|
504
|
+
node_comfyClass: widget.node_comfyClass || ""
|
|
505
|
+
})) : null;
|
|
506
|
+
|
|
507
|
+
window.parent.postMessage({
|
|
508
|
+
type: 'widget_info_response',
|
|
509
|
+
messageId,
|
|
510
|
+
widget: safeWidget,
|
|
511
|
+
error
|
|
512
|
+
}, '*');
|
|
513
|
+
} catch (e) {
|
|
514
|
+
console.error('[aiAppHandler] 发送 widget_info_response 失败', e);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
// 导出模块
|
|
520
|
+
export {
|
|
521
|
+
enableAIAppMode,
|
|
522
|
+
disableAIAppMode,
|
|
523
|
+
selectInputNode,
|
|
524
|
+
deselectInputNode,
|
|
525
|
+
updateInputNodeWidget,
|
|
526
|
+
getSelectedInputNodes,
|
|
527
|
+
clearSelectedInputNodes,
|
|
528
|
+
toggleExportMode
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
//前端点击清除所有
|
|
532
|
+
function clearExportNodes() {
|
|
533
|
+
if (!app || !app.graph || !app.graph._nodes) return;
|
|
534
|
+
for (const node of app.graph._nodes) {
|
|
535
|
+
deselectInputNode(node.id);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
window.clearExportNodes = clearExportNodes;
|
|
539
|
+
window.deselectInputNode = deselectInputNode;
|
|
540
|
+
window.saveOriginalNodeColors = saveOriginalNodeColors;
|