@muloka/figma-console-mcp 0.5.5 → 0.5.6
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 +5 -4
- package/dist/core/http-request-guard.d.ts.map +1 -1
- package/dist/core/http-request-guard.js +11 -13
- package/dist/core/http-request-guard.js.map +1 -1
- package/dist/core/port-discovery.d.ts.map +1 -1
- package/dist/core/port-discovery.js +151 -52
- package/dist/core/port-discovery.js.map +1 -1
- package/dist/core/websocket-server.d.ts.map +1 -1
- package/dist/core/websocket-server.js +9 -1
- package/dist/core/websocket-server.js.map +1 -1
- package/dist/core/write-tools.d.ts +5 -1
- package/dist/core/write-tools.d.ts.map +1 -1
- package/dist/core/write-tools.js +113 -83
- package/dist/core/write-tools.js.map +1 -1
- package/dist/local.d.ts.map +1 -1
- package/dist/local.js +9 -2
- package/dist/local.js.map +1 -1
- package/figma-desktop-bridge/code.js +10 -2
- package/figma-desktop-bridge/ui.html +82 -8
- package/package.json +1 -1
|
@@ -1266,10 +1266,42 @@
|
|
|
1266
1266
|
}
|
|
1267
1267
|
};
|
|
1268
1268
|
|
|
1269
|
+
// Ports with an in-flight CONNECTING handshake: { [port]: { ws, timer } }.
|
|
1270
|
+
// Kept separate from activeConnections so status-pill counts reflect only
|
|
1271
|
+
// open sockets, while preventing the 3s discovery loop from opening
|
|
1272
|
+
// duplicate sockets to a port still mid-handshake.
|
|
1273
|
+
var connectingSockets = {};
|
|
1274
|
+
var CONNECT_STALE_TIMEOUT_MS = 10000;
|
|
1275
|
+
|
|
1276
|
+
function clearConnecting(port, sock) {
|
|
1277
|
+
var entry = connectingSockets[port];
|
|
1278
|
+
if (entry && (!sock || entry.ws === sock)) {
|
|
1279
|
+
clearTimeout(entry.timer);
|
|
1280
|
+
delete connectingSockets[port];
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
function trackConnecting(port, sock) {
|
|
1285
|
+
clearConnecting(port, sock);
|
|
1286
|
+
var staleTimer = setTimeout(function() {
|
|
1287
|
+
if (connectingSockets[port] && connectingSockets[port].ws === sock) {
|
|
1288
|
+
delete connectingSockets[port];
|
|
1289
|
+
if (sock.readyState === 0) {
|
|
1290
|
+
try { sock.close(); } catch (e) {}
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
}, CONNECT_STALE_TIMEOUT_MS);
|
|
1294
|
+
connectingSockets[port] = { ws: sock, timer: staleTimer };
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1269
1297
|
/**
|
|
1270
|
-
* Check if we already have
|
|
1298
|
+
* Check if we already have an open or in-flight connection to a specific port.
|
|
1271
1299
|
*/
|
|
1272
1300
|
function isPortConnected(port) {
|
|
1301
|
+
var pendingEntry = connectingSockets[port];
|
|
1302
|
+
if (pendingEntry && pendingEntry.ws && pendingEntry.ws.readyState === 0) {
|
|
1303
|
+
return true;
|
|
1304
|
+
}
|
|
1273
1305
|
for (var i = 0; i < activeConnections.length; i++) {
|
|
1274
1306
|
if (activeConnections[i].port === port && activeConnections[i].ws.readyState === 1) {
|
|
1275
1307
|
return true;
|
|
@@ -1279,10 +1311,12 @@
|
|
|
1279
1311
|
}
|
|
1280
1312
|
|
|
1281
1313
|
/**
|
|
1282
|
-
* Remove a
|
|
1314
|
+
* Remove a specific socket from the active list and update compat state.
|
|
1315
|
+
* Matches by socket reference (not port) so a late onclose from an old
|
|
1316
|
+
* socket can never evict a live replacement socket on the same port.
|
|
1283
1317
|
*/
|
|
1284
|
-
function removeConnection(
|
|
1285
|
-
activeConnections = activeConnections.filter(function(c) { return c.
|
|
1318
|
+
function removeConnection(targetWs) {
|
|
1319
|
+
activeConnections = activeConnections.filter(function(c) { return c.ws !== targetWs; });
|
|
1286
1320
|
updateCompatState();
|
|
1287
1321
|
// Re-pace the health discovery loop: dropping to zero connections
|
|
1288
1322
|
// switches it to the fast (3s) cadence immediately.
|
|
@@ -1364,6 +1398,7 @@
|
|
|
1364
1398
|
portsToTry.forEach(function(port) {
|
|
1365
1399
|
try {
|
|
1366
1400
|
var testWs = new WebSocket('ws://localhost:' + port);
|
|
1401
|
+
trackConnecting(port, testWs);
|
|
1367
1402
|
|
|
1368
1403
|
var timeout = setTimeout(function() {
|
|
1369
1404
|
if (testWs.readyState !== 1) testWs.close();
|
|
@@ -1371,6 +1406,7 @@
|
|
|
1371
1406
|
|
|
1372
1407
|
testWs.onopen = function() {
|
|
1373
1408
|
clearTimeout(timeout);
|
|
1409
|
+
clearConnecting(port, testWs);
|
|
1374
1410
|
foundAny = true;
|
|
1375
1411
|
activeConnections.push({ port: port, ws: testWs });
|
|
1376
1412
|
updateCompatState();
|
|
@@ -1385,10 +1421,12 @@
|
|
|
1385
1421
|
|
|
1386
1422
|
testWs.onerror = function() {
|
|
1387
1423
|
clearTimeout(timeout);
|
|
1424
|
+
clearConnecting(port, testWs);
|
|
1388
1425
|
};
|
|
1389
1426
|
|
|
1390
1427
|
testWs.onclose = function() {
|
|
1391
1428
|
clearTimeout(timeout);
|
|
1429
|
+
clearConnecting(port, testWs);
|
|
1392
1430
|
pending--;
|
|
1393
1431
|
if (pending <= 0) {
|
|
1394
1432
|
isScanning = false;
|
|
@@ -1435,12 +1473,14 @@
|
|
|
1435
1473
|
if (userPaused || isPortConnected(port)) return;
|
|
1436
1474
|
try {
|
|
1437
1475
|
var testWs = new WebSocket('ws://localhost:' + port);
|
|
1476
|
+
trackConnecting(port, testWs);
|
|
1438
1477
|
var timeout = setTimeout(function() {
|
|
1439
1478
|
if (testWs.readyState !== 1) testWs.close();
|
|
1440
1479
|
}, 2000);
|
|
1441
1480
|
|
|
1442
1481
|
testWs.onopen = function() {
|
|
1443
1482
|
clearTimeout(timeout);
|
|
1483
|
+
clearConnecting(port, testWs);
|
|
1444
1484
|
activeConnections.push({ port: port, ws: testWs });
|
|
1445
1485
|
updateCompatState();
|
|
1446
1486
|
console.log('[MCP Bridge] Reconnected to port ' + port + ' (' + activeConnections.length + ' server(s) total)');
|
|
@@ -1450,6 +1490,12 @@
|
|
|
1450
1490
|
|
|
1451
1491
|
testWs.onerror = function() {
|
|
1452
1492
|
clearTimeout(timeout);
|
|
1493
|
+
clearConnecting(port, testWs);
|
|
1494
|
+
};
|
|
1495
|
+
|
|
1496
|
+
testWs.onclose = function() {
|
|
1497
|
+
clearTimeout(timeout);
|
|
1498
|
+
clearConnecting(port, testWs);
|
|
1453
1499
|
};
|
|
1454
1500
|
} catch (e) {
|
|
1455
1501
|
// Port gone — the discovery loop will find it if it comes back
|
|
@@ -1465,12 +1511,14 @@
|
|
|
1465
1511
|
if (userPaused || isPortConnected(port)) return;
|
|
1466
1512
|
try {
|
|
1467
1513
|
var testWs = new WebSocket('ws://localhost:' + port);
|
|
1514
|
+
trackConnecting(port, testWs);
|
|
1468
1515
|
var timeout = setTimeout(function() {
|
|
1469
1516
|
if (testWs.readyState !== 1) testWs.close();
|
|
1470
1517
|
}, 3000);
|
|
1471
1518
|
|
|
1472
1519
|
testWs.onopen = function() {
|
|
1473
1520
|
clearTimeout(timeout);
|
|
1521
|
+
clearConnecting(port, testWs);
|
|
1474
1522
|
var conn = { port: port, ws: testWs };
|
|
1475
1523
|
if (serverVersion) conn.serverVersion = serverVersion;
|
|
1476
1524
|
activeConnections.push(conn);
|
|
@@ -1482,6 +1530,12 @@
|
|
|
1482
1530
|
|
|
1483
1531
|
testWs.onerror = function() {
|
|
1484
1532
|
clearTimeout(timeout);
|
|
1533
|
+
clearConnecting(port, testWs);
|
|
1534
|
+
};
|
|
1535
|
+
|
|
1536
|
+
testWs.onclose = function() {
|
|
1537
|
+
clearTimeout(timeout);
|
|
1538
|
+
clearConnecting(port, testWs);
|
|
1485
1539
|
};
|
|
1486
1540
|
} catch (e) {
|
|
1487
1541
|
// ignore — next discovery pass will retry
|
|
@@ -1536,7 +1590,11 @@
|
|
|
1536
1590
|
var HANDLER_TIMEOUT_MS = requestedBudget ? Math.min(requestedBudget + 5000, 310000) : 30000;
|
|
1537
1591
|
var handlerSettled = false;
|
|
1538
1592
|
var handlerTimeoutId = null;
|
|
1539
|
-
|
|
1593
|
+
// Wrap inside Promise constructor so synchronous throws reject
|
|
1594
|
+
// into .catch() and send { id, error } instead of hanging the caller.
|
|
1595
|
+
var handlerPromise = new Promise(function(resolve) {
|
|
1596
|
+
resolve(handler(message.params || {}));
|
|
1597
|
+
});
|
|
1540
1598
|
var timeoutPromise = new Promise(function(_, reject) {
|
|
1541
1599
|
handlerTimeoutId = setTimeout(function() {
|
|
1542
1600
|
if (!handlerSettled) {
|
|
@@ -1570,7 +1628,7 @@
|
|
|
1570
1628
|
};
|
|
1571
1629
|
|
|
1572
1630
|
activeWs.onclose = function(event) {
|
|
1573
|
-
removeConnection(
|
|
1631
|
+
removeConnection(activeWs);
|
|
1574
1632
|
console.log('[MCP Bridge] WebSocket disconnected from port ' + port + ' (' + activeConnections.length + ' server(s) remaining)');
|
|
1575
1633
|
|
|
1576
1634
|
// If replaced by same file reconnecting (e.g., plugin reloaded), stop
|
|
@@ -1672,6 +1730,14 @@
|
|
|
1672
1730
|
window.__wsGetActiveConnections = function() { return activeConnections; };
|
|
1673
1731
|
|
|
1674
1732
|
window.__wsDisconnectAll = function() {
|
|
1733
|
+
for (var cPort in connectingSockets) {
|
|
1734
|
+
if (Object.prototype.hasOwnProperty.call(connectingSockets, cPort)) {
|
|
1735
|
+
var cEntry = connectingSockets[cPort];
|
|
1736
|
+
clearTimeout(cEntry.timer);
|
|
1737
|
+
try { cEntry.ws.close(1000, 'Manual disconnect'); } catch (e) {}
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
connectingSockets = {};
|
|
1675
1741
|
for (var i = 0; i < activeConnections.length; i++) {
|
|
1676
1742
|
try { activeConnections[i].ws.close(1000, 'Manual disconnect'); } catch (e) {}
|
|
1677
1743
|
}
|
|
@@ -1982,7 +2048,12 @@
|
|
|
1982
2048
|
}
|
|
1983
2049
|
|
|
1984
2050
|
function escHtml(s) {
|
|
1985
|
-
return s
|
|
2051
|
+
return String(s)
|
|
2052
|
+
.replace(/&/g, '&')
|
|
2053
|
+
.replace(/</g, '<')
|
|
2054
|
+
.replace(/>/g, '>')
|
|
2055
|
+
.replace(/"/g, '"')
|
|
2056
|
+
.replace(/'/g, ''');
|
|
1986
2057
|
}
|
|
1987
2058
|
|
|
1988
2059
|
function log(message, level, ts) {
|
|
@@ -2528,7 +2599,10 @@
|
|
|
2528
2599
|
if (msg.fileContext !== undefined) result.fileContext = msg.fileContext;
|
|
2529
2600
|
request.resolve(result);
|
|
2530
2601
|
} else {
|
|
2531
|
-
|
|
2602
|
+
var errResult = { success: false, error: msg.error || 'Unknown error' };
|
|
2603
|
+
if (msg.data !== undefined) errResult.data = msg.data;
|
|
2604
|
+
if (msg.fileContext !== undefined) errResult.fileContext = msg.fileContext;
|
|
2605
|
+
request.resolve(errResult);
|
|
2532
2606
|
}
|
|
2533
2607
|
window.__figmaPendingRequests.delete(msg.requestId);
|
|
2534
2608
|
}
|