mindexec-ai 0.2.385

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.
Files changed (99) hide show
  1. package/README.md +354 -0
  2. package/codex-runtime.js +1339 -0
  3. package/launch-bridge.cjs +236 -0
  4. package/package.json +77 -0
  5. package/port-guard.cjs +232 -0
  6. package/remote-fast/osx-arm64/mindexec-remote-fast +0 -0
  7. package/remote-fast/osx-arm64/mindexec-remote-fast.deps.json +24 -0
  8. package/remote-fast/osx-arm64/mindexec-remote-fast.dll +0 -0
  9. package/remote-fast/osx-arm64/mindexec-remote-fast.runtimeconfig.json +13 -0
  10. package/remote-fast/osx-x64/mindexec-remote-fast +0 -0
  11. package/remote-fast/osx-x64/mindexec-remote-fast.deps.json +24 -0
  12. package/remote-fast/osx-x64/mindexec-remote-fast.dll +0 -0
  13. package/remote-fast/osx-x64/mindexec-remote-fast.runtimeconfig.json +13 -0
  14. package/remote-fast/win-x64/mindexec-remote-fast.deps.json +24 -0
  15. package/remote-fast/win-x64/mindexec-remote-fast.dll +0 -0
  16. package/remote-fast/win-x64/mindexec-remote-fast.exe +0 -0
  17. package/remote-fast/win-x64/mindexec-remote-fast.runtimeconfig.json +20 -0
  18. package/remote-hub.js +3106 -0
  19. package/scripts/auth-session-smoke.mjs +262 -0
  20. package/scripts/remote-agent-managed-smoke.mjs +291 -0
  21. package/scripts/remote-agent-package-smoke.mjs +64 -0
  22. package/scripts/remote-agent-ws-smoke.mjs +202 -0
  23. package/scripts/remote-fast-live-rate-smoke.mjs +355 -0
  24. package/scripts/remote-fast-mdm-browser-smoke.mjs +476 -0
  25. package/scripts/remote-fleet-render-smoke.mjs +1491 -0
  26. package/scripts/remote-frame-ws-smoke.mjs +234 -0
  27. package/scripts/remote-http-smoke.mjs +592 -0
  28. package/scripts/remote-hub-identity-smoke.mjs +146 -0
  29. package/scripts/remote-hub-scale-smoke.mjs +124 -0
  30. package/scripts/remote-hub-smoke.mjs +631 -0
  31. package/scripts/remote-input-ws-smoke.mjs +263 -0
  32. package/scripts/remote-registry-follower-smoke.mjs +752 -0
  33. package/scripts/setup-tree-sitter-grammars.mjs +80 -0
  34. package/server.js +15709 -0
  35. package/start-bridge.bat +32 -0
  36. package/start-bridge.sh +81 -0
  37. package/tree-sitter-grammars/README.md +18 -0
  38. package/tree-sitter-grammars/tree-sitter-c_sharp.wasm +0 -0
  39. package/tree-sitter-grammars/tree-sitter-go.wasm +0 -0
  40. package/tree-sitter-grammars/tree-sitter-java.wasm +0 -0
  41. package/tree-sitter-grammars/tree-sitter-javascript.wasm +0 -0
  42. package/tree-sitter-grammars/tree-sitter-python.wasm +0 -0
  43. package/tree-sitter-grammars/tree-sitter-rust.wasm +0 -0
  44. package/tree-sitter-grammars/tree-sitter-tsx.wasm +0 -0
  45. package/tree-sitter-grammars/tree-sitter-typescript.wasm +0 -0
  46. package/wwwroot/_headers +73 -0
  47. package/wwwroot/_redirects +1 -0
  48. package/wwwroot/appsettings.json +83 -0
  49. package/wwwroot/assets/AdminDashboardPage-B2vz2Px9.css +1 -0
  50. package/wwwroot/assets/AdminDashboardPage-DnuCHywn.js +1 -0
  51. package/wwwroot/assets/AppSidebar-DU2OgSiv.js +2 -0
  52. package/wwwroot/assets/AuthPages-BrH6kRcv.css +1 -0
  53. package/wwwroot/assets/AuthPages-Dgezl7Vj.js +1 -0
  54. package/wwwroot/assets/CodePage-7kgZlB3O.js +87 -0
  55. package/wwwroot/assets/CodePage-Bncc352E.css +1 -0
  56. package/wwwroot/assets/CompanyCorePage-ChBnq1ve.css +1 -0
  57. package/wwwroot/assets/CompanyCorePage-CzIZIIU_.js +13 -0
  58. package/wwwroot/assets/ExecutionModePage-B-etp_mc.js +18 -0
  59. package/wwwroot/assets/ExecutionModePage-TLuld9l3.css +1 -0
  60. package/wwwroot/assets/LaunchLeadCapture-Bx9LM0IX.js +1 -0
  61. package/wwwroot/assets/LaunchLeadCapture-CiRI1shz.css +1 -0
  62. package/wwwroot/assets/MarketingHome-BsyerRpe.js +1 -0
  63. package/wwwroot/assets/MarketingHome-DPzaYzA_.css +1 -0
  64. package/wwwroot/assets/MindCanvas-DtqOZnoW.css +1 -0
  65. package/wwwroot/assets/MindCanvas-zEDXzaxW.js +49 -0
  66. package/wwwroot/assets/PlanMasterPage-CJ36rep-.css +1 -0
  67. package/wwwroot/assets/PlanMasterPage-NZ_mPvaE.js +4 -0
  68. package/wwwroot/assets/PricingPage-Cg_0i_ZR.css +1 -0
  69. package/wwwroot/assets/PricingPage-Ylrn8l2g.js +1 -0
  70. package/wwwroot/assets/ToolPages-3M2KqA9k.js +28 -0
  71. package/wwwroot/assets/ToolPages-DIB187pZ.css +1 -0
  72. package/wwwroot/assets/YouTubeSearchPage-COv1oAA7.js +4 -0
  73. package/wwwroot/assets/YouTubeSearchPage-IPPa_BIH.css +1 -0
  74. package/wwwroot/assets/app-runtime-xD2Z3NdN.js +1 -0
  75. package/wwwroot/assets/canvas-runtime-BbicBcOj.js +44 -0
  76. package/wwwroot/assets/code-agent-runtime-B5PPZd1t.js +74 -0
  77. package/wwwroot/assets/executionModeSettings-NJqurj-o.js +1 -0
  78. package/wwwroot/assets/index-CQMKCp-t.js +2 -0
  79. package/wwwroot/assets/index-yNpEK-gp.css +1 -0
  80. package/wwwroot/assets/marketingTools-DN_rnHeB.js +4 -0
  81. package/wwwroot/assets/mindCanvasSearchWorker-BzPMsHOB.js +1 -0
  82. package/wwwroot/assets/mindexecution-mindcanvas.png +0 -0
  83. package/wwwroot/assets/mindexecution-prod-home-current.png +0 -0
  84. package/wwwroot/assets/mindexecution-prod-pricing-current.png +0 -0
  85. package/wwwroot/assets/pricingCheckoutShell-O-DnwmbU.js +1 -0
  86. package/wwwroot/assets/productionAdapterConfig-C5jfk6oG.js +1 -0
  87. package/wwwroot/assets/runtimeSettingsPersistenceProjection-BoNWmYjU.js +1 -0
  88. package/wwwroot/assets/storage-TM3YrWaj.js +1 -0
  89. package/wwwroot/assets/supabaseAuthAdapter-DA43DeSY.js +44 -0
  90. package/wwwroot/assets/toolHandoff-D5e5f7t5.js +4 -0
  91. package/wwwroot/assets/vendor-icons-DE3gIReG.js +681 -0
  92. package/wwwroot/assets/vendor-msgpack-BE8aAsr3.js +1 -0
  93. package/wwwroot/assets/vendor-react-BXzpOyCS.js +40 -0
  94. package/wwwroot/favicon.svg +7 -0
  95. package/wwwroot/index.html +22 -0
  96. package/wwwroot/manifest.webmanifest +19 -0
  97. package/wwwroot/robots.txt +4 -0
  98. package/wwwroot/service-worker.js +7 -0
  99. package/wwwroot/sitemap.xml +39 -0
