axhub-mcp-bridge 1.0.35 → 1.0.36

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.
@@ -7,7 +7,7 @@ export declare enum NATIVE_MESSAGE_TYPE {
7
7
  PONG = "pong",
8
8
  ERROR = "error"
9
9
  }
10
- export declare const NATIVE_SERVER_PORT = 56889;
10
+ export declare const NATIVE_SERVER_PORT: number;
11
11
  export declare const TIMEOUTS: {
12
12
  readonly DEFAULT_REQUEST_TIMEOUT: 90000;
13
13
  readonly EXTENSION_REQUEST_TIMEOUT: 90000;
@@ -11,7 +11,9 @@ var NATIVE_MESSAGE_TYPE;
11
11
  NATIVE_MESSAGE_TYPE["PONG"] = "pong";
12
12
  NATIVE_MESSAGE_TYPE["ERROR"] = "error";
13
13
  })(NATIVE_MESSAGE_TYPE || (exports.NATIVE_MESSAGE_TYPE = NATIVE_MESSAGE_TYPE = {}));
14
- exports.NATIVE_SERVER_PORT = 56889;
14
+ // Use different ports for dev and production
15
+ // Dev: 12307, Prod: 12308 (matches Chrome extension configuration)
16
+ exports.NATIVE_SERVER_PORT = process.env.NODE_ENV === 'production' ? 12308 : 12307;
15
17
  // Timeout constants (in milliseconds)
