blockmine 1.22.0 → 1.23.1
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.
- package/.claude/agents/code-architect.md +34 -0
- package/.claude/agents/code-explorer.md +51 -0
- package/.claude/agents/code-reviewer.md +46 -0
- package/.claude/commands/feature-dev.md +125 -0
- package/.claude/settings.json +5 -1
- package/.claude/settings.local.json +12 -1
- package/.claude/skills/frontend-design/SKILL.md +42 -0
- package/CHANGELOG.md +32 -1
- package/README.md +302 -152
- package/backend/package-lock.json +681 -9
- package/backend/package.json +8 -0
- package/backend/prisma/migrations/20251116111851_add_execution_trace/migration.sql +22 -0
- package/backend/prisma/migrations/20251120154914_add_panel_api_keys/migration.sql +21 -0
- package/backend/prisma/migrations/20251121110241_add_proxy_table/migration.sql +45 -0
- package/backend/prisma/schema.prisma +70 -1
- package/backend/src/__tests__/services/BotLifecycleService.test.js +9 -4
- package/backend/src/ai/plugin-assistant-system-prompt.md +788 -0
- package/backend/src/api/middleware/auth.js +27 -0
- package/backend/src/api/middleware/botAccess.js +7 -3
- package/backend/src/api/middleware/panelApiAuth.js +135 -0
- package/backend/src/api/routes/aiAssistant.js +995 -0
- package/backend/src/api/routes/auth.js +90 -54
- package/backend/src/api/routes/botCommands.js +107 -0
- package/backend/src/api/routes/botGroups.js +165 -0
- package/backend/src/api/routes/botHistory.js +108 -0
- package/backend/src/api/routes/botPermissions.js +99 -0
- package/backend/src/api/routes/botStatus.js +36 -0
- package/backend/src/api/routes/botUsers.js +162 -0
- package/backend/src/api/routes/bots.js +108 -59
- package/backend/src/api/routes/eventGraphs.js +4 -1
- package/backend/src/api/routes/logs.js +13 -3
- package/backend/src/api/routes/panel.js +3 -3
- package/backend/src/api/routes/panelApiKeys.js +179 -0
- package/backend/src/api/routes/pluginIde.js +1715 -135
- package/backend/src/api/routes/plugins.js +170 -13
- package/backend/src/api/routes/proxies.js +130 -0
- package/backend/src/api/routes/search.js +4 -0
- package/backend/src/api/routes/servers.js +20 -3
- package/backend/src/api/routes/settings.js +5 -0
- package/backend/src/api/routes/system.js +3 -3
- package/backend/src/api/routes/traces.js +131 -0
- package/backend/src/config/debug.config.js +36 -0
- package/backend/src/core/BotHistoryStore.js +180 -0
- package/backend/src/core/BotManager.js +14 -4
- package/backend/src/core/BotProcess.js +1517 -1092
- package/backend/src/core/EventGraphManager.js +194 -280
- package/backend/src/core/GraphExecutionEngine.js +1004 -321
- package/backend/src/core/MessageQueue.js +12 -6
- package/backend/src/core/PluginLoader.js +99 -5
- package/backend/src/core/PluginManager.js +74 -13
- package/backend/src/core/TaskScheduler.js +1 -1
- package/backend/src/core/commands/whois.js +1 -1
- package/backend/src/core/node-registries/actions.js +72 -2
- package/backend/src/core/node-registries/arrays.js +18 -0
- package/backend/src/core/node-registries/data.js +1 -1
- package/backend/src/core/node-registries/events.js +14 -0
- package/backend/src/core/node-registries/logic.js +17 -0
- package/backend/src/core/node-registries/strings.js +34 -0
- package/backend/src/core/node-registries/type.js +25 -0
- package/backend/src/core/nodes/actions/bot_look_at.js +1 -1
- package/backend/src/core/nodes/actions/create_command.js +189 -0
- package/backend/src/core/nodes/actions/delete_command.js +92 -0
- package/backend/src/core/nodes/actions/http_request.js +23 -4
- package/backend/src/core/nodes/actions/send_message.js +2 -12
- package/backend/src/core/nodes/actions/update_command.js +133 -0
- package/backend/src/core/nodes/arrays/join.js +28 -0
- package/backend/src/core/nodes/data/cast.js +2 -1
- package/backend/src/core/nodes/data/string_literal.js +2 -13
- package/backend/src/core/nodes/logic/not.js +22 -0
- package/backend/src/core/nodes/strings/starts_with.js +1 -1
- package/backend/src/core/nodes/strings/to_lower.js +22 -0
- package/backend/src/core/nodes/strings/to_upper.js +22 -0
- package/backend/src/core/nodes/type/to_string.js +32 -0
- package/backend/src/core/services/BotLifecycleService.js +835 -596
- package/backend/src/core/services/CommandExecutionService.js +430 -351
- package/backend/src/core/services/DebugSessionManager.js +347 -0
- package/backend/src/core/services/GraphCollaborationManager.js +501 -0
- package/backend/src/core/services/MinecraftBotManager.js +259 -0
- package/backend/src/core/services/MinecraftViewerService.js +216 -0
- package/backend/src/core/services/TraceCollectorService.js +545 -0
- package/backend/src/core/system/RuntimeCommandRegistry.js +116 -0
- package/backend/src/core/system/Transport.js +0 -4
- package/backend/src/core/validation/nodeSchemas.js +6 -6
- package/backend/src/real-time/botApi/handlers/graphHandlers.js +2 -2
- package/backend/src/real-time/botApi/handlers/graphWebSocketHandlers.js +1 -1
- package/backend/src/real-time/botApi/utils.js +11 -0
- package/backend/src/real-time/panelNamespace.js +387 -0
- package/backend/src/real-time/presence.js +7 -2
- package/backend/src/real-time/socketHandler.js +395 -4
- package/backend/src/server.js +18 -0
- package/frontend/dist/assets/index-DqzDkFsP.js +11210 -0
- package/frontend/dist/assets/index-t6K1u4OV.css +32 -0
- package/frontend/dist/index.html +2 -2
- package/frontend/package-lock.json +9437 -0
- package/frontend/package.json +8 -0
- package/package.json +2 -2
- package/screen/console.png +0 -0
- package/screen/dashboard.png +0 -0
- package/screen/graph_collabe.png +0 -0
- package/screen/graph_live_debug.png +0 -0
- package/screen/management_command.png +0 -0
- package/screen/node_debug_trace.png +0 -0
- package/screen/plugin_/320/276/320/261/320/267/320/276/321/200.png +0 -0
- package/screen/websocket.png +0 -0
- package/screen//320/275/320/260/321/201/321/202/321/200/320/276/320/271/320/272/320/270_/320/276/321/202/320/264/320/265/320/273/321/214/320/275/321/213/321/205_/320/272/320/276/320/274/320/260/320/275/320/264_/320/272/320/260/320/266/320/264/321/203_/320/272/320/276/320/274/320/260/320/275/320/273/320/264/321/203_/320/274/320/276/320/266/320/275/320/276_/320/275/320/260/321/201/321/202/321/200/320/260/320/270/320/262/320/260/321/202/321/214.png +0 -0
- package/screen//320/277/320/273/320/260/320/275/320/270/321/200/320/276/320/262/321/211/320/270/320/272_/320/274/320/276/320/266/320/275/320/276_/320/267/320/260/320/264/320/260/320/262/320/260/321/202/321/214_/320/264/320/265/320/271/321/201/321/202/320/262/320/270/321/217_/320/277/320/276_/320/262/321/200/320/265/320/274/320/265/320/275/320/270.png +0 -0
- package/frontend/dist/assets/index-CfTo92bP.css +0 -1
- package/frontend/dist/assets/index-CiFD5X9Z.js +0 -8344
|
@@ -1,322 +1,1005 @@
|
|
|
1
|
-
const prismaService = require('./PrismaService');
|
|
2
|
-
const { parseVariables } = require('./utils/variableParser');
|
|
3
|
-
const validationService = require('./services/ValidationService');
|
|
4
|
-
const { MAX_RECURSION_DEPTH } = require('./config/validation');
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
await this.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if (
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
if (
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
|
|
1
|
+
const prismaService = require('./PrismaService');
|
|
2
|
+
const { parseVariables } = require('./utils/variableParser');
|
|
3
|
+
const validationService = require('./services/ValidationService');
|
|
4
|
+
const { MAX_RECURSION_DEPTH } = require('./config/validation');
|
|
5
|
+
const debugConfig = require('../config/debug.config');
|
|
6
|
+
const prisma = prismaService.getClient();
|
|
7
|
+
|
|
8
|
+
const BreakLoopSignal = require('./BreakLoopSignal');
|
|
9
|
+
const { getTraceCollector } = require('./services/TraceCollectorService');
|
|
10
|
+
const { getGlobalDebugManager } = require('./services/DebugSessionManager');
|
|
11
|
+
|
|
12
|
+
class GraphExecutionEngine {
|
|
13
|
+
// Static флаг для предотвращения дублирования IPC handler
|
|
14
|
+
static _ipcHandlerAttached = false;
|
|
15
|
+
// Static Map для хранения всех pending requests из всех instances
|
|
16
|
+
static _allPendingRequests = new Map();
|
|
17
|
+
|
|
18
|
+
constructor(nodeRegistry, botManagerOrApi = null) {
|
|
19
|
+
if (!nodeRegistry || typeof nodeRegistry.getNodeConfig !== 'function') {
|
|
20
|
+
throw new Error('GraphExecutionEngine requires a valid NodeRegistry instance.');
|
|
21
|
+
}
|
|
22
|
+
this.nodeRegistry = nodeRegistry;
|
|
23
|
+
this.botManager = botManagerOrApi;
|
|
24
|
+
this.activeGraph = null;
|
|
25
|
+
this.context = null;
|
|
26
|
+
this.memo = new Map();
|
|
27
|
+
this.traceCollector = getTraceCollector();
|
|
28
|
+
this.currentTraceId = null;
|
|
29
|
+
|
|
30
|
+
// Используем статическую Map для всех instance
|
|
31
|
+
this.pendingDebugRequests = GraphExecutionEngine._allPendingRequests;
|
|
32
|
+
|
|
33
|
+
if (process.on && !GraphExecutionEngine._ipcHandlerAttached) {
|
|
34
|
+
process.on('message', (message) => {
|
|
35
|
+
if (message.type === 'debug:breakpoint_response' || message.type === 'debug:step_response') {
|
|
36
|
+
GraphExecutionEngine._handleGlobalDebugResponse(message);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
GraphExecutionEngine._ipcHandlerAttached = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async execute(graph, context, eventType) {
|
|
44
|
+
if (!graph || graph === 'null') return context;
|
|
45
|
+
|
|
46
|
+
const parsedGraph = validationService.parseGraph(graph, 'GraphExecutionEngine.execute');
|
|
47
|
+
if (!parsedGraph) {
|
|
48
|
+
return context;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const validation = validationService.validateGraphStructure(parsedGraph, 'GraphExecutionEngine');
|
|
52
|
+
if (validation.shouldSkip) {
|
|
53
|
+
return context;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const graphId = context.graphId || null;
|
|
57
|
+
const botId = context.botId || null;
|
|
58
|
+
|
|
59
|
+
if (graphId && botId) {
|
|
60
|
+
this.currentTraceId = await this.traceCollector.startTrace(
|
|
61
|
+
botId,
|
|
62
|
+
graphId,
|
|
63
|
+
eventType || 'command',
|
|
64
|
+
context.eventArgs || {}
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
this.activeGraph = parsedGraph;
|
|
70
|
+
this.context = context;
|
|
71
|
+
|
|
72
|
+
if (!this.context.variables) {
|
|
73
|
+
this.context.variables = parseVariables(
|
|
74
|
+
this.activeGraph.variables,
|
|
75
|
+
'GraphExecutionEngine'
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!this.context.persistenceIntent) this.context.persistenceIntent = new Map();
|
|
80
|
+
this.memo.clear();
|
|
81
|
+
|
|
82
|
+
const eventName = eventType || 'command';
|
|
83
|
+
const startNode = this.activeGraph.nodes.find(n => n.type === `event:${eventName}`);
|
|
84
|
+
|
|
85
|
+
if (startNode) {
|
|
86
|
+
if (this.currentTraceId) {
|
|
87
|
+
this.traceCollector.recordStep(this.currentTraceId, {
|
|
88
|
+
nodeId: startNode.id,
|
|
89
|
+
nodeType: startNode.type,
|
|
90
|
+
status: 'executed',
|
|
91
|
+
duration: 0,
|
|
92
|
+
inputs: {},
|
|
93
|
+
outputs: await this._captureNodeOutputs(startNode),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
await this.traverse(startNode, 'exec');
|
|
98
|
+
} else if (!eventType) {
|
|
99
|
+
throw new Error(`Не найдена стартовая нода события (event:command) в графе.`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (this.currentTraceId) {
|
|
103
|
+
// Перед завершением trace, захватываем outputs для всех data-нод
|
|
104
|
+
await this._captureAllDataNodeOutputs();
|
|
105
|
+
|
|
106
|
+
const trace = await this.traceCollector.completeTrace(this.currentTraceId);
|
|
107
|
+
|
|
108
|
+
// Если работаем в дочернем процессе (BotProcess), отправляем трассировку в главный процесс
|
|
109
|
+
if (trace && process.send) {
|
|
110
|
+
process.send({
|
|
111
|
+
type: 'trace:completed',
|
|
112
|
+
trace: {
|
|
113
|
+
...trace,
|
|
114
|
+
steps: trace.steps,
|
|
115
|
+
eventArgs: typeof trace.eventArgs === 'string' ? trace.eventArgs : JSON.stringify(trace.eventArgs)
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Отправляем debug событие только если DebugSessionManager инициализирован
|
|
121
|
+
// (он может быть не инициализирован в дочерних процессах BotProcess)
|
|
122
|
+
if (graphId) {
|
|
123
|
+
try {
|
|
124
|
+
const debugManager = getGlobalDebugManager();
|
|
125
|
+
const debugState = debugManager.get(graphId);
|
|
126
|
+
if (debugState && debugState.activeExecution) {
|
|
127
|
+
debugState.broadcast('debug:completed', {
|
|
128
|
+
trace: await this.traceCollector.getTrace(this.currentTraceId)
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
} catch (error) {
|
|
132
|
+
// DebugSessionManager не инициализирован - это нормально для дочерних процессов
|
|
133
|
+
// Просто игнорируем
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
this.currentTraceId = null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
} catch (error) {
|
|
141
|
+
if (this.currentTraceId) {
|
|
142
|
+
// Даже при ошибке захватываем outputs для data-нод
|
|
143
|
+
try {
|
|
144
|
+
await this._captureAllDataNodeOutputs();
|
|
145
|
+
} catch (captureError) {
|
|
146
|
+
console.error(`[GraphExecutor] Error capturing outputs on failure:`, captureError);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const trace = await this.traceCollector.failTrace(this.currentTraceId, error);
|
|
150
|
+
|
|
151
|
+
// Если работаем в дочернем процессе (BotProcess), отправляем трассировку с ошибкой в главный процесс
|
|
152
|
+
if (trace && process.send) {
|
|
153
|
+
process.send({
|
|
154
|
+
type: 'trace:completed',
|
|
155
|
+
trace: {
|
|
156
|
+
...trace,
|
|
157
|
+
steps: trace.steps,
|
|
158
|
+
eventArgs: typeof trace.eventArgs === 'string' ? trace.eventArgs : JSON.stringify(trace.eventArgs)
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
this.currentTraceId = null;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (!(error instanceof BreakLoopSignal)) {
|
|
167
|
+
console.error(`[GraphExecutionEngine] Критическая ошибка выполнения графа: ${error.stack}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return this.context;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async traverse(node, fromPinId) {
|
|
175
|
+
const connection = this.activeGraph.connections.find(c => c.sourceNodeId === node.id && c.sourcePinId === fromPinId);
|
|
176
|
+
if (!connection) return;
|
|
177
|
+
|
|
178
|
+
const nextNode = this.activeGraph.nodes.find(n => n.id === connection.targetNodeId);
|
|
179
|
+
if (!nextNode) return;
|
|
180
|
+
|
|
181
|
+
if (this.currentTraceId) {
|
|
182
|
+
this.traceCollector.recordTraversal(
|
|
183
|
+
this.currentTraceId,
|
|
184
|
+
node.id,
|
|
185
|
+
fromPinId,
|
|
186
|
+
nextNode.id
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
await this.executeNode(nextNode);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async executeNode(node) {
|
|
194
|
+
const startTime = Date.now();
|
|
195
|
+
|
|
196
|
+
// Записываем шаг ДО проверки брейкпоинта, чтобы в trace были данные о предыдущих нодах
|
|
197
|
+
if (this.currentTraceId) {
|
|
198
|
+
this.traceCollector.recordStep(this.currentTraceId, {
|
|
199
|
+
nodeId: node.id,
|
|
200
|
+
nodeType: node.type,
|
|
201
|
+
status: 'executed',
|
|
202
|
+
duration: null,
|
|
203
|
+
inputs: await this._captureNodeInputs(node),
|
|
204
|
+
outputs: {},
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Проверка брейкпоинта ПЕРЕД выполнением (но ПОСЛЕ записи в trace)
|
|
209
|
+
await this.checkBreakpoint(node);
|
|
210
|
+
|
|
211
|
+
// Проверка step mode ПЕРЕД выполнением (важно делать ДО executor, чтобы поймать ноду до traverse)
|
|
212
|
+
await this._checkStepMode(node);
|
|
213
|
+
|
|
214
|
+
const nodeConfig = this.nodeRegistry.getNodeConfig(node.type);
|
|
215
|
+
if (nodeConfig && typeof nodeConfig.executor === 'function') {
|
|
216
|
+
const helpers = {
|
|
217
|
+
resolvePinValue: this.resolvePinValue.bind(this),
|
|
218
|
+
traverse: this.traverse.bind(this),
|
|
219
|
+
memo: this.memo,
|
|
220
|
+
clearLoopBodyMemo: this.clearLoopBodyMemo.bind(this),
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
try {
|
|
224
|
+
await nodeConfig.executor.call(this, node, this.context, helpers);
|
|
225
|
+
|
|
226
|
+
const executionTime = Date.now() - startTime;
|
|
227
|
+
|
|
228
|
+
if (this.currentTraceId) {
|
|
229
|
+
this.traceCollector.updateStepOutputs(this.currentTraceId, node.id, await this._captureNodeOutputs(node));
|
|
230
|
+
this.traceCollector.updateStepDuration(this.currentTraceId, node.id, executionTime);
|
|
231
|
+
}
|
|
232
|
+
} catch (error) {
|
|
233
|
+
if (this.currentTraceId) {
|
|
234
|
+
this.traceCollector.updateStepError(
|
|
235
|
+
this.currentTraceId,
|
|
236
|
+
node.id,
|
|
237
|
+
error.message,
|
|
238
|
+
Date.now() - startTime
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
throw error;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const execCacheKey = `${node.id}_executed`;
|
|
248
|
+
if (this.memo.has(execCacheKey)) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
this.memo.set(execCacheKey, true);
|
|
252
|
+
|
|
253
|
+
try {
|
|
254
|
+
await this._executeLegacyNode(node);
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
const executionTime = Date.now() - startTime;
|
|
258
|
+
|
|
259
|
+
if (this.currentTraceId) {
|
|
260
|
+
this.traceCollector.updateStepOutputs(this.currentTraceId, node.id, await this._captureNodeOutputs(node));
|
|
261
|
+
this.traceCollector.updateStepDuration(this.currentTraceId, node.id, executionTime);
|
|
262
|
+
}
|
|
263
|
+
} catch (error) {
|
|
264
|
+
if (this.currentTraceId) {
|
|
265
|
+
this.traceCollector.updateStepError(
|
|
266
|
+
this.currentTraceId,
|
|
267
|
+
node.id,
|
|
268
|
+
error.message,
|
|
269
|
+
Date.now() - startTime
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
throw error;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async _checkStepMode(node) {
|
|
277
|
+
try {
|
|
278
|
+
// Если работаем в дочернем процессе, используем IPC
|
|
279
|
+
if (process.send) {
|
|
280
|
+
return await this._checkStepModeViaIpc(node);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Иначе используем прямой доступ к DebugManager
|
|
284
|
+
const { getGlobalDebugManager } = require('./services/DebugSessionManager');
|
|
285
|
+
const debugManager = getGlobalDebugManager();
|
|
286
|
+
const graphId = this.activeGraph?.id;
|
|
287
|
+
|
|
288
|
+
if (graphId) {
|
|
289
|
+
const debugState = debugManager.get(graphId);
|
|
290
|
+
if (debugState && debugState.shouldStepPause(node.id)) {
|
|
291
|
+
console.log(`[Debug] Step mode: pausing after executing node ${node.id}`);
|
|
292
|
+
|
|
293
|
+
// Получаем inputs для отправки в debug session
|
|
294
|
+
const inputs = await this._captureNodeInputs(node);
|
|
295
|
+
|
|
296
|
+
// Получаем текущую трассировку для отображения выполненных шагов
|
|
297
|
+
const executedSteps = this.currentTraceId
|
|
298
|
+
? await this.traceCollector.getTrace(this.currentTraceId)
|
|
299
|
+
: null;
|
|
300
|
+
|
|
301
|
+
// Паузим выполнение
|
|
302
|
+
await debugState.pause({
|
|
303
|
+
nodeId: node.id,
|
|
304
|
+
nodeType: node.type,
|
|
305
|
+
inputs,
|
|
306
|
+
executedSteps,
|
|
307
|
+
context: {
|
|
308
|
+
user: this.context.user,
|
|
309
|
+
variables: this.context.variables,
|
|
310
|
+
commandArguments: this.context.commandArguments,
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
} catch (error) {
|
|
316
|
+
if (error.message !== 'DebugSessionManager not initialized! Call initializeDebugManager(io) first.') {
|
|
317
|
+
throw error;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async _checkStepModeViaIpc(node) {
|
|
323
|
+
// Step mode работает аналогично breakpoint, просто отправляем тип 'step'
|
|
324
|
+
const { randomUUID } = require('crypto');
|
|
325
|
+
const requestId = randomUUID();
|
|
326
|
+
|
|
327
|
+
const inputs = await this._captureNodeInputs(node);
|
|
328
|
+
const executedSteps = this.currentTraceId
|
|
329
|
+
? await this.traceCollector.getTrace(this.currentTraceId)
|
|
330
|
+
: null;
|
|
331
|
+
|
|
332
|
+
process.send({
|
|
333
|
+
type: 'debug:check_step_mode',
|
|
334
|
+
requestId,
|
|
335
|
+
payload: {
|
|
336
|
+
graphId: this.context.graphId,
|
|
337
|
+
nodeId: node.id,
|
|
338
|
+
nodeType: node.type,
|
|
339
|
+
inputs,
|
|
340
|
+
executedSteps,
|
|
341
|
+
context: {
|
|
342
|
+
user: this.context.user,
|
|
343
|
+
variables: this.context.variables,
|
|
344
|
+
commandArguments: this.context.commandArguments,
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// Ждём ответа (если step mode не активен, ответ придёт сразу)
|
|
350
|
+
await new Promise((resolve) => {
|
|
351
|
+
this.pendingDebugRequests.set(requestId, resolve);
|
|
352
|
+
|
|
353
|
+
// Таймаут на случай, если ответ не придёт
|
|
354
|
+
const timeoutId = setTimeout(() => {
|
|
355
|
+
if (this.pendingDebugRequests.has(requestId)) {
|
|
356
|
+
this.pendingDebugRequests.delete(requestId);
|
|
357
|
+
resolve(null);
|
|
358
|
+
}
|
|
359
|
+
}, debugConfig.STEP_MODE_TIMEOUT);
|
|
360
|
+
|
|
361
|
+
// Сохраняем timeoutId для возможной отмены
|
|
362
|
+
this.pendingDebugRequests.set(`${requestId}_timeout`, timeoutId);
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
async _executeLegacyNode(node) {
|
|
367
|
+
switch (node.type) {
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
case 'string:contains':
|
|
376
|
+
case 'string:matches':
|
|
377
|
+
case 'string:equals': {
|
|
378
|
+
await this.traverse(node, 'exec');
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
case 'array:get_random_element': {
|
|
382
|
+
await this.traverse(node, 'element');
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
case 'array:add_element':
|
|
386
|
+
case 'array:remove_by_index':
|
|
387
|
+
case 'array:get_by_index':
|
|
388
|
+
case 'array:find_index':
|
|
389
|
+
case 'array:contains': {
|
|
390
|
+
await this.traverse(node, 'result');
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
case 'data:array_literal':
|
|
394
|
+
case 'data:make_object':
|
|
395
|
+
case 'data:get_variable':
|
|
396
|
+
case 'data:get_argument':
|
|
397
|
+
case 'data:length':
|
|
398
|
+
case 'data:get_entity_field':
|
|
399
|
+
case 'data:cast':
|
|
400
|
+
case 'data:string_literal':
|
|
401
|
+
case 'data:get_user_field':
|
|
402
|
+
case 'data:get_server_players':
|
|
403
|
+
case 'data:get_bot_look':
|
|
404
|
+
case 'math:operation':
|
|
405
|
+
case 'math:random_number':
|
|
406
|
+
case 'logic:operation':
|
|
407
|
+
case 'string:concat':
|
|
408
|
+
case 'object:create':
|
|
409
|
+
case 'object:get':
|
|
410
|
+
case 'object:set':
|
|
411
|
+
case 'object:delete':
|
|
412
|
+
case 'object:has_key': {
|
|
413
|
+
await this.traverse(node, 'value');
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
clearLoopBodyMemo(loopNode) {
|
|
420
|
+
const nodesToClear = new Set();
|
|
421
|
+
const queue = [];
|
|
422
|
+
|
|
423
|
+
const initialConnection = this.activeGraph.connections.find(
|
|
424
|
+
c => c.sourceNodeId === loopNode.id && c.sourcePinId === 'loop_body'
|
|
425
|
+
);
|
|
426
|
+
if (initialConnection) {
|
|
427
|
+
const firstNode = this.activeGraph.nodes.find(n => n.id === initialConnection.targetNodeId);
|
|
428
|
+
if (firstNode) {
|
|
429
|
+
queue.push(firstNode);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const visited = new Set();
|
|
434
|
+
while (queue.length > 0) {
|
|
435
|
+
const currentNode = queue.shift();
|
|
436
|
+
if (visited.has(currentNode.id)) continue;
|
|
437
|
+
visited.add(currentNode.id);
|
|
438
|
+
|
|
439
|
+
nodesToClear.add(currentNode.id);
|
|
440
|
+
|
|
441
|
+
const connections = this.activeGraph.connections.filter(c => c.sourceNodeId === currentNode.id);
|
|
442
|
+
for (const conn of connections) {
|
|
443
|
+
const nextNode = this.activeGraph.nodes.find(n => n.id === conn.targetNodeId);
|
|
444
|
+
if (nextNode) {
|
|
445
|
+
queue.push(nextNode);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
for (const nodeId of nodesToClear) {
|
|
451
|
+
for (const key of this.memo.keys()) {
|
|
452
|
+
if (key.startsWith(nodeId)) {
|
|
453
|
+
this.memo.delete(key);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
async resolvePinValue(node, pinId, defaultValue = null) {
|
|
460
|
+
const connection = this.activeGraph.connections.find(c => c.targetNodeId === node.id && c.targetPinId === pinId);
|
|
461
|
+
if (connection) {
|
|
462
|
+
const sourceNode = this.activeGraph.nodes.find(n => n.id === connection.sourceNodeId);
|
|
463
|
+
return await this.evaluateOutputPin(sourceNode, connection.sourcePinId, defaultValue);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
let value = node.data && node.data[pinId] !== undefined ? node.data[pinId] : defaultValue;
|
|
467
|
+
|
|
468
|
+
// Автоматически заменяем переменные {varName} в строковых значениях
|
|
469
|
+
if (typeof value === 'string' && value.includes('{')) {
|
|
470
|
+
value = await this._replaceVariablesInString(value, node);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
return value;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Заменяет переменные {varName} на значения из пинов
|
|
478
|
+
* @private
|
|
479
|
+
*/
|
|
480
|
+
async _replaceVariablesInString(text, node) {
|
|
481
|
+
const variablePattern = /\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;
|
|
482
|
+
const matches = [...text.matchAll(variablePattern)];
|
|
483
|
+
|
|
484
|
+
let result = text;
|
|
485
|
+
|
|
486
|
+
for (const match of matches) {
|
|
487
|
+
const varName = match[1];
|
|
488
|
+
const varValue = await this.resolvePinValue(node, `var_${varName}`, '');
|
|
489
|
+
result = result.replace(match[0], String(varValue));
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
return result;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
async evaluateOutputPin(node, pinId, defaultValue = null) {
|
|
496
|
+
if (!node) return defaultValue;
|
|
497
|
+
|
|
498
|
+
const cacheKey = `${node.id}:${pinId}`;
|
|
499
|
+
if (this.memo.has(cacheKey)) {
|
|
500
|
+
return this.memo.get(cacheKey);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
const nodeConfig = this.nodeRegistry.getNodeConfig(node.type);
|
|
504
|
+
if (nodeConfig && typeof nodeConfig.evaluator === 'function') {
|
|
505
|
+
const helpers = {
|
|
506
|
+
resolvePinValue: this.resolvePinValue.bind(this),
|
|
507
|
+
memo: this.memo,
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
// Записываем data ноду в трассировку перед вычислением (только один раз)
|
|
511
|
+
const traceKey = `trace_recorded:${node.id}`;
|
|
512
|
+
const isDataNode = !nodeConfig.pins.inputs.some(p => p.type === 'Exec');
|
|
513
|
+
|
|
514
|
+
if (this.currentTraceId && isDataNode && !this.memo.has(traceKey)) {
|
|
515
|
+
// Это data нода (нет exec пинов) и она ещё не записана - записываем её inputs
|
|
516
|
+
const inputs = await this._captureNodeInputs(node);
|
|
517
|
+
|
|
518
|
+
this.traceCollector.recordStep(this.currentTraceId, {
|
|
519
|
+
nodeId: node.id,
|
|
520
|
+
nodeType: node.type,
|
|
521
|
+
status: 'executed',
|
|
522
|
+
duration: 0,
|
|
523
|
+
inputs,
|
|
524
|
+
outputs: {},
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
// Помечаем, что нода уже записана в трассировку
|
|
528
|
+
this.memo.set(traceKey, true);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
const result = await nodeConfig.evaluator.call(this, node, pinId, this.context, helpers);
|
|
532
|
+
|
|
533
|
+
const isVolatile = this.isNodeVolatile(node);
|
|
534
|
+
if (!isVolatile) {
|
|
535
|
+
this.memo.set(cacheKey, result);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// Обновляем outputs для data ноды после вычисления И после записи в memo
|
|
539
|
+
// Обновляем только один раз для всей ноды (не для каждого пина отдельно)
|
|
540
|
+
const traceOutputsKey = `trace_outputs_recorded:${node.id}`;
|
|
541
|
+
if (this.currentTraceId && isDataNode && this.memo.has(traceKey) && !this.memo.has(traceOutputsKey)) {
|
|
542
|
+
const outputs = {};
|
|
543
|
+
for (const outputPin of nodeConfig.pins.outputs) {
|
|
544
|
+
if (outputPin.type !== 'Exec') {
|
|
545
|
+
const outKey = `${node.id}:${outputPin.id}`;
|
|
546
|
+
if (this.memo.has(outKey)) {
|
|
547
|
+
outputs[outputPin.id] = this.memo.get(outKey);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
this.traceCollector.updateStepOutputs(this.currentTraceId, node.id, outputs);
|
|
552
|
+
this.memo.set(traceOutputsKey, true); // Помечаем, что outputs уже записаны
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
return result;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
let result;
|
|
559
|
+
|
|
560
|
+
switch (node.type) {
|
|
561
|
+
case 'user:set_blacklist':
|
|
562
|
+
result = this.memo.get(`${node.id}:updated_user`);
|
|
563
|
+
break;
|
|
564
|
+
case 'event:command':
|
|
565
|
+
if (pinId === 'args') result = this.context.eventArgs?.args || {};
|
|
566
|
+
else if (pinId === 'user') result = this.context.eventArgs?.user || {};
|
|
567
|
+
else if (pinId === 'chat_type') result = this.context.eventArgs?.typeChat || 'chat';
|
|
568
|
+
else if (pinId === 'command_name') result = this.context.eventArgs?.commandName;
|
|
569
|
+
else if (pinId === 'success') result = this.context.success !== undefined ? this.context.success : true;
|
|
570
|
+
else result = this.context.eventArgs?.[pinId];
|
|
571
|
+
break;
|
|
572
|
+
case 'event:chat':
|
|
573
|
+
if (pinId === 'username') result = this.context.eventArgs?.username || this.context.username;
|
|
574
|
+
else if (pinId === 'message') result = this.context.eventArgs?.message || this.context.message;
|
|
575
|
+
else if (pinId === 'chatType') result = this.context.eventArgs?.chatType || this.context.chat_type;
|
|
576
|
+
else result = this.context.eventArgs?.[pinId] || this.context[pinId];
|
|
577
|
+
break;
|
|
578
|
+
case 'event:raw_message':
|
|
579
|
+
if (pinId === 'rawText') result = this.context.eventArgs?.rawText || this.context.rawText;
|
|
580
|
+
else result = this.context.eventArgs?.[pinId] || this.context[pinId];
|
|
581
|
+
break;
|
|
582
|
+
case 'event:playerJoined':
|
|
583
|
+
case 'event:playerLeft':
|
|
584
|
+
if (pinId === 'user') result = this.context.eventArgs?.user || this.context.user;
|
|
585
|
+
else result = this.context.eventArgs?.[pinId] || this.context[pinId];
|
|
586
|
+
break;
|
|
587
|
+
case 'event:entitySpawn':
|
|
588
|
+
case 'event:entityMoved':
|
|
589
|
+
case 'event:entityGone':
|
|
590
|
+
if (pinId === 'entity') result = this.context.eventArgs?.entity || this.context.entity;
|
|
591
|
+
else result = this.context.eventArgs?.[pinId] || this.context[pinId];
|
|
592
|
+
break;
|
|
593
|
+
case 'event:health':
|
|
594
|
+
case 'event:botDied':
|
|
595
|
+
case 'event:botStartup':
|
|
596
|
+
result = this.context.eventArgs?.[pinId] || this.context[pinId];
|
|
597
|
+
break;
|
|
598
|
+
case 'event:websocket_call':
|
|
599
|
+
if (pinId === 'graphName') result = this.context.eventArgs?.graphName || this.context.graphName;
|
|
600
|
+
else if (pinId === 'data') result = this.context.eventArgs?.data || this.context.data;
|
|
601
|
+
else if (pinId === 'socketId') result = this.context.eventArgs?.socketId || this.context.socketId;
|
|
602
|
+
else if (pinId === 'keyPrefix') result = this.context.eventArgs?.keyPrefix || this.context.keyPrefix;
|
|
603
|
+
else result = this.context.eventArgs?.[pinId] || this.context[pinId];
|
|
604
|
+
break;
|
|
605
|
+
|
|
606
|
+
case 'flow:for_each': {
|
|
607
|
+
if (pinId === 'element') {
|
|
608
|
+
result = this.memo.get(`${node.id}:element`);
|
|
609
|
+
} else if (pinId === 'index') {
|
|
610
|
+
result = this.memo.get(`${node.id}:index`);
|
|
611
|
+
}
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
default:
|
|
616
|
+
result = defaultValue;
|
|
617
|
+
break;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
const isVolatile = this.isNodeVolatile(node);
|
|
621
|
+
|
|
622
|
+
if (!isVolatile) {
|
|
623
|
+
this.memo.set(cacheKey, result);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
return result;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
isNodeVolatile(node, visited = new Set(), depth = 0) {
|
|
630
|
+
if (!node) return false;
|
|
631
|
+
|
|
632
|
+
if (depth > MAX_RECURSION_DEPTH) {
|
|
633
|
+
console.warn(`[GraphExecutionEngine] isNodeVolatile достиг максимальной глубины рекурсии (${MAX_RECURSION_DEPTH})`);
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
if (visited.has(node.id)) {
|
|
638
|
+
return false;
|
|
639
|
+
}
|
|
640
|
+
visited.add(node.id);
|
|
641
|
+
|
|
642
|
+
if (node.type === 'data:get_variable') {
|
|
643
|
+
return true;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
const connections = this.activeGraph.connections.filter(c => c.targetNodeId === node.id);
|
|
647
|
+
for (const conn of connections) {
|
|
648
|
+
const sourceNode = this.activeGraph.nodes.find(n => n.id === conn.sourceNodeId);
|
|
649
|
+
if (this.isNodeVolatile(sourceNode, visited, depth + 1)) {
|
|
650
|
+
return true;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
return false;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
hasConnection(node, pinId) {
|
|
658
|
+
if (!this.activeGraph || !this.activeGraph.connections) return false;
|
|
659
|
+
return this.activeGraph.connections.some(conn =>
|
|
660
|
+
conn.targetNodeId === node.id && conn.targetPinId === pinId
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Захватить outputs для всех data-нод в trace
|
|
666
|
+
* Вызывается перед завершением trace, чтобы гарантировать,
|
|
667
|
+
* что для всех data-нод записаны outputs (даже если их выходы не подключены)
|
|
668
|
+
*/
|
|
669
|
+
async _captureAllDataNodeOutputs() {
|
|
670
|
+
if (!this.currentTraceId) return;
|
|
671
|
+
|
|
672
|
+
const trace = await this.traceCollector.getTrace(this.currentTraceId);
|
|
673
|
+
if (!trace || !trace.steps) return;
|
|
674
|
+
|
|
675
|
+
// Проходим по всем шагам и находим data-ноды
|
|
676
|
+
for (const step of trace.steps) {
|
|
677
|
+
if (step.type === 'traversal') continue;
|
|
678
|
+
|
|
679
|
+
// Проверяем, есть ли уже outputs
|
|
680
|
+
if (step.outputs && Object.keys(step.outputs).length > 0) continue;
|
|
681
|
+
|
|
682
|
+
// Находим ноду в графе
|
|
683
|
+
const node = this.activeGraph.nodes.find(n => n.id === step.nodeId);
|
|
684
|
+
if (!node) continue;
|
|
685
|
+
|
|
686
|
+
// Получаем конфигурацию ноды
|
|
687
|
+
const nodeConfig = this.nodeRegistry.getNodeConfig(node.type);
|
|
688
|
+
if (!nodeConfig) continue;
|
|
689
|
+
|
|
690
|
+
// Проверяем, является ли это data-нодой (нет exec входов)
|
|
691
|
+
const isDataNode = !nodeConfig.pins.inputs.some(p => p.type === 'Exec');
|
|
692
|
+
if (!isDataNode) continue;
|
|
693
|
+
|
|
694
|
+
// Захватываем outputs
|
|
695
|
+
try {
|
|
696
|
+
const outputs = await this._captureNodeOutputs(node);
|
|
697
|
+
if (outputs && Object.keys(outputs).length > 0) {
|
|
698
|
+
this.traceCollector.updateStepOutputs(this.currentTraceId, node.id, outputs);
|
|
699
|
+
}
|
|
700
|
+
} catch (error) {
|
|
701
|
+
console.error(`[GraphExecutor] Error capturing outputs for data node ${node.id}:`, error);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* Захватить значения входов ноды для трассировки
|
|
708
|
+
*/
|
|
709
|
+
async _captureNodeInputs(node) {
|
|
710
|
+
const inputs = {};
|
|
711
|
+
|
|
712
|
+
// Получаем конфигурацию ноды
|
|
713
|
+
const nodeConfig = this.nodeRegistry.getNodeConfig(node.type);
|
|
714
|
+
if (!nodeConfig || !nodeConfig.pins || !nodeConfig.pins.inputs) {
|
|
715
|
+
return inputs;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
// Захватываем значения всех входов
|
|
719
|
+
for (const inputPin of nodeConfig.pins.inputs) {
|
|
720
|
+
if (inputPin.type === 'Exec') continue; // Пропускаем exec пины
|
|
721
|
+
|
|
722
|
+
try {
|
|
723
|
+
// Используем resolvePinValue для получения актуального значения
|
|
724
|
+
const value = await this.resolvePinValue(node, inputPin.id);
|
|
725
|
+
// Записываем все значения, включая undefined и null
|
|
726
|
+
inputs[inputPin.id] = value;
|
|
727
|
+
} catch (error) {
|
|
728
|
+
inputs[inputPin.id] = '<error capturing>';
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
return inputs;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Захватить значения выходов ноды для трассировки
|
|
736
|
+
*/
|
|
737
|
+
async _captureNodeOutputs(node) {
|
|
738
|
+
const outputs = {};
|
|
739
|
+
|
|
740
|
+
// Получаем конфигурацию ноды
|
|
741
|
+
const nodeConfig = this.nodeRegistry.getNodeConfig(node.type);
|
|
742
|
+
if (!nodeConfig || !nodeConfig.pins || !nodeConfig.pins.outputs) {
|
|
743
|
+
return outputs;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// Захватываем значения всех выходов
|
|
747
|
+
for (const outputPin of nodeConfig.pins.outputs) {
|
|
748
|
+
if (outputPin.type === 'Exec') continue; // Пропускаем exec пины
|
|
749
|
+
|
|
750
|
+
try {
|
|
751
|
+
// Активно вызываем evaluateOutputPin вместо чтения из memo
|
|
752
|
+
// Это необходимо для event нод, которые используют switch-case и не пишут в memo
|
|
753
|
+
const value = await this.evaluateOutputPin(node, outputPin.id);
|
|
754
|
+
// Записываем все значения, включая undefined и null
|
|
755
|
+
outputs[outputPin.id] = value;
|
|
756
|
+
} catch (error) {
|
|
757
|
+
outputs[outputPin.id] = '<error capturing>';
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
return outputs;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* Проверить брейкпоинт перед выполнением ноды
|
|
765
|
+
*/
|
|
766
|
+
async checkBreakpoint(node) {
|
|
767
|
+
try {
|
|
768
|
+
// Если работаем в дочернем процессе, используем IPC
|
|
769
|
+
if (process.send) {
|
|
770
|
+
return await this._checkBreakpointViaIpc(node);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
// Иначе используем прямой доступ к DebugManager
|
|
774
|
+
const debugManager = getGlobalDebugManager();
|
|
775
|
+
const graphId = this.context.graphId;
|
|
776
|
+
|
|
777
|
+
if (!graphId) return;
|
|
778
|
+
|
|
779
|
+
const debugState = debugManager.get(graphId);
|
|
780
|
+
if (!debugState) return;
|
|
781
|
+
|
|
782
|
+
const breakpoint = debugState.breakpoints.get(node.id);
|
|
783
|
+
if (!breakpoint || !breakpoint.enabled) return;
|
|
784
|
+
|
|
785
|
+
const shouldPause = await this.evaluateBreakpointCondition(breakpoint);
|
|
786
|
+
|
|
787
|
+
if (shouldPause) {
|
|
788
|
+
console.log(`[Debug] Hit breakpoint at node ${node.id}, pausing execution`);
|
|
789
|
+
|
|
790
|
+
breakpoint.hitCount++;
|
|
791
|
+
|
|
792
|
+
const inputs = await this._captureNodeInputs(node);
|
|
793
|
+
|
|
794
|
+
const executedSteps = this.currentTraceId
|
|
795
|
+
? await this.traceCollector.getTrace(this.currentTraceId)
|
|
796
|
+
: null;
|
|
797
|
+
|
|
798
|
+
const overrides = await debugState.pause({
|
|
799
|
+
nodeId: node.id,
|
|
800
|
+
nodeType: node.type,
|
|
801
|
+
inputs,
|
|
802
|
+
executedSteps, // Добавляем выполненные шаги
|
|
803
|
+
context: {
|
|
804
|
+
user: this.context.user,
|
|
805
|
+
variables: this.context.variables,
|
|
806
|
+
commandArguments: this.context.commandArguments,
|
|
807
|
+
},
|
|
808
|
+
breakpoint: {
|
|
809
|
+
condition: breakpoint.condition,
|
|
810
|
+
hitCount: breakpoint.hitCount
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
if (overrides && overrides.__stopped) {
|
|
815
|
+
throw new Error('Execution stopped by debugger');
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
if (overrides) {
|
|
819
|
+
this.applyWhatIfOverrides(node, overrides);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
} catch (error) {
|
|
823
|
+
console.error(`[checkBreakpoint] ERROR:`, error.message, error.stack);
|
|
824
|
+
if (error.message === 'DebugSessionManager not initialized! Call initializeDebugManager(io) first.') {
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
// НЕ пробрасываем ошибку дальше, чтобы не сломать выполнение
|
|
828
|
+
console.error(`[checkBreakpoint] Ignoring error to continue execution`);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Оценить условие брейкпоинта
|
|
834
|
+
*/
|
|
835
|
+
async evaluateBreakpointCondition(breakpoint) {
|
|
836
|
+
// Если нет условия, всегда срабатывает
|
|
837
|
+
if (!breakpoint.condition || breakpoint.condition.trim() === '') {
|
|
838
|
+
return true;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
try {
|
|
842
|
+
// Создаем sandbox для безопасного выполнения условия
|
|
843
|
+
const sandbox = {
|
|
844
|
+
user: this.context.user || {},
|
|
845
|
+
args: this.context.commandArguments || {},
|
|
846
|
+
variables: this.context.variables || {},
|
|
847
|
+
context: this.context
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
// Используем Function constructor для безопасного выполнения
|
|
851
|
+
const fn = new Function(
|
|
852
|
+
...Object.keys(sandbox),
|
|
853
|
+
`return (${breakpoint.condition})`
|
|
854
|
+
);
|
|
855
|
+
|
|
856
|
+
const result = fn(...Object.values(sandbox));
|
|
857
|
+
|
|
858
|
+
return Boolean(result);
|
|
859
|
+
} catch (error) {
|
|
860
|
+
console.error(`[Debug] Error evaluating breakpoint condition: ${error.message}`);
|
|
861
|
+
console.error(`[Debug] Condition was: ${breakpoint.condition}`);
|
|
862
|
+
return false;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* Применить what-if overrides к ноде
|
|
868
|
+
*/
|
|
869
|
+
/**
|
|
870
|
+
* Проверить брейкпоинт через IPC (для дочерних процессов)
|
|
871
|
+
*/
|
|
872
|
+
async _checkBreakpointViaIpc(node) {
|
|
873
|
+
try {
|
|
874
|
+
const { randomUUID } = require('crypto');
|
|
875
|
+
const requestId = randomUUID();
|
|
876
|
+
|
|
877
|
+
const inputs = await this._captureNodeInputs(node);
|
|
878
|
+
const executedSteps = this.currentTraceId
|
|
879
|
+
? await this.traceCollector.getTrace(this.currentTraceId)
|
|
880
|
+
: null;
|
|
881
|
+
|
|
882
|
+
// Отправляем запрос в главный процесс
|
|
883
|
+
process.send({
|
|
884
|
+
type: 'debug:check_breakpoint',
|
|
885
|
+
requestId,
|
|
886
|
+
payload: {
|
|
887
|
+
graphId: this.context.graphId,
|
|
888
|
+
nodeId: node.id,
|
|
889
|
+
nodeType: node.type,
|
|
890
|
+
inputs,
|
|
891
|
+
executedSteps,
|
|
892
|
+
context: {
|
|
893
|
+
user: this.context.user,
|
|
894
|
+
variables: this.context.variables,
|
|
895
|
+
commandArguments: this.context.commandArguments,
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
});
|
|
899
|
+
|
|
900
|
+
// Ждём ответа
|
|
901
|
+
const overrides = await new Promise((resolve) => {
|
|
902
|
+
this.pendingDebugRequests.set(requestId, resolve);
|
|
903
|
+
|
|
904
|
+
// Таймаут на случай, если ответ не придёт
|
|
905
|
+
const timeoutId = setTimeout(() => {
|
|
906
|
+
if (this.pendingDebugRequests.has(requestId)) {
|
|
907
|
+
this.pendingDebugRequests.delete(requestId);
|
|
908
|
+
resolve(null);
|
|
909
|
+
}
|
|
910
|
+
}, debugConfig.BREAKPOINT_TIMEOUT);
|
|
911
|
+
|
|
912
|
+
// Сохраняем timeoutId для возможной отмены
|
|
913
|
+
this.pendingDebugRequests.set(`${requestId}_timeout`, timeoutId);
|
|
914
|
+
});
|
|
915
|
+
|
|
916
|
+
if (overrides && overrides.__stopped) {
|
|
917
|
+
throw new Error('Execution stopped by debugger');
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
if (overrides) {
|
|
921
|
+
this.applyWhatIfOverrides(node, overrides);
|
|
922
|
+
}
|
|
923
|
+
} catch (error) {
|
|
924
|
+
if (error.message === 'Execution stopped by debugger') {
|
|
925
|
+
throw error;
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* Статический обработчик IPC ответов (глобальный для всех instances)
|
|
932
|
+
*/
|
|
933
|
+
static _handleGlobalDebugResponse(message) {
|
|
934
|
+
const { requestId, overrides } = message;
|
|
935
|
+
const resolve = GraphExecutionEngine._allPendingRequests.get(requestId);
|
|
936
|
+
|
|
937
|
+
if (resolve) {
|
|
938
|
+
// Отменяем таймаут
|
|
939
|
+
const timeoutId = GraphExecutionEngine._allPendingRequests.get(`${requestId}_timeout`);
|
|
940
|
+
if (timeoutId) {
|
|
941
|
+
clearTimeout(timeoutId);
|
|
942
|
+
GraphExecutionEngine._allPendingRequests.delete(`${requestId}_timeout`);
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
GraphExecutionEngine._allPendingRequests.delete(requestId);
|
|
946
|
+
resolve(overrides);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/**
|
|
951
|
+
* Обработать IPC ответ от главного процесса (legacy wrapper)
|
|
952
|
+
*/
|
|
953
|
+
_handleDebugResponse(message) {
|
|
954
|
+
GraphExecutionEngine._handleGlobalDebugResponse(message);
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
applyWhatIfOverrides(node, overrides) {
|
|
958
|
+
if (!overrides || typeof overrides !== 'object') return;
|
|
959
|
+
|
|
960
|
+
console.log(`[Debug] Applying what-if overrides to node ${node.id}:`, overrides);
|
|
961
|
+
|
|
962
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
963
|
+
if (key === '__stopped') continue;
|
|
964
|
+
|
|
965
|
+
// Парсим ключ для определения типа изменения
|
|
966
|
+
// Форматы:
|
|
967
|
+
// - "var.varName" - переменная графа
|
|
968
|
+
// - "nodeId.out.pinName" - выходной пин ноды
|
|
969
|
+
// - "nodeId.in.pinName" - входной пин ноды
|
|
970
|
+
// - "pinName" - входной пин текущей ноды
|
|
971
|
+
|
|
972
|
+
if (key.startsWith('var.')) {
|
|
973
|
+
// Изменение переменной графа
|
|
974
|
+
const varName = key.substring(4);
|
|
975
|
+
if (!this.context.variables) {
|
|
976
|
+
this.context.variables = {};
|
|
977
|
+
}
|
|
978
|
+
this.context.variables[varName] = value;
|
|
979
|
+
console.log(`[Debug] Variable override: ${varName} = ${JSON.stringify(value)}`);
|
|
980
|
+
}
|
|
981
|
+
else if (key.includes('.out.')) {
|
|
982
|
+
// Изменение выходного пина ноды
|
|
983
|
+
const [nodeId, , pinName] = key.split('.');
|
|
984
|
+
const memoKey = `${nodeId}:${pinName}`;
|
|
985
|
+
this.memo.set(memoKey, value);
|
|
986
|
+
console.log(`[Debug] Output override: ${memoKey} = ${JSON.stringify(value)}`);
|
|
987
|
+
}
|
|
988
|
+
else if (key.includes('.in.')) {
|
|
989
|
+
// Изменение входного пина ноды (пока не применяется, но можно расширить)
|
|
990
|
+
const [nodeId, , pinName] = key.split('.');
|
|
991
|
+
console.log(`[Debug] Input override (informational): ${nodeId}.${pinName} = ${JSON.stringify(value)}`);
|
|
992
|
+
// Входы можно изменить через изменение outputs предыдущих нод или переменных
|
|
993
|
+
}
|
|
994
|
+
else {
|
|
995
|
+
// Изменение входного пина текущей ноды
|
|
996
|
+
if (!node.data) {
|
|
997
|
+
node.data = {};
|
|
998
|
+
}
|
|
999
|
+
node.data[key] = value;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
|
|
322
1005
|
module.exports = GraphExecutionEngine;
|