@@ -0,0 +1,592 @@
1
+ #!/usr/bin/env node
2
+
3
+ import assert from 'node:assert/strict';
4
+ import net from 'node:net';
5
+ import { spawn } from 'node:child_process';
6
+ import path from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+ import { readFileSync } from 'node:fs';
9
+
10
+ const BRIDGE_TOKEN = 'remote-http-smoke-token';
11
+ const PAIR_TOKEN = 'remote-http-pair-token';
12
+ const SYNTHETIC_COUNT = Number(process.env.REMOTE_HTTP_SMOKE_COUNT || 500);
13
+ const LOCAL_BRIDGE_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
14
+ const LOCAL_BRIDGE_PACKAGE = JSON.parse(readFileSync(path.join(LOCAL_BRIDGE_DIR, 'package.json'), 'utf8'));
15
+
16
+ function wait(ms) {
17
+ return new Promise(resolve => setTimeout(resolve, ms));
18
+ }
19
+
20
+ async function findFreePort() {
21
+ return await new Promise((resolve, reject) => {
22
+ const server = net.createServer();
23
+ server.unref();
24
+ server.once('error', reject);
25
+ server.listen(0, '127.0.0.1', () => {
26
+ const address = server.address();
27
+ const port = typeof address === 'object' && address ? address.port : 0;
28
+ server.close(() => resolve(port));
29
+ });
30
+ });
31
+ }
32
+
33
+ async function fetchJson(url, options = {}) {
34
+ const response = await fetch(url, {
35
+ ...options,
36
+ headers: {
37
+ ...(options.body ? { 'Content-Type': 'application/json' } : {}),
38
+ ...(options.token ? { 'X-Bridge-Token': options.token } : {}),
39
+ ...(options.headers || {})
40
+ }
41
+ });
42
+
43
+ let payload = null;
44
+ try {
45
+ payload = await response.json();
46
+ } catch {
47
+ // Some failure responses may be empty.
48
+ }
49
+
50
+ return {
51
+ status: response.status,
52
+ ok: response.ok,
53
+ payload
54
+ };
55
+ }
56
+
57
+ async function fetchBinary(url, options = {}) {
58
+ const response = await fetch(url, {
59
+ ...options,
60
+ headers: {
61
+ Accept: 'image/png,image/jpeg,image/webp,image/*',
62
+ ...(options.token ? { 'X-Bridge-Token': options.token } : {}),
63
+ ...(options.headers || {})
64
+ }
65
+ });
66
+
67
+ return {
68
+ status: response.status,
69
+ ok: response.ok,
70
+ contentType: response.headers.get('content-type') || '',
71
+ frameSeq: response.headers.get('x-mindexec-remote-frame-seq') || '',
72
+ streamId: response.headers.get('x-mindexec-remote-stream-id') || '',
73
+ payload: Buffer.from(await response.arrayBuffer())
74
+ };
75
+ }
76
+
77
+ async function waitForBridge(baseUrl, getFailureDetails, bridgeToken = BRIDGE_TOKEN) {
78
+ const startedAt = Date.now();
79
+ while (Date.now() - startedAt < 30000) {
80
+ try {
81
+ const result = await fetchJson(`${baseUrl}/api/remote/status`, { token: bridgeToken });
82
+ if (result.ok && result.payload?.started === true) {
83
+ return result.payload;
84
+ }
85
+ } catch {
86
+ // Server is still starting.
87
+ }
88
+ await wait(100);
89
+ }
90
+
91
+ throw new Error(`Timed out waiting for LocalBridge RemoteHub HTTP API.\n${getFailureDetails()}`);
92
+ }
93
+
94
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
95
+ const bridgeRoot = path.resolve(__dirname, '..');
96
+
97
+ function spawnBridge({
98
+ bridgePort,
99
+ remoteHubPort,
100
+ bridgeToken = BRIDGE_TOKEN,
101
+ pairToken = PAIR_TOKEN,
102
+ syntheticFleetEnabled = false
103
+ }) {
104
+ const env = {
105
+ ...process.env,
106
+ BRIDGE_PORT: String(bridgePort),
107
+ BRIDGE_TOKEN: bridgeToken,
108
+ BRIDGE_REQUIRE_TOKEN: '1',
109
+ MINDEXEC_REMOTE_HUB: '1',
110
+ REMOTE_HUB_HOST: '127.0.0.1',
111
+ REMOTE_HUB_PORT: String(remoteHubPort),
112
+ REMOTE_HUB_PAIR_TOKEN: pairToken,
113
+ NO_COLOR: '1'
114
+ };
115
+
116
+ delete env.MINDEXEC_REMOTE_SYNTHETIC_FLEET;
117
+ delete env.REMOTE_HUB_SYNTHETIC_FLEET;
118
+ if (syntheticFleetEnabled) {
119
+ env.MINDEXEC_REMOTE_SYNTHETIC_FLEET = '1';
120
+ }
121
+
122
+ const child = spawn(process.execPath, ['server.js'], {
123
+ cwd: bridgeRoot,
124
+ stdio: ['ignore', 'pipe', 'pipe'],
125
+ windowsHide: true,
126
+ env
127
+ });
128
+
129
+ let stdout = '';
130
+ let stderr = '';
131
+ child.stdout.on('data', chunk => {
132
+ stdout += chunk.toString();
133
+ });
134
+ child.stderr.on('data', chunk => {
135
+ stderr += chunk.toString();
136
+ });
137
+
138
+ const exitPromise = new Promise(resolve => child.once('exit', resolve));
139
+ const details = () => `stdout=${stdout}\nstderr=${stderr}`;
140
+ const stop = async () => {
141
+ if (child.exitCode === null && !child.killed) {
142
+ child.kill('SIGTERM');
143
+ await Promise.race([
144
+ exitPromise,
145
+ wait(5000)
146
+ ]);
147
+ if (child.exitCode === null && !child.killed) {
148
+ child.kill('SIGKILL');
149
+ }
150
+ }
151
+ };
152
+
153
+ return {
154
+ baseUrl: `http://127.0.0.1:${bridgePort}`,
155
+ bridgePort,
156
+ remoteHubPort,
157
+ bridgeToken,
158
+ pairToken,
159
+ child,
160
+ details,
161
+ stop
162
+ };
163
+ }
164
+
165
+ async function runSyntheticEnabledSmoke() {
166
+ const bridgePort = await findFreePort();
167
+ const remoteHubPort = await findFreePort();
168
+ const bridge = spawnBridge({
169
+ bridgePort,
170
+ remoteHubPort,
171
+ syntheticFleetEnabled: true
172
+ });
173
+ const { baseUrl } = bridge;
174
+ const details = bridge.details;
175
+
176
+ try {
177
+ const status = await waitForBridge(baseUrl, details, bridge.bridgeToken);
178
+ assert.equal(status.started, true);
179
+ assert.equal(status.port, remoteHubPort);
180
+ assert.equal(status.managerPackage, 'mindexec-ai');
181
+ assert.equal(status.managerVersion, LOCAL_BRIDGE_PACKAGE.version);
182
+ assert.equal(status.agentPackage, '@mindexec/remote');
183
+ assert.equal(status.canvasPagination, 'none');
184
+ assert.equal(status.canvasDeviceListMode, 'all-devices');
185
+ assert.equal(status.hostTargetActive, false);
186
+ assert.equal(status.pairToken, PAIR_TOKEN);
187
+
188
+ const unauthorizedStatus = await fetchJson(`${baseUrl}/api/remote/status`);
189
+ assert.equal(unauthorizedStatus.status, 401);
190
+ assert.equal(unauthorizedStatus.payload?.header, 'X-Bridge-Token');
191
+
192
+ const unauthorizedDelete = await fetchJson(`${baseUrl}/api/remote/synthetic`, {
193
+ method: 'DELETE'
194
+ });
195
+ assert.equal(unauthorizedDelete.status, 401);
196
+
197
+ const unauthorizedHost = await fetchJson(`${baseUrl}/api/remote/host-target`, {
198
+ method: 'POST',
199
+ body: JSON.stringify({
200
+ nodeId: 'remote-fleet-host-unauthorized',
201
+ enabled: true
202
+ })
203
+ });
204
+ assert.equal(unauthorizedHost.status, 401);
205
+
206
+ const setHost = await fetchJson(`${baseUrl}/api/remote/host-target`, {
207
+ method: 'POST',
208
+ token: BRIDGE_TOKEN,
209
+ body: JSON.stringify({
210
+ nodeId: 'remote-fleet-monitor-a',
211
+ enabled: true,
212
+ leaseMs: 30000
213
+ })
214
+ });
215
+ assert.equal(setHost.ok, true, JSON.stringify(setHost.payload));
216
+ assert.equal(setHost.payload?.ok, true);
217
+ assert.equal(setHost.payload?.active, true);
218
+ assert.equal(setHost.payload?.hostTarget?.nodeId, 'remote-fleet-monitor-a');
219
+ assert.equal(setHost.payload?.hostTarget?.endpoint, `127.0.0.1:${remoteHubPort}`);
220
+ assert.deepEqual(setHost.payload?.hostTarget?.endpointCandidates, [`127.0.0.1:${remoteHubPort}`]);
221
+
222
+ const hostStatus = await fetchJson(`${baseUrl}/api/remote/status`, { token: BRIDGE_TOKEN });
223
+ assert.equal(hostStatus.ok, true, JSON.stringify(hostStatus.payload));
224
+ assert.equal(hostStatus.payload?.hostTargetActive, true);
225
+ assert.equal(hostStatus.payload?.hostTargetNodeId, 'remote-fleet-monitor-a');
226
+ assert.equal(hostStatus.payload?.hostTargetEndpoint, `127.0.0.1:${remoteHubPort}`);
227
+ assert.deepEqual(hostStatus.payload?.hostTargetEndpointCandidates, [`127.0.0.1:${remoteHubPort}`]);
228
+
229
+ const clearHostMismatch = await fetchJson(`${baseUrl}/api/remote/host-target`, {
230
+ method: 'DELETE',
231
+ token: BRIDGE_TOKEN,
232
+ body: JSON.stringify({
233
+ nodeId: 'remote-fleet-monitor-b'
234
+ })
235
+ });
236
+ assert.equal(clearHostMismatch.ok, true, JSON.stringify(clearHostMismatch.payload));
237
+ assert.equal(clearHostMismatch.payload?.ok, false);
238
+ assert.equal(clearHostMismatch.payload?.error, 'host-target-node-mismatch');
239
+
240
+ const clearHost = await fetchJson(`${baseUrl}/api/remote/host-target`, {
241
+ method: 'DELETE',
242
+ token: BRIDGE_TOKEN,
243
+ body: JSON.stringify({
244
+ nodeId: 'remote-fleet-monitor-a'
245
+ })
246
+ });
247
+ assert.equal(clearHost.ok, true, JSON.stringify(clearHost.payload));
248
+ assert.equal(clearHost.payload?.ok, true);
249
+ assert.equal(clearHost.payload?.active, false);
250
+
251
+ const seed = await fetchJson(`${baseUrl}/api/remote/synthetic/seed`, {
252
+ method: 'POST',
253
+ token: BRIDGE_TOKEN,
254
+ body: JSON.stringify({
255
+ count: SYNTHETIC_COUNT,
256
+ connectedRatio: 0.84,
257
+ thumbnailRatio: 0.72,
258
+ aiAssistRatio: 0.42,
259
+ liveCount: 8,
260
+ replace: true
261
+ })
262
+ });
263
+ assert.equal(seed.ok, true, JSON.stringify(seed.payload));
264
+ assert.equal(seed.payload?.ok, true);
265
+ assert.equal(seed.payload?.seeded, SYNTHETIC_COUNT);
266
+
267
+ const devicesResult = await fetchJson(`${baseUrl}/api/remote/devices`, { token: BRIDGE_TOKEN });
268
+ assert.equal(devicesResult.ok, true, JSON.stringify(devicesResult.payload));
269
+ assert.equal(devicesResult.payload?.total, SYNTHETIC_COUNT);
270
+ assert.equal(devicesResult.payload?.pagination, 'none');
271
+ assert.equal(devicesResult.payload?.canvasDeviceListMode, 'all-devices');
272
+ assert.equal(devicesResult.payload?.devices?.length, SYNTHETIC_COUNT);
273
+ assert.equal(devicesResult.payload.devices.some(device => device.connected === false), true);
274
+
275
+ const noControlTarget = devicesResult.payload.devices.find(device => device.connected);
276
+ assert.ok(noControlTarget);
277
+ const inputUnavailable = await fetchJson(`${baseUrl}/api/remote/devices/${encodeURIComponent(noControlTarget.deviceId)}/input`, {
278
+ method: 'POST',
279
+ token: BRIDGE_TOKEN,
280
+ body: JSON.stringify({
281
+ type: 'noop'
282
+ })
283
+ });
284
+ assert.equal(inputUnavailable.ok, true, JSON.stringify(inputUnavailable.payload));
285
+ assert.equal(inputUnavailable.payload?.ok, false);
286
+ assert.equal(inputUnavailable.payload?.error, 'device-input-control-unavailable');
287
+
288
+ const connectedTargets = devicesResult.payload.devices
289
+ .filter(device => device.connected && device.capabilities?.taskDispatch)
290
+ .slice(0, 500)
291
+ .map(device => device.deviceId);
292
+ assert.ok(connectedTargets.length >= 400);
293
+
294
+ const batch = await fetchJson(`${baseUrl}/api/remote/tasks`, {
295
+ method: 'POST',
296
+ token: BRIDGE_TOKEN,
297
+ body: JSON.stringify({
298
+ deviceIds: connectedTargets,
299
+ allConnected: false,
300
+ title: 'HTTP smoke task batch',
301
+ instruction: 'HTTP smoke batch: report current status to the manager.',
302
+ approvalLevel: 'task-only'
303
+ })
304
+ });
305
+ assert.equal(batch.ok, true, JSON.stringify(batch.payload));
306
+ assert.equal(batch.payload?.ok, true);
307
+ assert.equal(batch.payload?.total, connectedTargets.length);
308
+ assert.equal(batch.payload?.queued, connectedTargets.length);
309
+ assert.equal(batch.payload?.batch?.completed, connectedTargets.length);
310
+ assert.equal(batch.payload?.batch?.failed, 0);
311
+ assert.equal(batch.payload?.batch?.status, 'completed');
312
+
313
+ const aiTargets = devicesResult.payload.devices
314
+ .filter(device => device.connected && device.capabilities?.taskDispatch && device.capabilities?.aiAssist)
315
+ .map(device => device.deviceId);
316
+ assert.ok(aiTargets.length >= 200);
317
+ const allAiBatch = await fetchJson(`${baseUrl}/api/remote/tasks`, {
318
+ method: 'POST',
319
+ token: BRIDGE_TOKEN,
320
+ body: JSON.stringify({
321
+ allConnected: true,
322
+ title: 'HTTP smoke all AI task batch',
323
+ instruction: 'HTTP smoke AI batch: summarize fleet condition only on AI-capable agents.',
324
+ approvalLevel: 'ai-assist'
325
+ })
326
+ });
327
+ assert.equal(allAiBatch.ok, true, JSON.stringify(allAiBatch.payload));
328
+ assert.equal(allAiBatch.payload?.ok, true);
329
+ assert.equal(allAiBatch.payload?.approvalLevel, 'ai-assist');
330
+ assert.equal(allAiBatch.payload?.total, aiTargets.length);
331
+ assert.equal(allAiBatch.payload?.queued, aiTargets.length);
332
+ assert.equal(allAiBatch.payload?.batch?.completed, aiTargets.length);
333
+ assert.equal(allAiBatch.payload?.batch?.failed, 0);
334
+ assert.equal(allAiBatch.payload?.batch?.status, 'completed');
335
+ assert.deepEqual(
336
+ [...(allAiBatch.payload?.results || []).map(result => result.deviceId)].sort(),
337
+ [...aiTargets].sort());
338
+
339
+ const aiTarget = devicesResult.payload.devices.find(device =>
340
+ device.connected && device.capabilities?.taskDispatch && device.capabilities?.aiAssist);
341
+ assert.ok(aiTarget);
342
+ const aiTask = await fetchJson(`${baseUrl}/api/remote/devices/${encodeURIComponent(aiTarget.deviceId)}/tasks`, {
343
+ method: 'POST',
344
+ token: BRIDGE_TOKEN,
345
+ body: JSON.stringify({
346
+ title: 'HTTP smoke AI task',
347
+ instruction: 'HTTP smoke AI assist: summarize fleet condition.',
348
+ approvalLevel: 'ai-assist'
349
+ })
350
+ });
351
+ assert.equal(aiTask.ok, true, JSON.stringify(aiTask.payload));
352
+ assert.equal(aiTask.payload?.ok, true);
353
+ assert.equal(aiTask.payload?.approvalLevel, 'ai-assist');
354
+
355
+ const thumbnailTarget = devicesResult.payload.devices.find(device =>
356
+ device.connected && device.capabilities?.thumbnail);
357
+ assert.ok(thumbnailTarget);
358
+ const thumbnailRequest = await fetchJson(`${baseUrl}/api/remote/devices/${encodeURIComponent(thumbnailTarget.deviceId)}/thumbnail/request`, {
359
+ method: 'POST',
360
+ token: BRIDGE_TOKEN,
361
+ body: JSON.stringify({
362
+ streamId: 'http-smoke-thumb',
363
+ maxWidth: 360,
364
+ maxHeight: 220,
365
+ quality: 50
366
+ })
367
+ });
368
+ assert.equal(thumbnailRequest.ok, true, JSON.stringify(thumbnailRequest.payload));
369
+ assert.equal(thumbnailRequest.payload?.ok, true);
370
+
371
+ const thumbnail = await fetchJson(`${baseUrl}/api/remote/devices/${encodeURIComponent(thumbnailTarget.deviceId)}/thumbnail`, {
372
+ token: BRIDGE_TOKEN
373
+ });
374
+ assert.equal(thumbnail.ok, true, JSON.stringify(thumbnail.payload));
375
+ assert.equal(thumbnail.payload?.thumbnail?.streamId, 'http-smoke-thumb');
376
+ assert.ok(!('dataUrl' in thumbnail.payload.thumbnail));
377
+ assert.ok(String(thumbnail.payload?.thumbnail?.framePath || '').includes(`/api/remote/devices/${encodeURIComponent(thumbnailTarget.deviceId)}/thumbnail?`));
378
+ assert.equal(thumbnail.payload?.thumbnail?.frameUrl, thumbnail.payload?.thumbnail?.framePath);
379
+
380
+ const thumbnailWithData = await fetchJson(`${baseUrl}/api/remote/devices/${encodeURIComponent(thumbnailTarget.deviceId)}/thumbnail?includeDataUrl=true`, {
381
+ token: BRIDGE_TOKEN
382
+ });
383
+ assert.equal(thumbnailWithData.ok, true, JSON.stringify(thumbnailWithData.payload));
384
+ assert.ok(String(thumbnailWithData.payload?.thumbnail?.dataUrl || '').startsWith('data:image/png;base64,'));
385
+
386
+ const thumbnailBinary = await fetchBinary(`${baseUrl}${thumbnail.payload.thumbnail.framePath}`);
387
+ assert.equal(thumbnailBinary.ok, true, `${thumbnailBinary.status} ${thumbnailBinary.contentType}`);
388
+ assert.equal(thumbnailBinary.contentType, 'image/png');
389
+ assert.equal(thumbnailBinary.streamId, 'http-smoke-thumb');
390
+ assert.ok(thumbnailBinary.payload.length > 0);
391
+
392
+ const badThumbnailBinary = await fetchBinary(`${baseUrl}${thumbnail.payload.thumbnail.framePath.replace(/token=[^&]+/, 'token=wrong-token')}`);
393
+ assert.equal(badThumbnailBinary.status, 401);
394
+
395
+ const devicesUrlOnlyResult = await fetchJson(`${baseUrl}/api/remote/devices?frameData=url`, { token: BRIDGE_TOKEN });
396
+ assert.equal(devicesUrlOnlyResult.ok, true, JSON.stringify(devicesUrlOnlyResult.payload));
397
+ const urlOnlyThumbnailDevice = devicesUrlOnlyResult.payload?.devices?.find(device => device.deviceId === thumbnailTarget.deviceId);
398
+ assert.ok(urlOnlyThumbnailDevice?.latestThumbnail?.framePath);
399
+ assert.ok(!('dataUrl' in urlOnlyThumbnailDevice.latestThumbnail));
400
+
401
+ const thumbnailFramesOnly = await fetchJson(`${baseUrl}/api/remote/frames`, {
402
+ method: 'POST',
403
+ token: BRIDGE_TOKEN,
404
+ body: JSON.stringify({
405
+ deviceIds: [thumbnailTarget.deviceId],
406
+ includeThumbnail: true,
407
+ includeLive: true
408
+ })
409
+ });
410
+ assert.equal(thumbnailFramesOnly.ok, true, JSON.stringify(thumbnailFramesOnly.payload));
411
+ assert.equal(thumbnailFramesOnly.payload?.ok, true);
412
+ assert.equal(thumbnailFramesOnly.payload?.frames?.length, 1);
413
+ assert.equal(thumbnailFramesOnly.payload.frames[0].deviceId, thumbnailTarget.deviceId);
414
+ assert.equal(thumbnailFramesOnly.payload.frames[0].thumbnailEnabled, true);
415
+ assert.ok(String(thumbnailFramesOnly.payload.frames[0].thumbnail?.framePath || '').includes(`/api/remote/devices/${encodeURIComponent(thumbnailTarget.deviceId)}/thumbnail?`));
416
+ assert.ok(!('dataUrl' in thumbnailFramesOnly.payload.frames[0].thumbnail));
417
+
418
+ const liveTarget = devicesResult.payload.devices.find(device =>
419
+ device.connected && device.capabilities?.liveStream);
420
+ assert.ok(liveTarget);
421
+ const liveStart = await fetchJson(`${baseUrl}/api/remote/devices/${encodeURIComponent(liveTarget.deviceId)}/live/start`, {
422
+ method: 'POST',
423
+ token: BRIDGE_TOKEN,
424
+ body: JSON.stringify({
425
+ streamId: 'http-smoke-live',
426
+ fps: 20,
427
+ maxWidth: 960,
428
+ maxHeight: 540,
429
+ quality: 60
430
+ })
431
+ });
432
+ assert.equal(liveStart.ok, true, JSON.stringify(liveStart.payload));
433
+ assert.equal(liveStart.payload?.ok, true);
434
+
435
+ const liveFrame = await fetchJson(`${baseUrl}/api/remote/devices/${encodeURIComponent(liveTarget.deviceId)}/live/frame`, {
436
+ token: BRIDGE_TOKEN
437
+ });
438
+ assert.equal(liveFrame.ok, true, JSON.stringify(liveFrame.payload));
439
+ assert.equal(liveFrame.payload?.frame?.streamId, 'http-smoke-live');
440
+ assert.equal(liveFrame.payload?.frame?.mode, 'remote-fast');
441
+ assert.equal(liveFrame.payload?.frame?.fps, 20);
442
+ assert.ok(!('dataUrl' in liveFrame.payload.frame));
443
+ assert.ok(String(liveFrame.payload?.frame?.framePath || '').includes(`/api/remote/devices/${encodeURIComponent(liveTarget.deviceId)}/live/frame?`));
444
+
445
+ const liveFrameWithData = await fetchJson(`${baseUrl}/api/remote/devices/${encodeURIComponent(liveTarget.deviceId)}/live/frame?includeDataUrl=true`, {
446
+ token: BRIDGE_TOKEN
447
+ });
448
+ assert.equal(liveFrameWithData.ok, true, JSON.stringify(liveFrameWithData.payload));
449
+ assert.ok(String(liveFrameWithData.payload?.frame?.dataUrl || '').startsWith('data:image/png;base64,'));
450
+
451
+ const liveBinary = await fetchBinary(`${baseUrl}${liveFrame.payload.frame.framePath}`);
452
+ assert.equal(liveBinary.ok, true, `${liveBinary.status} ${liveBinary.contentType}`);
453
+ assert.equal(liveBinary.contentType, 'image/png');
454
+ assert.equal(liveBinary.streamId, 'http-smoke-live');
455
+ assert.ok(liveBinary.payload.length > 0);
456
+
457
+ const liveBinaryWithBridgeToken = await fetchBinary(
458
+ `${baseUrl}/api/remote/devices/${encodeURIComponent(liveTarget.deviceId)}/live/frame?format=binary`,
459
+ { token: BRIDGE_TOKEN });
460
+ assert.equal(liveBinaryWithBridgeToken.ok, true, `${liveBinaryWithBridgeToken.status} ${liveBinaryWithBridgeToken.contentType}`);
461
+ assert.equal(liveBinaryWithBridgeToken.contentType, 'image/png');
462
+
463
+ const badLiveSeq = await fetchBinary(`${baseUrl}${liveFrame.payload.frame.framePath.replace(/seq=\d+/, 'seq=999999')}`);
464
+ assert.equal(badLiveSeq.status, 401);
465
+
466
+ const liveFramesOnly = await fetchJson(`${baseUrl}/api/remote/frames`, {
467
+ method: 'POST',
468
+ token: BRIDGE_TOKEN,
469
+ body: JSON.stringify({
470
+ deviceIds: [liveTarget.deviceId],
471
+ includeThumbnail: true,
472
+ includeLive: true
473
+ })
474
+ });
475
+ assert.equal(liveFramesOnly.ok, true, JSON.stringify(liveFramesOnly.payload));
476
+ assert.equal(liveFramesOnly.payload?.ok, true);
477
+ assert.equal(liveFramesOnly.payload?.frames?.length, 1);
478
+ assert.equal(liveFramesOnly.payload.frames[0].deviceId, liveTarget.deviceId);
479
+ assert.equal(liveFramesOnly.payload.frames[0].liveStreamActive, true);
480
+ assert.ok(String(liveFramesOnly.payload.frames[0].live?.framePath || '').includes(`/api/remote/devices/${encodeURIComponent(liveTarget.deviceId)}/live/frame?`));
481
+ assert.ok(!('dataUrl' in liveFramesOnly.payload.frames[0].live));
482
+
483
+ const liveStop = await fetchJson(`${baseUrl}/api/remote/devices/${encodeURIComponent(liveTarget.deviceId)}/live/stop`, {
484
+ method: 'POST',
485
+ token: BRIDGE_TOKEN,
486
+ body: JSON.stringify({
487
+ streamId: 'http-smoke-live'
488
+ })
489
+ });
490
+ assert.equal(liveStop.ok, true, JSON.stringify(liveStop.payload));
491
+ assert.equal(liveStop.payload?.ok, true);
492
+
493
+ const clear = await fetchJson(`${baseUrl}/api/remote/synthetic`, {
494
+ method: 'DELETE',
495
+ token: BRIDGE_TOKEN
496
+ });
497
+ assert.equal(clear.ok, true, JSON.stringify(clear.payload));
498
+ assert.equal(clear.payload?.ok, true);
499
+ assert.equal(clear.payload?.removed, SYNTHETIC_COUNT);
500
+
501
+ console.log(`RemoteHub HTTP smoke OK (${SYNTHETIC_COUNT} synthetic devices, bridge ${bridgePort}, remote ${remoteHubPort})`);
502
+ } finally {
503
+ await bridge.stop();
504
+ }
505
+ }
506
+
507
+ async function runSyntheticDisabledSmoke() {
508
+ const bridgePort = await findFreePort();
509
+ const remoteHubPort = await findFreePort();
510
+ const bridgeToken = `${BRIDGE_TOKEN}-disabled`;
511
+ const pairToken = `${PAIR_TOKEN}-disabled`;
512
+ const bridge = spawnBridge({
513
+ bridgePort,
514
+ remoteHubPort,
515
+ bridgeToken,
516
+ pairToken,
517
+ syntheticFleetEnabled: false
518
+ });
519
+ const { baseUrl } = bridge;
520
+
521
+ try {
522
+ const status = await waitForBridge(baseUrl, bridge.details, bridge.bridgeToken);
523
+ assert.equal(status.started, true);
524
+ assert.equal(status.port, remoteHubPort);
525
+ assert.equal(status.pairToken, pairToken);
526
+ assert.equal(status.canvasPagination, 'none');
527
+ assert.equal(status.canvasDeviceListMode, 'all-devices');
528
+ assert.equal(status.hostTargetActive, false);
529
+
530
+ const seedDenied = await fetchJson(`${baseUrl}/api/remote/synthetic/seed`, {
531
+ method: 'POST',
532
+ token: bridge.bridgeToken,
533
+ body: JSON.stringify({
534
+ count: 3,
535
+ replace: true
536
+ })
537
+ });
538
+ assert.equal(seedDenied.status, 403);
539
+ assert.equal(seedDenied.payload?.ok, false);
540
+ assert.equal(seedDenied.payload?.error, 'synthetic-fleet-disabled');
541
+
542
+ const clearDenied = await fetchJson(`${baseUrl}/api/remote/synthetic`, {
543
+ method: 'DELETE',
544
+ token: bridge.bridgeToken
545
+ });
546
+ assert.equal(clearDenied.status, 403);
547
+ assert.equal(clearDenied.payload?.ok, false);
548
+ assert.equal(clearDenied.payload?.error, 'synthetic-fleet-disabled');
549
+
550
+ const devicesResult = await fetchJson(`${baseUrl}/api/remote/devices`, { token: bridge.bridgeToken });
551
+ assert.equal(devicesResult.ok, true, JSON.stringify(devicesResult.payload));
552
+ assert.equal(devicesResult.payload?.total, 0);
553
+ assert.equal(devicesResult.payload?.pagination, 'none');
554
+ assert.equal(devicesResult.payload?.canvasDeviceListMode, 'all-devices');
555
+ assert.equal(devicesResult.payload?.devices?.length, 0);
556
+
557
+ const emptyBatch = await fetchJson(`${baseUrl}/api/remote/tasks`, {
558
+ method: 'POST',
559
+ token: bridge.bridgeToken,
560
+ body: JSON.stringify({
561
+ allConnected: true,
562
+ title: 'HTTP smoke no target batch',
563
+ instruction: 'This should not queue because no remote devices are connected.',
564
+ approvalLevel: 'task-only'
565
+ })
566
+ });
567
+ assert.equal(emptyBatch.ok, true, JSON.stringify(emptyBatch.payload));
568
+ assert.equal(emptyBatch.payload?.ok, false);
569
+ assert.equal(emptyBatch.payload?.total, 0);
570
+ assert.equal(emptyBatch.payload?.queued, 0);
571
+ assert.equal(emptyBatch.payload?.error, 'no-target-devices');
572
+
573
+ const hostTarget = await fetchJson(`${baseUrl}/api/remote/host-target`, {
574
+ method: 'POST',
575
+ token: bridge.bridgeToken,
576
+ body: JSON.stringify({
577
+ nodeId: 'disabled-synthetic-host',
578
+ enabled: true
579
+ })
580
+ });
581
+ assert.equal(hostTarget.ok, true, JSON.stringify(hostTarget.payload));
582
+ assert.equal(hostTarget.payload?.ok, true);
583
+ assert.equal(hostTarget.payload?.active, true);
584
+
585
+ console.log(`RemoteHub HTTP safety smoke OK (synthetic disabled, bridge ${bridgePort}, remote ${remoteHubPort})`);
586
+ } finally {
587
+ await bridge.stop();
588
+ }
589
+ }
590
+
591
+ await runSyntheticEnabledSmoke();
592
+ await runSyntheticDisabledSmoke();