16
18
  exports.TIMEOUTS = {
17
19
  DEFAULT_REQUEST_TIMEOUT: 90000,
@@ -22,7 +24,7 @@ exports.TIMEOUTS = {
22
24
  exports.SERVER_CONFIG = {
23
25
  HOST: '127.0.0.1',
24
26
  CORS_ORIGIN: true,
25
- LOGGER_ENABLED: false,
27
+ LOGGER_ENABLED: false, // CRITICAL: Must be false! Fastify logger outputs to stdout, corrupting Native Messaging Protocol
26
28
  };
27
29
  // HTTP Status codes
28
30
  exports.HTTP_STATUS = {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constant/index.ts"],"names":[],"mappings":";;;AAAA,IAAY,mBAQX;AARD,WAAY,mBAAmB;IAC7B,sCAAe,CAAA;IACf,0CAAmB,CAAA;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mEAAmE;AACtD,QAAA,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;AAExF,sCAAsC;AACzB,QAAA,QAAQ,GAAG;IACtB,uBAAuB,EAAE,KAAK;IAC9B,yBAAyB,EAAE,KAAK;IAChC,oBAAoB,EAAE,KAAK;CACnB,CAAC;AAEX,uBAAuB;AACV,QAAA,aAAa,GAAG;IAC3B,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE,IAAI;IACjB,cAAc,EAAE,KAAK,EAAE,kGAAkG;CACjH,CAAC;AAEX,oBAAoB;AACP,QAAA,WAAW,GAAG;IACzB,EAAE,EAAE,GAAG;IACP,UAAU,EAAE,GAAG;IACf,WAAW,EAAE,GAAG;IAChB,qBAAqB,EAAE,GAAG;IAC1B,eAAe,EAAE,GAAG;CACZ,CAAC;AAEX,iBAAiB;AACJ,QAAA,cAAc,GAAG;IAC5B,yBAAyB,EAAE,yCAAyC;IACpE,kBAAkB,EAAE,iCAAiC;IACrD,eAAe,EAAE,iCAAiC;IAClD,mBAAmB,EAAE,iCAAiC;IACtD,kBAAkB,EAAE,oCAAoC;IACxD,qBAAqB,EAAE,uBAAuB;IAC9C,0BAA0B,EAAE,oDAAoD;IAChF,4BAA4B,EAAE,sDAAsD;IACpF,mBAAmB,EAAE,4CAA4C;CACzD,CAAC"}
package/dist/index.js CHANGED
@@ -6,15 +6,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const server_1 = __importDefault(require("./server"));
8
8
  const native_messaging_host_1 = __importDefault(require("./native-messaging-host"));
9
+ const logger_1 = __importDefault(require("./utils/logger"));
9
10
  try {
11
+ logger_1.default.log('Starting native messaging host...');
10
12
  server_1.default.setNativeHost(native_messaging_host_1.default); // Server needs setNativeHost method
11
13
  native_messaging_host_1.default.setServer(server_1.default); // NativeHost needs setServer method
12
14
  native_messaging_host_1.default.start();
15
+ logger_1.default.log('Native messaging host started successfully');
13
16
  }
14
17
  catch (error) {
18
+ logger_1.default.error('Failed to start native messaging host:', { message: error.message, stack: error.stack });
15
19
  process.exit(1);
16
20
  }
17
21
  process.on('error', (error) => {
22
+ logger_1.default.error('Process error:', { message: error.message, stack: error.stack });
18
23
  process.exit(1);
19
24
  });
20
25
  // Handle process signals and uncaught exceptions
@@ -27,9 +32,11 @@ process.on('SIGTERM', () => {
27
32
  process.on('exit', (code) => {
28
33
  });
29
34
  process.on('uncaughtException', (error) => {
35
+ logger_1.default.error('Uncaught exception:', { message: error.message, stack: error.stack });
30
36
  process.exit(1);
31
37
  });
32
38
  process.on('unhandledRejection', (reason) => {
39
+ logger_1.default.error('Unhandled rejection:', reason);
33
40
  // Don't exit immediately, let the program continue running
34
41
  });
35
42
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AACA,sDAAsC;AACtC,oFAAkE;AAElE,IAAI,CAAC;IACH,gBAAc,CAAC,aAAa,CAAC,+BAA2B,CAAC,CAAC,CAAC,oCAAoC;IAC/F,+BAA2B,CAAC,SAAS,CAAC,gBAAc,CAAC,CAAC,CAAC,oCAAoC;IAC3F,+BAA2B,CAAC,KAAK,EAAE,CAAC;AACtC,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;IAC5B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,iDAAiD;AACjD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;IACxB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CA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B,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IAC/E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,iDAAiD;AACjD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;IACxB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;IACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;AAC5B,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,KAAU,EAAE,EAAE;IAC7C,gBAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IACpF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAW,EAAE,EAAE;IAC/C,gBAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;IAC7C,2DAA2D;AAC7D,CAAC,CAAC,CAAC"}
@@ -33,6 +33,9 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  return result;
34
34
  };
35
35
  })();
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
36
39
  Object.defineProperty(exports, "__esModule", { value: true });
37
40
  exports.setupTools = exports.ensureMcpClient = exports.getStdioMcpServer = void 0;
38
41
  const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
@@ -43,6 +46,7 @@ const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
43
46
  const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
44
47
  const fs = __importStar(require("fs"));
45
48
  const path = __importStar(require("path"));
49
+ const logger_1 = __importDefault(require("../utils/logger"));
46
50
  let stdioMcpServer = null;
47
51
  let mcpClient = null;
48
52
  // Read configuration from stdio-config.json
@@ -53,7 +57,7 @@ const loadConfig = () => {
53
57
  return JSON.parse(configData);
54
58
  }
55
59
  catch (error) {
56
- console.error('Failed to load stdio-config.json:', error);
60
+ logger_1.default.error('Failed to load stdio-config.json:', error);
57
61
  throw new Error('Configuration file stdio-config.json not found or invalid');
58
62
  }
59
63
  };
@@ -90,7 +94,7 @@ const ensureMcpClient = async () => {
90
94
  catch (error) {
91
95
  mcpClient === null || mcpClient === void 0 ? void 0 : mcpClient.close();
92
96
  mcpClient = null;
93
- console.error('Failed to connect to MCP server:', error);
97
+ logger_1.default.error('Failed to connect to MCP server:', error);
94
98
  }
95
99
  };
96
100
  exports.ensureMcpClient = ensureMcpClient;
@@ -129,7 +133,7 @@ async function main() {
129
133
  await (0, exports.getStdioMcpServer)().connect(transport);
130
134
  }
131
135
  main().catch((error) => {
132
- console.error('Fatal error Chrome MCP Server main():', error);
136
+ logger_1.default.error('Fatal error Chrome MCP Server main():', error);
133
137
  process.exit(1);
134
138
  });
135
139
  //# sourceMappingURL=mcp-server-stdio.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-server-stdio.js","sourceRoot":"","sources":["../../src/mcp/mcp-server-stdio.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,wEAAmE;AACnE,wEAAmE;AACnE,iEAI4C;AAC5C,sCAAyC;AACzC,wEAAiF;AACjF,0FAAmG;AACnG,uCAAyB;AACzB,2CAA6B;AAE7B,IAAI,cAAc,GAAk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OAAO,MAAwB,CAAC;IAClC,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,uBAAuB,KAAK,CAAC,OAAO,EAAE;iBAC7C;aACF;YACD,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,KAAK,UAAU,IAAI;IACjB,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;IAC7C,MAAM,IAAA,yBAAiB,GAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAC/C,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,gBAAM,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;IAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -7,6 +7,7 @@ exports.setupTools = void 0;
7
7
  const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
8
8
  const native_messaging_host_1 = __importDefault(require("../native-messaging-host"));
9
9
  const shared_1 = require("../shared");
10
+ const logger_1 = __importDefault(require("../utils/logger"));
10
11
  const setupTools = (server) => {
11
12
  // List tools handler
12
13
  server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({ tools: shared_1.TOOL_SCHEMAS }));
@@ -15,12 +16,18 @@ const setupTools = (server) => {
15
16
  };
16
17
  exports.setupTools = setupTools;
17
18
  const handleToolCall = async (name, args) => {
19
+ logger_1.default.log('[TOOL CALL] Starting tool call:', { name, args });
18
20
  try {
21
+ logger_1.default.log('[TOOL CALL] Sending request to Chrome extension...');
19
22
  // 发送请求到Chrome扩展并等待响应
20
23
  const response = await native_messaging_host_1.default.sendRequestToExtensionAndWait({
21
24
  name,
22
25
  args,
23
26
  }, shared_1.NativeMessageType.CALL_TOOL, 90000);
27
+ logger_1.default.log('[TOOL CALL] Received response from Chrome extension:', {
28
+ status: response.status,
29
+ hasData: !!response.data,
30
+ });
24
31
  if (response.status === 'success') {
25
32
  return response.data;
26
33
  }
@@ -37,6 +44,7 @@ const handleToolCall = async (name, args) => {
37
44
  }
38
45
  }
39
46
  catch (error) {
47
+ logger_1.default.error('[TOOL CALL] Error:', error.message);
40
48
  return {
41
49
  content: [
42
50
  {
@@ -1 +1 @@
1
- {"version":3,"file":"register-tools.js","sourceRoot":"","sources":["../../src/mcp/register-tools.ts"],"names":[],"mappings":";;;;;;AACA,iEAI4C;AAC5C,qFAAmE;AACnE,sCAA4D;AAErD,MAAM,UAAU,GAAG,CAAC,MAAc,EAAE,EAAE;IAC3C,qBAAqB;IACrB,MAAM,CAAC,iBAAiB,CAAC,iCAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,qBAAY,EAAE,CAAC,CAAC,CAAC;IAExF,oBAAoB;IACpB,MAAM,CAAC,iBAAiB,CAAC,gCAAqB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAChE,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,CACpE,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,UAAU,cAQrB;AAEF,MAAM,cAAc,GAAG,KAAK,EAAE,IAAY,EAAE,IAAS,EAA2B,EAAE;IAChF,IAAI,CAAC;QACH,qBAAqB;QACrB,MAAM,QAAQ,GAAG,MAAM,+BAA2B,CAAC,6BAA6B,CAC9E;YACE,IAAI;YACJ,IAAI;SACL,EACD,0BAAiB,CAAC,SAAS,EAC3B,KAAK,CACN,CAAC;QACF,IAAI,QAAQ,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAClC,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAM;wBAC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ACJ,IAAI;SACL,EACD,0BAAiB,CAAC,SAAS,EAC3B,KAAK,CACN,CAAC;QACF,gBAAM,CAAC,GAAG,CAAC,sDAAsD,EAAE;YACjE,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI;SACzB,CAAC,CAAC;QACH,IAAI,QAAQ,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAClC,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,uBAAuB,QAAQ,CAAC,KAAK,EAAE;qBAC9C;iBACF;gBACD,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,gBAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAClD,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,uBAAuB,KAAK,CAAC,OAAO,EAAE;iBAC7C;aACF;YACD,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;AACH,CAAC,CAAC"}
@@ -3,6 +3,27 @@ export declare class NativeMessagingHost {
3
3
  private associatedServer;
4
4
  private pendingRequests;
5
5
  setServer(serverInstance: Server): void;
6
+ /**
7
+ * Handle message from Figma plugin (via WebSocket)
8
+ * Forward to Extension via Native Messaging
9
+ */
10
+ handleFigmaMessage(message: any): void;
11
+ /**
12
+ * Handle WebSocket client connection event
13
+ * Notify Extension via Native Messaging
14
+ */
15
+ handleClientConnect(clientId: string, stats: {
16
+ total: number;
17
+ figma: number;
18
+ }): void;
19
+ /**
20
+ * Handle WebSocket client disconnection event
21
+ * Notify Extension via Native Messaging
22
+ */
23
+ handleClientDisconnect(clientId: string, stats: {
24
+ total: number;
25
+ figma: number;
26
+ }): void;
6
27
  start(): void;
7
28
  private setupMessageHandling;
8
29
  private handleMessage;
@@ -18,7 +39,7 @@ export declare class NativeMessagingHost {
18
39
  */
19
40
  private startServer;
20
41
  /**
21
- * Stop Fastify server
42
+ * Stop Fastify server and WebSocket server
22
43
  */
23
44
  private stopServer;
24
45
  /**
@@ -29,6 +50,22 @@ export declare class NativeMessagingHost {
29
50
  * Send error message to Chrome extension (mainly for sending non-request-response type errors)
30
51
  */
31
52
  private sendError;
53
+ /**
54
+ * Start WebSocket server
55
+ */
56
+ private startWebSocket;
57
+ /**
58
+ * Stop WebSocket server
59
+ */
60
+ private stopWebSocket;
61
+ /**
62
+ * Get WebSocket server status
63
+ */
64
+ private getWebSocketStatus;
65
+ /**
66
+ * Send message to Figma clients via WebSocket
67
+ */
68
+ private sendToFigma;
32
69
  /**
33
70
  * Clean up resources
34
71
  */
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.NativeMessagingHost = void 0;
4
7
  const process_1 = require("process");
5
8
  const uuid_1 = require("uuid");
6
9
  const shared_1 = require("./shared");
7
10
  const constant_1 = require("./constant");
11
+ const logger_1 = __importDefault(require("./utils/logger"));
8
12
  class NativeMessagingHost {
9
13
  constructor() {
10
14
  this.associatedServer = null;
@@ -13,6 +17,40 @@ class NativeMessagingHost {
13
17
  setServer(serverInstance) {
14
18
  this.associatedServer = serverInstance;
15
19
  }
20
+ /**
21
+ * Handle message from Figma plugin (via WebSocket)
22
+ * Forward to Extension via Native Messaging
23
+ */
24
+ handleFigmaMessage(message) {
25
+ logger_1.default.log('[NATIVE HOST] Received message from Figma plugin', { messageType: message.type });
26
+ // Forward to Extension via Native Messaging
27
+ this.sendMessage({
28
+ type: shared_1.NativeMessageType.FIGMA_MESSAGE,
29
+ payload: message
30
+ });
31
+ }
32
+ /**
33
+ * Handle WebSocket client connection event
34
+ * Notify Extension via Native Messaging
35
+ */
36
+ handleClientConnect(clientId, stats) {
37
+ logger_1.default.log('[NATIVE HOST] WebSocket client connected', { clientId, stats });
38
+ this.sendMessage({
39
+ type: shared_1.NativeMessageType.WEBSOCKET_CLIENT_CONNECTED,
40
+ payload: { clientId, stats }
41
+ });
42
+ }
43
+ /**
44
+ * Handle WebSocket client disconnection event
45
+ * Notify Extension via Native Messaging
46
+ */
47
+ handleClientDisconnect(clientId, stats) {
48
+ logger_1.default.log('[NATIVE HOST] WebSocket client disconnected', { clientId, stats });
49
+ this.sendMessage({
50
+ type: shared_1.NativeMessageType.WEBSOCKET_CLIENT_DISCONNECTED,
51
+ payload: { clientId, stats }
52
+ });
53
+ }
16
54
  // add message handler to wait for start server
17
55
  start() {
18
56
  try {
@@ -56,11 +94,18 @@ class NativeMessagingHost {
56
94
  }
57
95
  async handleMessage(message) {
58
96
  var _a;
97
+ logger_1.default.log('[NATIVE HOST] Received message:', {
98
+ type: message.type,
99
+ responseToRequestId: message.responseToRequestId,
100
+ hasPayload: !!message.payload,
101
+ });
59
102
  if (!message || typeof message !== 'object') {
103
+ logger_1.default.error('[NATIVE HOST] Invalid message format');
60
104
  this.sendError('Invalid message format');
61
105
  return;
62
106
  }
63
107
  if (message.responseToRequestId) {
108
+ logger_1.default.log('[NATIVE HOST] This is a response message, handling...');
64
109
  const requestId = message.responseToRequestId;
65
110
  const pending = this.pendingRequests.get(requestId);
66
111
  if (pending) {
@@ -79,26 +124,54 @@ class NativeMessagingHost {
79
124
  return;
80
125
  }
81
126
  // Handle directive messages from Chrome
127
+ logger_1.default.log('[NATIVE HOST] Handling directive message, type:', message.type);
128
+ logger_1.default.log('[NATIVE HOST] NativeMessageType.START value:', shared_1.NativeMessageType.START);
129
+ logger_1.default.log('[NATIVE HOST] Type comparison (===):', message.type === shared_1.NativeMessageType.START);
130
+ logger_1.default.log('[NATIVE HOST] Type comparison (==):', message.type == shared_1.NativeMessageType.START);
131
+ logger_1.default.log('[NATIVE HOST] typeof message.type:', typeof message.type);
82
132
  try {
83
133
  switch (message.type) {
84
134
  case shared_1.NativeMessageType.START:
135
+ logger_1.default.log('[NATIVE HOST] ✅ Matched START case, calling startServer...');
85
136
  await this.startServer(((_a = message.payload) === null || _a === void 0 ? void 0 : _a.port) || 3000);
137
+ logger_1.default.log('[NATIVE HOST] ✅ startServer completed');
86
138
  break;
87
139
  case shared_1.NativeMessageType.STOP:
140
+ logger_1.default.log('[NATIVE HOST] ✅ Matched STOP case');
88
141
  await this.stopServer();
89
142
  break;
143
+ case shared_1.NativeMessageType.START_WEBSOCKET:
144
+ logger_1.default.log('[NATIVE HOST] ✅ Matched START_WEBSOCKET case');
145
+ await this.startWebSocket();
146
+ break;
147
+ case shared_1.NativeMessageType.STOP_WEBSOCKET:
148
+ logger_1.default.log('[NATIVE HOST] ✅ Matched STOP_WEBSOCKET case');
149
+ await this.stopWebSocket();
150
+ break;
151
+ case shared_1.NativeMessageType.WEBSOCKET_STATUS:
152
+ logger_1.default.log('[NATIVE HOST] ✅ Matched WEBSOCKET_STATUS case');
153
+ this.getWebSocketStatus();
154
+ break;
155
+ case shared_1.NativeMessageType.FIGMA_MESSAGE:
156
+ logger_1.default.log('[NATIVE HOST] ✅ Matched FIGMA_MESSAGE case');
157
+ this.sendToFigma(message.payload);
158
+ break;
90
159
  // Keep ping/pong for simple liveness detection, but this differs from request-response pattern
91
160
  case 'ping_from_extension':
161
+ logger_1.default.log('[NATIVE HOST] ✅ Matched ping case');
92
162
  this.sendMessage({ type: 'pong_to_extension' });
93
163
  break;
94
164
  default:
165
+ logger_1.default.warn('[NATIVE HOST] ❌ No case matched, message type:', message.type);
95
166
  // Double check when message type is not supported
96
167
  if (!message.responseToRequestId) {
97
168
  this.sendError(`Unknown message type or non-response message: ${message.type || 'no type'}`);
98
169
  }
99
170
  }
171
+ logger_1.default.log('[NATIVE HOST] Switch statement completed');
100
172
  }
101
173
  catch (error) {
174
+ logger_1.default.error('[NATIVE HOST] Error in handleMessage:', { message: error.message, stack: error.stack });
102
175
  this.sendError(`Failed to handle directive message: ${error.message}`);
103
176
  }
104
177
  }
@@ -111,6 +184,11 @@ class NativeMessagingHost {
111
184
  sendRequestToExtensionAndWait(messagePayload, messageType = 'request_data', timeoutMs = constant_1.TIMEOUTS.DEFAULT_REQUEST_TIMEOUT) {
112
185
  return new Promise((resolve, reject) => {
113
186
  const requestId = (0, uuid_1.v4)(); // Generate unique request ID
187
+ logger_1.default.log('[NATIVE HOST] Sending request to extension:', {
188
+ requestId,
189
+ messageType,
190
+ payload: messagePayload,
191
+ });
114
192
  const timeoutId = setTimeout(() => {
115
193
  this.pendingRequests.delete(requestId); // Remove from Map after timeout
116
194
  reject(new Error(`Request timed out after ${timeoutMs}ms`));
@@ -129,30 +207,75 @@ class NativeMessagingHost {
129
207
  * Start Fastify server (now accepts Server instance)
130
208
  */
131
209
  async startServer(port) {
210
+ logger_1.default.log('[START SERVER] Called with port:', port);
132
211
  if (!this.associatedServer) {
212
+ logger_1.default.error('[START SERVER] Server instance not set');
133
213
  this.sendError('Internal error: server instance not set');
134
214
  return;
135
215
  }
136
216
  try {
137
- if (this.associatedServer.isRunning) {
217
+ logger_1.default.log('[START SERVER] Checking if servers are already running...');
218
+ const httpRunning = this.associatedServer.isRunning;
219
+ const wsStatus = this.associatedServer.getWebSocketStatus();
220
+ const wsRunning = wsStatus.running;
221
+ if (httpRunning && wsRunning) {
222
+ logger_1.default.warn('[START SERVER] Both HTTP and WebSocket servers are already running');
138
223
  this.sendMessage({
139
224
  type: shared_1.NativeMessageType.ERROR,
140
- payload: { message: 'Server is already running' },
225
+ payload: { message: 'Both HTTP and WebSocket servers are already running' },
141
226
  });
142
227
  return;
143
228
  }
144
- await this.associatedServer.start(port, this);
229
+ // Start HTTP server if not running
230
+ if (!httpRunning) {
231
+ logger_1.default.log('[START SERVER] Starting HTTP server on port:', port);
232
+ await this.associatedServer.start(port, this);
233
+ logger_1.default.log('[START SERVER] HTTP server started successfully');
234
+ }
235
+ else {
236
+ logger_1.default.log('[START SERVER] HTTP server already running, skipping');
237
+ }
238
+ // Start WebSocket server if not running
239
+ if (!wsRunning) {
240
+ logger_1.default.log('[START SERVER] Starting WebSocket server...');
241
+ const wsResult = this.associatedServer.startWebSocket();
242
+ if (!wsResult.success) {
243
+ logger_1.default.error('[START SERVER] Failed to start WebSocket server:', wsResult.error);
244
+ // If HTTP started but WebSocket failed, we should stop HTTP to maintain consistency
245
+ if (!httpRunning) {
246
+ try {
247
+ await this.associatedServer.stop();
248
+ }
249
+ catch (stopError) {
250
+ logger_1.default.error('[START SERVER] Failed to stop HTTP server after WebSocket failure:', stopError);
251
+ }
252
+ }
253
+ this.sendError(`Failed to start WebSocket server: ${wsResult.error}`);
254
+ return;
255
+ }
256
+ logger_1.default.log('[START SERVER] WebSocket server started successfully');
257
+ }
258
+ else {
259
+ logger_1.default.log('[START SERVER] WebSocket server already running, skipping');
260
+ }
145
261
  this.sendMessage({
146
262
  type: shared_1.NativeMessageType.SERVER_STARTED,
147
263
  payload: { port },
148
264
  });
265
+ // Also send WebSocket started message for consistency
266
+ this.sendMessage({
267
+ type: shared_1.NativeMessageType.WEBSOCKET_STARTED,
268
+ payload: { success: true },
269
+ });
270
+ logger_1.default.log('[START SERVER] Both servers started successfully');
149
271
  }
150
272
  catch (error) {
273
+ logger_1.default.error('[START SERVER] Failed to start server:', { message: error.message, stack: error.stack });
151
274
  this.sendError(`Failed to start server: ${error.message}`);
152
275
  }
153
276
  }
154
277
  /**
155
- * Stop Fastify server
278
+ * Stop Fastify server and WebSocket server
156
279
  */
157
280
  async stopServer() {
158
281
  if (!this.associatedServer) {
@@ -161,18 +284,40 @@ class NativeMessagingHost {
161
284
  }
162
285
  try {
163
286
  // Check status through associatedServer
164
- if (!this.associatedServer.isRunning) {
287
+ const httpRunning = this.associatedServer.isRunning;
288
+ const wsStatus = this.associatedServer.getWebSocketStatus();
289
+ const wsRunning = wsStatus.running;
290
+ if (!httpRunning && !wsRunning) {
165
291
  this.sendMessage({
166
292
  type: shared_1.NativeMessageType.ERROR,
167
- payload: { message: 'Server is not running' },
293
+ payload: { message: 'Both HTTP and WebSocket servers are not running' },
168
294
  });
169
295
  return;
170
296
  }
171
- await this.associatedServer.stop();
172
- // this.serverStarted = false; // Server should update its own status after successful stop
173
- this.sendMessage({ type: shared_1.NativeMessageType.SERVER_STOPPED }); // Distinguish from previous 'stopped'
297
+ // Stop WebSocket server first if running
298
+ if (wsRunning) {
299
+ logger_1.default.log('[STOP SERVER] Stopping WebSocket server...');
300
+ const wsResult = this.associatedServer.stopWebSocket();
301
+ if (wsResult.success) {
302
+ logger_1.default.log('[STOP SERVER] WebSocket server stopped successfully');
303
+ this.sendMessage({ type: shared_1.NativeMessageType.WEBSOCKET_STOPPED });
304
+ }
305
+ else {
306
+ logger_1.default.warn('[STOP SERVER] Failed to stop WebSocket server:', wsResult.error);
307
+ // Continue to stop HTTP server even if WebSocket stop fails
308
+ }
309
+ }
310
+ // Stop HTTP server if running
311
+ if (httpRunning) {
312
+ logger_1.default.log('[STOP SERVER] Stopping HTTP server...');
313
+ await this.associatedServer.stop();
314
+ logger_1.default.log('[STOP SERVER] HTTP server stopped successfully');
315
+ this.sendMessage({ type: shared_1.NativeMessageType.SERVER_STOPPED });
316
+ }
317
+ logger_1.default.log('[STOP SERVER] Both servers stopped successfully');
174
318
  }
175
319
  catch (error) {
320
+ logger_1.default.error('[STOP SERVER] Failed to stop server:', error);
176
321
  this.sendError(`Failed to stop server: ${error.message}`);
177
322
  }
178
323
  }
@@ -180,6 +325,11 @@ class NativeMessagingHost {
180
325
  * Send message to Chrome extension
181
326
  */
182
327
  sendMessage(message) {
328
+ logger_1.default.log('[NATIVE HOST] Sending message to Chrome:', {
329
+ type: message.type,
330
+ requestId: message.requestId,
331
+ responseToRequestId: message.responseToRequestId,
332
+ });
183
333
  try {
184
334
  const messageString = JSON.stringify(message);
185
335
  const messageBuffer = Buffer.from(messageString);
@@ -210,6 +360,119 @@ class NativeMessagingHost {
210
360
  payload: { message: errorMessage },
211
361
  });
212
362
  }
363
+ /**
364
+ * Start WebSocket server
365
+ */
366
+ async startWebSocket() {
367
+ logger_1.default.log('[START WEBSOCKET] Called');
368
+ if (!this.associatedServer) {
369
+ logger_1.default.error('[START WEBSOCKET] Server instance not set');
370
+ this.sendError('Internal error: server instance not set');
371
+ return;
372
+ }
373
+ try {
374
+ const result = this.associatedServer.startWebSocket();
375
+ if (result.success) {
376
+ logger_1.default.log('[START WEBSOCKET] WebSocket server started successfully');
377
+ this.sendMessage({
378
+ type: shared_1.NativeMessageType.WEBSOCKET_STARTED,
379
+ payload: { success: true },
380
+ });
381
+ }
382
+ else {
383
+ logger_1.default.warn('[START WEBSOCKET] Failed to start:', result.error);
384
+ this.sendMessage({
385
+ type: shared_1.NativeMessageType.ERROR,
386
+ payload: { message: result.error || 'Failed to start WebSocket server' },
387
+ });
388
+ }
389
+ }
390
+ catch (error) {
391
+ logger_1.default.error('[START WEBSOCKET] Error:', error);
392
+ this.sendError(`Failed to start WebSocket server: ${error.message}`);
393
+ }
394
+ }
395
+ /**
396
+ * Stop WebSocket server
397
+ */
398
+ async stopWebSocket() {
399
+ logger_1.default.log('[STOP WEBSOCKET] Called');
400
+ if (!this.associatedServer) {
401
+ this.sendError('Internal error: server instance not set');
402
+ return;
403
+ }
404
+ try {
405
+ const result = this.associatedServer.stopWebSocket();
406
+ if (result.success) {
407
+ logger_1.default.log('[STOP WEBSOCKET] WebSocket server stopped successfully');
408
+ this.sendMessage({
409
+ type: shared_1.NativeMessageType.WEBSOCKET_STOPPED,
410
+ payload: { success: true },
411
+ });
412
+ }
413
+ else {
414
+ logger_1.default.warn('[STOP WEBSOCKET] Failed to stop:', result.error);
415
+ this.sendMessage({
416
+ type: shared_1.NativeMessageType.ERROR,
417
+ payload: { message: result.error || 'Failed to stop WebSocket server' },
418
+ });
419
+ }
420
+ }
421
+ catch (error) {
422
+ logger_1.default.error('[STOP WEBSOCKET] Error:', error);
423
+ this.sendError(`Failed to stop WebSocket server: ${error.message}`);
424
+ }
425
+ }
426
+ /**
427
+ * Get WebSocket server status
428
+ */
429
+ getWebSocketStatus() {
430
+ logger_1.default.log('[WEBSOCKET STATUS] Called');
431
+ if (!this.associatedServer) {
432
+ this.sendError('Internal error: server instance not set');
433
+ return;
434
+ }
435
+ try {
436
+ const status = this.associatedServer.getWebSocketStatus();
437
+ logger_1.default.log('[WEBSOCKET STATUS] Status:', status);
438
+ this.sendMessage({
439
+ type: shared_1.NativeMessageType.WEBSOCKET_STATUS,
440
+ payload: status,
441
+ });
442
+ }
443
+ catch (error) {
444
+ logger_1.default.error('[WEBSOCKET STATUS] Error:', error);
445
+ this.sendError(`Failed to get WebSocket status: ${error.message}`);
446
+ }
447
+ }
448
+ /**
449
+ * Send message to Figma clients via WebSocket
450
+ */
451
+ sendToFigma(payload) {
452
+ logger_1.default.log('[SEND TO FIGMA] Called with payload:', payload);
453
+ if (!this.associatedServer) {
454
+ this.sendError('Internal error: server instance not set');
455
+ return;
456
+ }
457
+ try {
458
+ const result = this.associatedServer.sendToFigma(payload);
459
+ if (result.success) {
460
+ logger_1.default.log('[SEND TO FIGMA] Message sent successfully');
461
+ // Don't send response for fire-and-forget messages
462
+ }
463
+ else {
464
+ logger_1.default.warn('[SEND TO FIGMA] Failed to send:', result.error);
465
+ this.sendMessage({
466
+ type: shared_1.NativeMessageType.ERROR,
467
+ payload: { message: result.error || 'Failed to send message to Figma' },
468
+ });
469
+ }
470
+ }
471
+ catch (error) {
472
+ logger_1.default.error('[SEND TO FIGMA] Error:', error);
473
+ this.sendError(`Failed to send message to Figma: ${error.message}`);
474
+ }
475
+ }
213
476
  /**
214
477
  * Clean up resources
215
478
  */