react-native-ai-devtools 1.4.15 → 1.4.17

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/build/index.js CHANGED
@@ -13,7 +13,7 @@ import { getInstallationId, getServerVersion, isDevMode, TELEMETRY_JSONL_PATH }
13
13
  import { isSDKInstalled, querySDKNetwork, getSDKNetworkEntry, getSDKNetworkStats, clearSDKNetwork, querySDKConsole, getSDKConsoleStats, clearSDKConsole } from "./core/sdkBridge.js";
14
14
  import { tap } from "./pro/tap.js";
15
15
  import { getActivateLicenseConfig, handleActivateLicense, getDeleteAccountConfig, handleDeleteAccount, } from "./tools/accountTools.js";
16
- import { logBuffers, networkBuffers, getLogBuffer, getNetworkBuffer, getTotalLogCount, getConnectedAppByDevice, LogBuffer, NetworkBuffer, bundleErrorBuffer, imageBuffer, connectedApps, scanMetroPorts, fetchDevices, selectMainDevice, filterDebuggableDevices, connectToDevice, getConnectedApps, executeInApp, listDebugGlobals, inspectGlobal, reloadApp,
16
+ import { logBuffers, networkBuffers, getLogBuffer, getNetworkBuffer, getTotalLogCount, getConnectedAppByDevice, LogBuffer, NetworkBuffer, bundleErrorBuffer, imageBuffer, connectedApps, scanMetroPorts, fetchDevices, filterDebuggableDevices, connectToDevice, getConnectedApps, executeInApp, listDebugGlobals, inspectGlobal, reloadApp,
17
17
  // React Component Inspection
18
18
  getComponentTree, getScreenLayout, inspectComponent, findComponents, inspectAtPoint, toggleElementInspector, isInspectorActive, getInspectorSelection, getFirstConnectedApp, getLogs, searchLogs, getLogSummary, getNetworkRequests, searchNetworkRequests, getNetworkStats, formatRequestDetails,
19
19
  // Connection state
@@ -3898,43 +3898,6 @@ if (isDevMode()) {
3898
3898
  };
3899
3899
  });
3900
3900
  }
3901
- /**
3902
- * Auto-connect to Metro bundler on startup
3903
- * Scans common ports and connects to any running Metro servers
3904
- */
3905
- async function autoConnectToMetro() {
3906
- console.error("[rn-ai-debugger] Auto-scanning for Metro servers...");
3907
- try {
3908
- const openPorts = await scanMetroPorts();
3909
- if (openPorts.length === 0) {
3910
- console.error("[rn-ai-debugger] No Metro servers found on startup. Use scan_metro to connect later.");
3911
- return;
3912
- }
3913
- for (const port of openPorts) {
3914
- try {
3915
- const devices = await fetchDevices(port);
3916
- const mainDevice = selectMainDevice(devices);
3917
- if (mainDevice) {
3918
- await connectToDevice(mainDevice, port);
3919
- console.error(`[rn-ai-debugger] Auto-connected to ${mainDevice.title} on port ${port}`);
3920
- // Also connect to Metro build events
3921
- try {
3922
- await connectMetroBuildEvents(port);
3923
- }
3924
- catch {
3925
- // Build events connection is optional
3926
- }
3927
- }
3928
- }
3929
- catch (error) {
3930
- console.error(`[rn-ai-debugger] Failed to auto-connect on port ${port}: ${error}`);
3931
- }
3932
- }
3933
- }
3934
- catch (error) {
3935
- console.error(`[rn-ai-debugger] Auto-connect error: ${error}`);
3936
- }
3937
- }
3938
3901
  // Main function
3939
3902
  async function main() {
3940
3903
  // Initialize telemetry (checks opt-out env var, loads/creates installation ID)
@@ -4017,19 +3980,38 @@ async function main() {
4017
3980
  await server.connect(transport);
4018
3981
  console.error("[rn-ai-debugger] Server started on stdio");
4019
3982
  }
4020
- // Auto-connect to Metro in background (non-blocking)
4021
- // Use setImmediate to ensure MCP server is fully ready first
4022
- setImmediate(() => {
4023
- autoConnectToMetro().catch((err) => {
4024
- console.error("[rn-ai-debugger] Auto-connect failed:", err);
4025
- });
4026
- });
4027
3983
  }
4028
3984
  main().catch((error) => {
4029
3985
  console.error("[rn-ai-debugger] Fatal error:", error);
4030
3986
  process.exit(1);
4031
3987
  });
3988
+ // Graceful shutdown: close CDP connections so the slot is freed for other sessions
3989
+ function gracefulShutdown() {
3990
+ suppressReconnection();
3991
+ cancelAllReconnectionTimers();
3992
+ for (const [key, app] of connectedApps.entries()) {
3993
+ try {
3994
+ app.ws.close();
3995
+ }
3996
+ catch {
3997
+ // Ignore close errors during shutdown
3998
+ }
3999
+ connectedApps.delete(key);
4000
+ }
4001
+ disconnectMetroBuildEvents();
4002
+ clearAllConnectionState();
4003
+ clearAllCDPMessageTimes();
4004
+ shutdownPostHog().catch(() => { });
4005
+ }
4032
4006
  process.on("beforeExit", () => {
4033
4007
  shutdownPostHog().catch(() => { });
4034
4008
  });
4009
+ process.on("SIGINT", () => {
4010
+ gracefulShutdown();
4011
+ process.exit(0);
4012
+ });
4013
+ process.on("SIGTERM", () => {
4014
+ gracefulShutdown();
4015
+ process.exit(0);
4016
+ });
4035
4017
  //# sourceMappingURL=index.js.map