@createlex/createlexgenai 1.0.4 → 1.0.5
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/README.md +7 -7
- package/package.json +1 -1
- package/src/core/remote-execution.js +202 -106
package/README.md
CHANGED
|
@@ -63,22 +63,22 @@ You need **at least one** of these enabled in your Unreal project. Both are buil
|
|
|
63
63
|
|
|
64
64
|
1. Open your UE project
|
|
65
65
|
2. Go to **Edit > Plugins**
|
|
66
|
-
3.
|
|
66
|
+
3. Enable **"Remote Control API"** and **"Remote Control Web Interface"**
|
|
67
67
|
4. Restart the editor
|
|
68
68
|
5. Go to **Edit > Project Settings > Plugins > Remote Control**
|
|
69
|
-
6.
|
|
70
|
-
7. Set
|
|
71
|
-
8.
|
|
69
|
+
6. Under **Remote Control Web Server**, check **"Auto Start Web Server"**
|
|
70
|
+
7. Set **"Remote Control HTTP Server Port"** to **30010** (default)
|
|
71
|
+
8. Under **Remote Control > Security**, check **"Enable Remote Python Execution"**
|
|
72
72
|
|
|
73
73
|
#### Option B: Python Remote Execution
|
|
74
74
|
|
|
75
75
|
1. Open your UE project
|
|
76
76
|
2. Go to **Edit > Plugins**
|
|
77
|
-
3.
|
|
77
|
+
3. Enable **"Python Editor Script Plugin"**
|
|
78
78
|
4. Restart the editor
|
|
79
79
|
5. Go to **Edit > Project Settings > Plugins > Python**
|
|
80
|
-
6.
|
|
81
|
-
7. Multicast
|
|
80
|
+
6. Under **Python Remote Execution**, check **"Enable Remote Execution?"**
|
|
81
|
+
7. Multicast Group Endpoint: `239.0.0.1:6766`, Multicast Bind Address: `127.0.0.1` (defaults)
|
|
82
82
|
|
|
83
83
|
> **Tip:** Enable both for maximum reliability. If one backend is unavailable, the CLI automatically falls back to the other.
|
|
84
84
|
|
package/package.json
CHANGED
|
@@ -4,21 +4,58 @@ const dgram = require('dgram');
|
|
|
4
4
|
const net = require('net');
|
|
5
5
|
const crypto = require('crypto');
|
|
6
6
|
|
|
7
|
-
// UE Python Remote Execution protocol constants
|
|
7
|
+
// UE Python Remote Execution protocol constants (from remote_execution.py)
|
|
8
8
|
const PROTOCOL_MAGIC = 'ue_py';
|
|
9
9
|
const PROTOCOL_VERSION = 1;
|
|
10
10
|
|
|
11
11
|
const MULTICAST_GROUP = '239.0.0.1';
|
|
12
12
|
const MULTICAST_PORT = 6766;
|
|
13
|
-
const
|
|
13
|
+
const MULTICAST_BIND_ADDRESS = '127.0.0.1';
|
|
14
|
+
const MULTICAST_TTL = 0;
|
|
15
|
+
|
|
16
|
+
const DEFAULT_COMMAND_ENDPOINT = ['127.0.0.1', 6776];
|
|
17
|
+
const DEFAULT_RECEIVE_BUFFER_SIZE = 8192;
|
|
14
18
|
|
|
15
19
|
const DISCOVERY_TIMEOUT = 3000;
|
|
16
|
-
const CONNECT_TIMEOUT = 10000;
|
|
17
20
|
const COMMAND_TIMEOUT = 30000;
|
|
18
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Build a protocol message matching UE's _RemoteExecutionMessage.to_json() format.
|
|
24
|
+
*/
|
|
25
|
+
function buildMessage(type, source, dest, data) {
|
|
26
|
+
const msg = {
|
|
27
|
+
version: PROTOCOL_VERSION,
|
|
28
|
+
magic: PROTOCOL_MAGIC,
|
|
29
|
+
type: type,
|
|
30
|
+
source: source
|
|
31
|
+
};
|
|
32
|
+
if (dest) {
|
|
33
|
+
msg.dest = dest;
|
|
34
|
+
}
|
|
35
|
+
if (data) {
|
|
36
|
+
msg.data = data;
|
|
37
|
+
}
|
|
38
|
+
return JSON.stringify(msg);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Parse and validate a received protocol message.
|
|
43
|
+
*/
|
|
44
|
+
function parseMessage(buf) {
|
|
45
|
+
try {
|
|
46
|
+
const msg = JSON.parse(buf.toString('utf-8'));
|
|
47
|
+
if (msg.version !== PROTOCOL_VERSION) return null;
|
|
48
|
+
if (msg.magic !== PROTOCOL_MAGIC) return null;
|
|
49
|
+
if (!msg.type || !msg.source) return null;
|
|
50
|
+
return msg;
|
|
51
|
+
} catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
19
56
|
/**
|
|
20
57
|
* Discover running Unreal Engine instances via UDP multicast ping.
|
|
21
|
-
*
|
|
58
|
+
* Matches UE's _RemoteExecutionBroadcastConnection protocol exactly.
|
|
22
59
|
*/
|
|
23
60
|
function discover(timeout = DISCOVERY_TIMEOUT) {
|
|
24
61
|
return new Promise((resolve) => {
|
|
@@ -28,56 +65,62 @@ function discover(timeout = DISCOVERY_TIMEOUT) {
|
|
|
28
65
|
const socket = dgram.createSocket({ type: 'udp4', reuseAddr: true });
|
|
29
66
|
|
|
30
67
|
const timer = setTimeout(() => {
|
|
31
|
-
socket.close();
|
|
68
|
+
try { socket.close(); } catch {}
|
|
32
69
|
resolve(nodes);
|
|
33
70
|
}, timeout);
|
|
34
71
|
|
|
35
72
|
socket.on('message', (msg) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// Ignore non-JSON or malformed messages
|
|
73
|
+
const message = parseMessage(msg);
|
|
74
|
+
if (!message) return;
|
|
75
|
+
|
|
76
|
+
// Filter: must not be from self, must be a pong
|
|
77
|
+
if (message.source === nodeId) return;
|
|
78
|
+
if (message.dest && message.dest !== nodeId) return;
|
|
79
|
+
if (message.type !== 'pong') return;
|
|
80
|
+
|
|
81
|
+
// Avoid duplicates
|
|
82
|
+
if (!nodes.find(n => n.node_id === message.source)) {
|
|
83
|
+
nodes.push({
|
|
84
|
+
node_id: message.source,
|
|
85
|
+
...(message.data || {})
|
|
86
|
+
});
|
|
51
87
|
}
|
|
52
88
|
});
|
|
53
89
|
|
|
54
90
|
socket.on('error', () => {
|
|
55
91
|
clearTimeout(timer);
|
|
56
|
-
socket.close();
|
|
92
|
+
try { socket.close(); } catch {}
|
|
57
93
|
resolve(nodes);
|
|
58
94
|
});
|
|
59
95
|
|
|
60
|
-
|
|
96
|
+
// Bind to the same port and address as UE expects
|
|
97
|
+
socket.bind(MULTICAST_PORT, MULTICAST_BIND_ADDRESS, () => {
|
|
61
98
|
try {
|
|
62
|
-
socket
|
|
99
|
+
// Match UE's socket options
|
|
100
|
+
socket.setMulticastLoopback(true);
|
|
101
|
+
socket.setMulticastTTL(MULTICAST_TTL);
|
|
102
|
+
socket.setMulticastInterface(MULTICAST_BIND_ADDRESS);
|
|
103
|
+
socket.addMembership(MULTICAST_GROUP, MULTICAST_BIND_ADDRESS);
|
|
63
104
|
} catch {
|
|
64
105
|
// Multicast may not be available
|
|
65
106
|
}
|
|
66
107
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
version: PROTOCOL_VERSION,
|
|
70
|
-
type: 'ping',
|
|
71
|
-
source: nodeId
|
|
72
|
-
});
|
|
73
|
-
|
|
108
|
+
// Send ping (matches UE's _broadcast_ping)
|
|
109
|
+
const ping = buildMessage('ping', nodeId);
|
|
74
110
|
socket.send(ping, 0, ping.length, MULTICAST_PORT, MULTICAST_GROUP, (err) => {
|
|
75
111
|
if (err) {
|
|
76
112
|
clearTimeout(timer);
|
|
77
|
-
socket.close();
|
|
113
|
+
try { socket.close(); } catch {}
|
|
78
114
|
resolve(nodes);
|
|
79
115
|
}
|
|
80
116
|
});
|
|
117
|
+
|
|
118
|
+
// Send a second ping after 1 second (UE pings every _NODE_PING_SECONDS = 1)
|
|
119
|
+
setTimeout(() => {
|
|
120
|
+
try {
|
|
121
|
+
socket.send(ping, 0, ping.length, MULTICAST_PORT, MULTICAST_GROUP);
|
|
122
|
+
} catch {}
|
|
123
|
+
}, 1000);
|
|
81
124
|
});
|
|
82
125
|
});
|
|
83
126
|
}
|
|
@@ -85,22 +128,18 @@ function discover(timeout = DISCOVERY_TIMEOUT) {
|
|
|
85
128
|
/**
|
|
86
129
|
* Execute a Python command on a discovered UE instance via the Remote Execution protocol.
|
|
87
130
|
*
|
|
88
|
-
*
|
|
89
|
-
* 1.
|
|
90
|
-
* 2.
|
|
91
|
-
* 3.
|
|
92
|
-
* 4.
|
|
93
|
-
*
|
|
94
|
-
* @param {string} command - Python code to execute
|
|
95
|
-
* @param {object} options
|
|
96
|
-
* @param {string} options.nodeId - Target node ID from discovery (optional, broadcasts if omitted)
|
|
97
|
-
* @param {string} options.execMode - 'ExecuteStatement', 'EvaluateStatement', or 'ExecuteFile'
|
|
98
|
-
* @param {number} options.timeout - Command timeout in ms
|
|
131
|
+
* Matches UE's _RemoteExecutionCommandConnection flow:
|
|
132
|
+
* 1. Start TCP listen server on command_endpoint
|
|
133
|
+
* 2. Send open_connection via UDP multicast targeting the node
|
|
134
|
+
* 3. Accept TCP connection from UE
|
|
135
|
+
* 4. Send command message over TCP
|
|
136
|
+
* 5. Receive command_result over TCP
|
|
99
137
|
*/
|
|
100
138
|
function executeCommand(command, options = {}) {
|
|
101
139
|
const {
|
|
102
140
|
nodeId = null,
|
|
103
|
-
execMode = '
|
|
141
|
+
execMode = 'ExecuteFile',
|
|
142
|
+
unattended = true,
|
|
104
143
|
timeout = COMMAND_TIMEOUT
|
|
105
144
|
} = options;
|
|
106
145
|
|
|
@@ -108,104 +147,162 @@ function executeCommand(command, options = {}) {
|
|
|
108
147
|
|
|
109
148
|
return new Promise((resolve, reject) => {
|
|
110
149
|
const timer = setTimeout(() => {
|
|
111
|
-
|
|
150
|
+
cleanup();
|
|
151
|
+
reject(new Error('Remote execution timed out. Ensure "Enable Remote Execution" is checked in UE Project Settings > Python.'));
|
|
112
152
|
}, timeout);
|
|
113
153
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
let responseBuffer = '';
|
|
154
|
+
let tcpServer = null;
|
|
155
|
+
let udpSocket = null;
|
|
117
156
|
|
|
157
|
+
function cleanup() {
|
|
158
|
+
clearTimeout(timer);
|
|
159
|
+
try { if (tcpServer) tcpServer.close(); } catch {}
|
|
160
|
+
try { if (udpSocket) udpSocket.close(); } catch {}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Step 1: Create TCP server to accept connection from UE
|
|
164
|
+
tcpServer = net.createServer((socket) => {
|
|
165
|
+
socket.setNoDelay(true);
|
|
166
|
+
let responseBuffer = Buffer.alloc(0);
|
|
167
|
+
|
|
168
|
+
// Step 4: Send command once UE connects
|
|
169
|
+
const commandMsg = buildMessage('command', clientId, nodeId || '', {
|
|
170
|
+
command: command,
|
|
171
|
+
unattended: unattended,
|
|
172
|
+
exec_mode: execMode
|
|
173
|
+
});
|
|
174
|
+
socket.write(commandMsg, 'utf-8');
|
|
175
|
+
|
|
176
|
+
// Step 5: Receive command_result
|
|
118
177
|
socket.on('data', (data) => {
|
|
119
|
-
responseBuffer
|
|
178
|
+
responseBuffer = Buffer.concat([responseBuffer, data]);
|
|
120
179
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
clearTimeout(timer);
|
|
125
|
-
tcpServer.close();
|
|
180
|
+
const message = parseMessage(responseBuffer);
|
|
181
|
+
if (message && message.type === 'command_result') {
|
|
182
|
+
cleanup();
|
|
126
183
|
socket.destroy();
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
outputLog: result.output_log || []
|
|
134
|
-
});
|
|
135
|
-
} else {
|
|
136
|
-
resolve({ success: true, raw: result });
|
|
137
|
-
}
|
|
138
|
-
} catch {
|
|
139
|
-
// Keep buffering
|
|
184
|
+
resolve({
|
|
185
|
+
success: message.data ? message.data.success !== false : true,
|
|
186
|
+
output: message.data?.output || '',
|
|
187
|
+
result: message.data?.result || null,
|
|
188
|
+
outputLog: message.data?.output_log || []
|
|
189
|
+
});
|
|
140
190
|
}
|
|
141
191
|
});
|
|
142
192
|
|
|
143
193
|
socket.on('error', (err) => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
reject(new Error(`TCP socket error: ${err.message}`));
|
|
194
|
+
cleanup();
|
|
195
|
+
reject(new Error(`TCP command socket error: ${err.message}`));
|
|
147
196
|
});
|
|
148
|
-
|
|
149
|
-
// Step 3: Once UE connects, send the command
|
|
150
|
-
const commandMsg = JSON.stringify({
|
|
151
|
-
magic: PROTOCOL_MAGIC,
|
|
152
|
-
version: PROTOCOL_VERSION,
|
|
153
|
-
type: 'command',
|
|
154
|
-
source: clientId,
|
|
155
|
-
command: command,
|
|
156
|
-
unattended: false,
|
|
157
|
-
exec_mode: execMode
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
socket.write(commandMsg);
|
|
161
197
|
});
|
|
162
198
|
|
|
163
199
|
tcpServer.on('error', (err) => {
|
|
164
|
-
|
|
200
|
+
cleanup();
|
|
165
201
|
reject(new Error(`TCP server error: ${err.message}`));
|
|
166
202
|
});
|
|
167
203
|
|
|
168
|
-
//
|
|
169
|
-
|
|
170
|
-
|
|
204
|
+
// Listen on the command endpoint
|
|
205
|
+
const commandPort = DEFAULT_COMMAND_ENDPOINT[1];
|
|
206
|
+
const commandHost = DEFAULT_COMMAND_ENDPOINT[0];
|
|
171
207
|
|
|
172
|
-
|
|
208
|
+
tcpServer.listen(commandPort, commandHost, () => {
|
|
209
|
+
// Step 2: Send open_connection via UDP multicast
|
|
210
|
+
udpSocket = dgram.createSocket({ type: 'udp4', reuseAddr: true });
|
|
173
211
|
|
|
174
|
-
udpSocket.bind(0,
|
|
212
|
+
udpSocket.bind(0, MULTICAST_BIND_ADDRESS, () => {
|
|
175
213
|
try {
|
|
176
|
-
udpSocket.
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
214
|
+
udpSocket.setMulticastLoopback(true);
|
|
215
|
+
udpSocket.setMulticastTTL(MULTICAST_TTL);
|
|
216
|
+
udpSocket.setMulticastInterface(MULTICAST_BIND_ADDRESS);
|
|
217
|
+
udpSocket.addMembership(MULTICAST_GROUP, MULTICAST_BIND_ADDRESS);
|
|
218
|
+
} catch {}
|
|
180
219
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
source: clientId,
|
|
186
|
-
dest: nodeId || '',
|
|
187
|
-
command_ip: '127.0.0.1',
|
|
188
|
-
command_port: tcpPort
|
|
220
|
+
// Send open_connection (UE retries 6 times with 5s waits)
|
|
221
|
+
const openMsg = buildMessage('open_connection', clientId, nodeId || '', {
|
|
222
|
+
command_ip: commandHost,
|
|
223
|
+
command_port: commandPort
|
|
189
224
|
});
|
|
190
225
|
|
|
191
226
|
udpSocket.send(openMsg, 0, openMsg.length, MULTICAST_PORT, MULTICAST_GROUP, () => {
|
|
192
|
-
udpSocket.close();
|
|
227
|
+
try { udpSocket.close(); } catch {}
|
|
228
|
+
udpSocket = null;
|
|
193
229
|
});
|
|
194
230
|
});
|
|
195
231
|
});
|
|
232
|
+
|
|
233
|
+
// If command port is in use, try a random port
|
|
234
|
+
tcpServer.on('error', (err) => {
|
|
235
|
+
if (err.code === 'EADDRINUSE') {
|
|
236
|
+
tcpServer = net.createServer((socket) => {
|
|
237
|
+
socket.setNoDelay(true);
|
|
238
|
+
let responseBuffer = Buffer.alloc(0);
|
|
239
|
+
|
|
240
|
+
const commandMsg = buildMessage('command', clientId, nodeId || '', {
|
|
241
|
+
command: command,
|
|
242
|
+
unattended: unattended,
|
|
243
|
+
exec_mode: execMode
|
|
244
|
+
});
|
|
245
|
+
socket.write(commandMsg, 'utf-8');
|
|
246
|
+
|
|
247
|
+
socket.on('data', (data) => {
|
|
248
|
+
responseBuffer = Buffer.concat([responseBuffer, data]);
|
|
249
|
+
const message = parseMessage(responseBuffer);
|
|
250
|
+
if (message && message.type === 'command_result') {
|
|
251
|
+
cleanup();
|
|
252
|
+
socket.destroy();
|
|
253
|
+
resolve({
|
|
254
|
+
success: message.data ? message.data.success !== false : true,
|
|
255
|
+
output: message.data?.output || '',
|
|
256
|
+
result: message.data?.result || null,
|
|
257
|
+
outputLog: message.data?.output_log || []
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
socket.on('error', (err2) => {
|
|
263
|
+
cleanup();
|
|
264
|
+
reject(new Error(`TCP command socket error: ${err2.message}`));
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
tcpServer.listen(0, commandHost, () => {
|
|
269
|
+
const actualPort = tcpServer.address().port;
|
|
270
|
+
udpSocket = dgram.createSocket({ type: 'udp4', reuseAddr: true });
|
|
271
|
+
|
|
272
|
+
udpSocket.bind(0, MULTICAST_BIND_ADDRESS, () => {
|
|
273
|
+
try {
|
|
274
|
+
udpSocket.setMulticastLoopback(true);
|
|
275
|
+
udpSocket.setMulticastTTL(MULTICAST_TTL);
|
|
276
|
+
udpSocket.setMulticastInterface(MULTICAST_BIND_ADDRESS);
|
|
277
|
+
udpSocket.addMembership(MULTICAST_GROUP, MULTICAST_BIND_ADDRESS);
|
|
278
|
+
} catch {}
|
|
279
|
+
|
|
280
|
+
const openMsg = buildMessage('open_connection', clientId, nodeId || '', {
|
|
281
|
+
command_ip: commandHost,
|
|
282
|
+
command_port: actualPort
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
udpSocket.send(openMsg, 0, openMsg.length, MULTICAST_PORT, MULTICAST_GROUP, () => {
|
|
286
|
+
try { udpSocket.close(); } catch {}
|
|
287
|
+
udpSocket = null;
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
});
|
|
196
293
|
});
|
|
197
294
|
}
|
|
198
295
|
|
|
199
296
|
/**
|
|
200
|
-
* Quick test: discover
|
|
297
|
+
* Quick test: discover remote nodes.
|
|
201
298
|
*/
|
|
202
299
|
async function testConnection() {
|
|
203
300
|
try {
|
|
204
|
-
const nodes = await discover(
|
|
301
|
+
const nodes = await discover(3000);
|
|
205
302
|
if (nodes.length === 0) {
|
|
206
303
|
return {
|
|
207
304
|
available: false,
|
|
208
|
-
error: 'No UE instances found via Remote Execution. Enable "Python Editor Script Plugin" and "
|
|
305
|
+
error: 'No UE instances found via Remote Execution. Enable "Python Editor Script Plugin" and check "Enable Remote Execution" in Project Settings > Python.'
|
|
209
306
|
};
|
|
210
307
|
}
|
|
211
308
|
return {
|
|
@@ -223,6 +320,5 @@ module.exports = {
|
|
|
223
320
|
executeCommand,
|
|
224
321
|
testConnection,
|
|
225
322
|
MULTICAST_GROUP,
|
|
226
|
-
MULTICAST_PORT
|
|
227
|
-
COMMAND_PORT
|
|
323
|
+
MULTICAST_PORT
|
|
228
324
|
};
|