@comake/skl-js-engine 1.0.8 → 1.1.0

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/dist/JsExecutor/PermissionBuilder.d.ts +13 -0
  2. package/dist/JsExecutor/PermissionBuilder.js +58 -0
  3. package/dist/JsExecutor/PermissionBuilder.js.map +1 -0
  4. package/dist/JsExecutor/constants.d.ts +26 -0
  5. package/dist/JsExecutor/constants.js +30 -0
  6. package/dist/JsExecutor/constants.js.map +1 -0
  7. package/dist/JsExecutor/denoUtils.d.ts +9 -0
  8. package/dist/JsExecutor/denoUtils.js +24 -0
  9. package/dist/JsExecutor/denoUtils.js.map +1 -0
  10. package/dist/JsExecutor/errors.d.ts +39 -0
  11. package/dist/JsExecutor/errors.js +67 -0
  12. package/dist/JsExecutor/errors.js.map +1 -0
  13. package/dist/JsExecutor/examples/basic/index.d.ts +0 -0
  14. package/dist/JsExecutor/examples/basic/index.js +46 -0
  15. package/dist/JsExecutor/examples/basic/index.js.map +1 -0
  16. package/dist/JsExecutor/examples/basic/process.d.ts +0 -0
  17. package/dist/JsExecutor/examples/basic/process.js +34 -0
  18. package/dist/JsExecutor/examples/basic/process.js.map +1 -0
  19. package/dist/JsExecutor/examples/jsExecutor/index.d.ts +1 -0
  20. package/dist/JsExecutor/examples/jsExecutor/index.js +48 -0
  21. package/dist/JsExecutor/examples/jsExecutor/index.js.map +1 -0
  22. package/dist/JsExecutor/examples/jsExecutor/process.d.ts +1 -0
  23. package/dist/JsExecutor/examples/jsExecutor/process.js +59 -0
  24. package/dist/JsExecutor/examples/jsExecutor/process.js.map +1 -0
  25. package/dist/JsExecutor/index.d.ts +6 -0
  26. package/dist/JsExecutor/index.js +36 -0
  27. package/dist/JsExecutor/index.js.map +1 -0
  28. package/dist/JsExecutor/jsExecutor.d.ts +67 -0
  29. package/dist/JsExecutor/jsExecutor.js +159 -0
  30. package/dist/JsExecutor/jsExecutor.js.map +1 -0
  31. package/dist/JsExecutor/jsonRpc/JsonRpcClient.d.ts +164 -0
  32. package/dist/JsExecutor/jsonRpc/JsonRpcClient.js +334 -0
  33. package/dist/JsExecutor/jsonRpc/JsonRpcClient.js.map +1 -0
  34. package/dist/JsExecutor/jsonRpc/JsonRpcServer.d.ts +124 -0
  35. package/dist/JsExecutor/jsonRpc/JsonRpcServer.js +391 -0
  36. package/dist/JsExecutor/jsonRpc/JsonRpcServer.js.map +1 -0
  37. package/dist/JsExecutor/jsonRpc/index.d.ts +3 -0
  38. package/dist/JsExecutor/jsonRpc/index.js +23 -0
  39. package/dist/JsExecutor/jsonRpc/index.js.map +1 -0
  40. package/dist/JsExecutor/jsonRpc/types.d.ts +192 -0
  41. package/dist/JsExecutor/jsonRpc/types.js +37 -0
  42. package/dist/JsExecutor/jsonRpc/types.js.map +1 -0
  43. package/dist/JsExecutor/transport/StdioTransport.d.ts +226 -0
  44. package/dist/JsExecutor/transport/StdioTransport.js +634 -0
  45. package/dist/JsExecutor/transport/StdioTransport.js.map +1 -0
  46. package/dist/JsExecutor/transport/Transport.d.ts +71 -0
  47. package/dist/JsExecutor/transport/Transport.js +14 -0
  48. package/dist/JsExecutor/transport/Transport.js.map +1 -0
  49. package/dist/JsExecutor/transport/base/BaseTransport.d.ts +50 -0
  50. package/dist/JsExecutor/transport/base/BaseTransport.js +68 -0
  51. package/dist/JsExecutor/transport/base/BaseTransport.js.map +1 -0
  52. package/dist/JsExecutor/transport/index.d.ts +12 -0
  53. package/dist/JsExecutor/transport/index.js +36 -0
  54. package/dist/JsExecutor/transport/index.js.map +1 -0
  55. package/dist/JsExecutor/transport/process/ProcessManager.d.ts +95 -0
  56. package/dist/JsExecutor/transport/process/ProcessManager.js +214 -0
  57. package/dist/JsExecutor/transport/process/ProcessManager.js.map +1 -0
  58. package/dist/JsExecutor/transport/stdio/ChildStdioTransport.d.ts +86 -0
  59. package/dist/JsExecutor/transport/stdio/ChildStdioTransport.js +215 -0
  60. package/dist/JsExecutor/transport/stdio/ChildStdioTransport.js.map +1 -0
  61. package/dist/JsExecutor/transport/stdio/ParentStdioTransport.d.ts +80 -0
  62. package/dist/JsExecutor/transport/stdio/ParentStdioTransport.js +263 -0
  63. package/dist/JsExecutor/transport/stdio/ParentStdioTransport.js.map +1 -0
  64. package/dist/JsExecutor/transport/utils/MessageUtils.d.ts +67 -0
  65. package/dist/JsExecutor/transport/utils/MessageUtils.js +135 -0
  66. package/dist/JsExecutor/transport/utils/MessageUtils.js.map +1 -0
  67. package/dist/JsExecutor/types.d.ts +112 -0
  68. package/dist/JsExecutor/types.js +3 -0
  69. package/dist/JsExecutor/types.js.map +1 -0
  70. package/dist/SklEngine.d.ts +9 -5
  71. package/dist/SklEngine.js +84 -87
  72. package/dist/SklEngine.js.map +1 -1
  73. package/dist/SklEngineOptions.d.ts +4 -0
  74. package/dist/constants.d.ts +1 -1
  75. package/dist/customCapabilities.d.ts +21 -0
  76. package/dist/customCapabilities.js +45 -0
  77. package/dist/customCapabilities.js.map +1 -0
  78. package/dist/examples/customCapabilitiesExample.d.ts +1 -0
  79. package/dist/examples/customCapabilitiesExample.js +57 -0
  80. package/dist/examples/customCapabilitiesExample.js.map +1 -0
  81. package/dist/executor.js +9 -3
  82. package/dist/index.d.ts +13 -11
  83. package/dist/index.js +20 -16
  84. package/dist/index.js.map +1 -1
  85. package/dist/logger.d.ts +5 -1
  86. package/dist/logger.js +21 -4
  87. package/dist/logger.js.map +1 -1
  88. package/dist/util/Vocabularies/Shared.d.ts +1 -1
  89. package/dist/util/Vocabularies/index.d.ts +1 -1
  90. package/package.json +1 -1
  91. package/dist/Jsexecutor.d.ts +0 -77
  92. package/dist/Jsexecutor.js +0 -184
  93. package/dist/Jsexecutor.js.map +0 -1
  94. package/dist/storage/operator/ArrayEqual.d.ts +0 -3
  95. package/dist/storage/operator/ArrayEqual.js +0 -13
  96. package/dist/storage/operator/ArrayEqual.js.map +0 -1
  97. package/dist/util/Vocabularies/core.d.ts +0 -7
  98. package/dist/util/Vocabularies/core.js +0 -119
  99. package/dist/util/Vocabularies/core.js.map +0 -1
@@ -0,0 +1,634 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StdioServerTransport = exports.BidirectionalStdioTransport = exports.StdioClientTransport = exports.StdioTransport = void 0;
4
+ const node_events_1 = require("node:events");
5
+ const logger_1 = require("../../logger");
6
+ const constants_1 = require("../constants");
7
+ const denoUtils_1 = require("../denoUtils");
8
+ const errors_1 = require("../errors");
9
+ const JsonRpcClient_1 = require("../jsonRpc/JsonRpcClient");
10
+ const JsonRpcServer_1 = require("../jsonRpc/JsonRpcServer");
11
+ const types_1 = require("../jsonRpc/types");
12
+ const PermissionBuilder_1 = require("../PermissionBuilder");
13
+ const Transport_1 = require("./Transport");
14
+ /**
15
+ * StdioTransport implementation using stdin/stdout for JSON-RPC communication
16
+ * This is the parent-side transport that manages a child process
17
+ */
18
+ class StdioTransport extends node_events_1.EventEmitter {
19
+ constructor(executorScriptPath, server) {
20
+ super();
21
+ this._status = Transport_1.TransportStatus.disconnected;
22
+ this.logger = logger_1.Logger.getInstance();
23
+ this.executorScriptPath = executorScriptPath;
24
+ this.server = server;
25
+ this.client = new JsonRpcClient_1.JsonRpcClient();
26
+ this.clientTransport = new StdioClientTransport();
27
+ this.setupServerMethods();
28
+ this.setupEventHandlers();
29
+ }
30
+ setName(name) {
31
+ this.name = name;
32
+ this.logger.setMetadata({ name, transport: 'StdioTransport' });
33
+ }
34
+ get status() {
35
+ return this._status;
36
+ }
37
+ /**
38
+ * Initialize the transport connection
39
+ */
40
+ async initialize(config, executionOptions) {
41
+ if (this._status !== Transport_1.TransportStatus.disconnected) {
42
+ throw new Error(`Cannot initialize transport in ${this._status} state`);
43
+ }
44
+ try {
45
+ this.setStatus(Transport_1.TransportStatus.connecting);
46
+ const normalizedOptions = this.normalizeOptions(executionOptions);
47
+ const permissionConfig = this.extractPermissionConfig(normalizedOptions);
48
+ // Validate permissions before proceeding
49
+ (0, PermissionBuilder_1.validatePermissionConfig)(permissionConfig);
50
+ const permissions = (0, PermissionBuilder_1.buildDenoPermissions)(permissionConfig);
51
+ const mergedPermissions = [...constants_1.EXECUTION_CONSTANTS.denoFlags];
52
+ permissions.forEach(permission => {
53
+ if (!mergedPermissions.includes(permission)) {
54
+ mergedPermissions.push(permission);
55
+ }
56
+ });
57
+ // Build command arguments (will be updated when we have permission support)
58
+ const commandArgs = [...mergedPermissions, this.executorScriptPath];
59
+ // Spawn the Deno process
60
+ this.childProcess = (0, denoUtils_1.spawnDenoProcess)(commandArgs);
61
+ // Set up client transport
62
+ this.clientTransport.setProcess(this.childProcess.stdout, this.childProcess.stdin);
63
+ this.client.setTransport(this.clientTransport);
64
+ // Set up process communication
65
+ this.setupProcessCommunication();
66
+ // Wait for process to be ready
67
+ await this.waitForReady(config?.timeout ?? 5000);
68
+ this.setStatus(Transport_1.TransportStatus.connected);
69
+ }
70
+ catch (error) {
71
+ this.setStatus(Transport_1.TransportStatus.error);
72
+ throw error;
73
+ }
74
+ }
75
+ /**
76
+ * Normalizes execution options with defaults
77
+ * @param options - Raw execution options
78
+ * @returns Normalized options with all required fields
79
+ */
80
+ normalizeOptions(options) {
81
+ return {
82
+ timeout: options?.timeout ?? constants_1.DEFAULT_EXECUTION_OPTIONS.timeout,
83
+ functionName: options?.functionName ?? constants_1.DEFAULT_EXECUTION_OPTIONS.functionName,
84
+ allowNetwork: options?.allowNetwork ?? constants_1.DEFAULT_EXECUTION_OPTIONS.allowNetwork,
85
+ allowedDomains: options?.allowedDomains ?? [...constants_1.DEFAULT_EXECUTION_OPTIONS.allowedDomains],
86
+ allowEnv: options?.allowEnv ?? constants_1.DEFAULT_EXECUTION_OPTIONS.allowEnv,
87
+ allowRead: options?.allowRead ?? constants_1.DEFAULT_EXECUTION_OPTIONS.allowRead,
88
+ debugMode: options?.debugMode ?? constants_1.DEFAULT_EXECUTION_OPTIONS.debugMode,
89
+ retries: options?.retries ?? constants_1.DEFAULT_EXECUTION_OPTIONS.retries
90
+ };
91
+ }
92
+ /**
93
+ * Extracts permission configuration from execution options
94
+ * @param options - Normalized execution options
95
+ * @returns Permission configuration object
96
+ */
97
+ extractPermissionConfig(options) {
98
+ return {
99
+ allowNetwork: options.allowNetwork,
100
+ allowedDomains: options.allowedDomains,
101
+ allowEnv: options.allowEnv,
102
+ allowRead: options.allowRead
103
+ };
104
+ }
105
+ /**
106
+ * Send a message through the transport
107
+ */
108
+ async send(message) {
109
+ if (!this.isReady()) {
110
+ throw new Error('Transport is not ready');
111
+ }
112
+ // Expect message to have method and params for direct RPC calls
113
+ const rpcMessage = message;
114
+ if (rpcMessage.method) {
115
+ return this.client.request(rpcMessage.method, rpcMessage.params);
116
+ }
117
+ throw new Error('Message must have a method property for RPC calls');
118
+ }
119
+ /**
120
+ * Make a direct RPC request to the child process
121
+ */
122
+ async request(method, params, options) {
123
+ if (!this.isReady()) {
124
+ throw new Error('Transport is not ready');
125
+ }
126
+ return this.client.request(method, params, options);
127
+ }
128
+ /**
129
+ * Send a notification to the child process (no response expected)
130
+ */
131
+ async notify(method, params) {
132
+ if (!this.isReady()) {
133
+ throw new Error('Transport is not ready');
134
+ }
135
+ return this.client.notify(method, params);
136
+ }
137
+ /**
138
+ * Register a message handler for incoming messages
139
+ */
140
+ onMessage(handler) {
141
+ this.messageHandler = handler;
142
+ }
143
+ /**
144
+ * Register an event listener
145
+ */
146
+ on(event, handler) {
147
+ return super.on(event, handler);
148
+ }
149
+ /**
150
+ * Remove an event listener
151
+ */
152
+ off(event, handler) {
153
+ return super.off(event, handler);
154
+ }
155
+ /**
156
+ * Close the transport connection
157
+ */
158
+ async close() {
159
+ if (this._status === Transport_1.TransportStatus.disconnected) {
160
+ return;
161
+ }
162
+ this.setStatus(Transport_1.TransportStatus.disconnected);
163
+ // Close JSON-RPC client
164
+ await this.client.close();
165
+ // Close child process
166
+ if (this.childProcess && !this.childProcess.killed) {
167
+ this.childProcess.kill(constants_1.EXECUTION_CONSTANTS.processSignals.term);
168
+ // Wait for process to exit gracefully
169
+ await new Promise(resolve => {
170
+ const timeout = setTimeout(() => {
171
+ if (this.childProcess && !this.childProcess.killed) {
172
+ this.childProcess.kill('SIGKILL');
173
+ }
174
+ resolve();
175
+ }, 3000);
176
+ this.childProcess.on('exit', () => {
177
+ clearTimeout(timeout);
178
+ resolve();
179
+ });
180
+ });
181
+ }
182
+ this.childProcess = undefined;
183
+ }
184
+ /**
185
+ * Check if the transport is ready for communication
186
+ */
187
+ isReady() {
188
+ return this._status === Transport_1.TransportStatus.connected && this.childProcess !== undefined && !this.childProcess.killed;
189
+ }
190
+ /**
191
+ * Set up server methods for handling incoming requests from Deno process
192
+ */
193
+ setupServerMethods() {
194
+ // Handle status requests
195
+ this.server.registerMethod(types_1.STANDARD_METHODS.getStatus, async () => ({
196
+ status: 'ready',
197
+ uptime: process.uptime() * 1000,
198
+ memoryUsage: {
199
+ used: process.memoryUsage().heapUsed,
200
+ total: process.memoryUsage().heapTotal
201
+ }
202
+ }));
203
+ // Handle ping requests
204
+ this.server.registerMethod(types_1.STANDARD_METHODS.ping, async () => 'pong');
205
+ // Handle log notifications
206
+ this.server.registerMethod(types_1.STANDARD_METHODS.log, async (params) => {
207
+ if (this.messageHandler) {
208
+ await this.messageHandler(params);
209
+ }
210
+ });
211
+ }
212
+ /**
213
+ * Set up event handlers
214
+ */
215
+ setupEventHandlers() {
216
+ this.server.on('error', error => {
217
+ this.emit('error', error);
218
+ });
219
+ this.client.on('error', error => {
220
+ this.emit('error', error);
221
+ });
222
+ }
223
+ /**
224
+ * Set up process communication handlers
225
+ */
226
+ setupProcessCommunication() {
227
+ if (!this.childProcess) {
228
+ throw new Error('Child process not available');
229
+ }
230
+ let buffer = '';
231
+ // Handle stdout data (responses from Deno process)
232
+ this.childProcess.stdout?.on('data', (data) => {
233
+ buffer += data.toString();
234
+ // Process complete JSON messages
235
+ const lines = buffer.split('\n');
236
+ buffer = lines.pop() ?? ''; // Keep incomplete line in buffer
237
+ for (const line of lines) {
238
+ if (line.trim()) {
239
+ this.logger.log('Received message', line.trim());
240
+ this.handleIncomingMessage(line.trim()).catch(error => {
241
+ this.emit('error', error);
242
+ });
243
+ }
244
+ }
245
+ });
246
+ // Handle stderr data (errors from Deno process)
247
+ this.childProcess.stderr?.on('data', (data) => {
248
+ this.emit('error', new Error(`Deno process error: ${data.toString()}`));
249
+ });
250
+ // Handle process exit
251
+ this.childProcess.on('exit', (code, signal) => {
252
+ if (this._status === Transport_1.TransportStatus.connected) {
253
+ const error = new Error(`Process exited unexpectedly (code: ${code}, signal: ${signal})`);
254
+ this.setStatus(Transport_1.TransportStatus.error);
255
+ this.emit('error', error);
256
+ }
257
+ });
258
+ // Handle process errors
259
+ this.childProcess.on('error', error => {
260
+ this.setStatus(Transport_1.TransportStatus.error);
261
+ this.emit('error', new errors_1.ProcessSpawnError(error));
262
+ });
263
+ }
264
+ /**
265
+ * Handle incoming message from Deno process with bidirectional routing
266
+ */
267
+ async handleIncomingMessage(messageData) {
268
+ try {
269
+ const message = this.safeParse(messageData);
270
+ if (!message) {
271
+ return;
272
+ }
273
+ // Check if this is a response to our request (has 'result' or 'error' and 'id')
274
+ if (this.isResponse(message)) {
275
+ // This is a response to a request we made - route to client
276
+ this.logger.log('Routing response to parent client', { id: message.id });
277
+ await this.client.handleIncomingMessage(messageData);
278
+ }
279
+ else {
280
+ // This is a request or notification for us - route to server
281
+ this.logger.log('Routing request to parent server', { method: message.method, id: message.id });
282
+ const response = await this.server.processMessage(messageData);
283
+ this.logger.log('Sending response to parent process', response);
284
+ // Only send response if there is one (requests get responses, notifications don't)
285
+ if (response && this.childProcess?.stdin) {
286
+ const responseData = `${JSON.stringify(response)}\n`;
287
+ this.childProcess.stdin.write(responseData);
288
+ }
289
+ }
290
+ }
291
+ catch (error) {
292
+ this.emit('error', new Error(`Failed to handle incoming message: ${error.message}`));
293
+ }
294
+ }
295
+ safeParse(message) {
296
+ try {
297
+ return JSON.parse(message);
298
+ }
299
+ catch {
300
+ return undefined;
301
+ }
302
+ }
303
+ /**
304
+ * Check if a message is a JSON-RPC response
305
+ */
306
+ isResponse(message) {
307
+ return message &&
308
+ typeof message === 'object' &&
309
+ ('result' in message || 'error' in message) &&
310
+ 'id' in message &&
311
+ !('method' in message);
312
+ }
313
+ /**
314
+ * Wait for the process to be ready
315
+ */
316
+ async waitForReady(timeout) {
317
+ return new Promise((resolve, reject) => {
318
+ const timeoutId = setTimeout(() => {
319
+ reject(new Error(`Transport initialization timed out after ${timeout}ms`));
320
+ }, timeout);
321
+ // Try to ping the process to check if it's ready
322
+ const checkReady = async () => {
323
+ try {
324
+ await this.client.request(types_1.STANDARD_METHODS.ping, undefined, { timeout: 1000 });
325
+ clearTimeout(timeoutId);
326
+ resolve();
327
+ }
328
+ catch {
329
+ // Process not ready yet, try again
330
+ setTimeout(checkReady, 100);
331
+ }
332
+ };
333
+ // Start checking after a short delay to let process start
334
+ setTimeout(checkReady, 100);
335
+ });
336
+ }
337
+ /**
338
+ * Set transport status and emit event
339
+ */
340
+ setStatus(status) {
341
+ if (this._status !== status) {
342
+ this._status = status;
343
+ this.emit('statusChange', status);
344
+ }
345
+ }
346
+ }
347
+ exports.StdioTransport = StdioTransport;
348
+ /**
349
+ * Client transport implementation for stdio communication
350
+ */
351
+ class StdioClientTransport {
352
+ constructor() {
353
+ this.logger = logger_1.Logger.getInstance();
354
+ }
355
+ setProcess(stdout, stdin) {
356
+ this.stdout = stdout;
357
+ this.stdin = stdin;
358
+ }
359
+ setName(name) {
360
+ this.name = name;
361
+ this.logger.setMetadata({ name, transport: 'StdioClientTransport' });
362
+ }
363
+ async send(message) {
364
+ if (!this.stdin) {
365
+ throw new Error('Process stdin not available');
366
+ }
367
+ this.logger.log('Sending message', message);
368
+ this.stdin.write(`${message}\n`);
369
+ }
370
+ onMessage(handler) {
371
+ this.messageHandler = handler;
372
+ // Note: Message handling is done in the main StdioTransport class
373
+ // This is here for interface compliance
374
+ }
375
+ async close() {
376
+ this.stdout = undefined;
377
+ this.stdin = undefined;
378
+ this.messageHandler = undefined;
379
+ }
380
+ }
381
+ exports.StdioClientTransport = StdioClientTransport;
382
+ /**
383
+ * Bidirectional StdioTransport for child processes
384
+ * This class handles both server (receiving requests) and client (sending requests) functionality
385
+ * over a single stdio channel with proper message routing.
386
+ *
387
+ * Usage in child process:
388
+ * ```typescript
389
+ * const transport = new BidirectionalStdioTransport();
390
+ *
391
+ * // Register methods that parent can call
392
+ * transport.registerMethod('ping', async () => 'pong');
393
+ *
394
+ * // Make requests to parent
395
+ * const result = await transport.request('getTime');
396
+ * ```
397
+ */
398
+ class BidirectionalStdioTransport extends node_events_1.EventEmitter {
399
+ constructor() {
400
+ super();
401
+ this.logger = logger_1.Logger.getInstance();
402
+ this.buffer = '';
403
+ this.initialized = false;
404
+ this.server = new JsonRpcServer_1.JsonRpcServer();
405
+ this.client = new JsonRpcClient_1.JsonRpcClient();
406
+ // Set up the client transport that routes through our stdio
407
+ const clientTransport = {
408
+ send: async (message) => {
409
+ this.sendMessage(message);
410
+ },
411
+ onMessage() {
412
+ // The message routing will handle client responses automatically
413
+ },
414
+ async close() {
415
+ // Nothing to close for stdio
416
+ }
417
+ };
418
+ this.client.setTransport(clientTransport);
419
+ this.setupEventHandlers();
420
+ }
421
+ /**
422
+ * Set a name for this transport (used in logging)
423
+ */
424
+ setName(name) {
425
+ this.name = name;
426
+ this.logger.setMetadata({ name, transport: 'BidirectionalStdioTransport' });
427
+ }
428
+ /**
429
+ * Initialize the bidirectional transport
430
+ * This should be called once after setting up all methods
431
+ */
432
+ async initialize() {
433
+ if (this.initialized) {
434
+ throw new Error('Transport already initialized');
435
+ }
436
+ this.initialized = true;
437
+ this.setupStdioCommunication();
438
+ // Log to stderr to avoid contaminating stdout
439
+ this.logger.log('Transport initialized');
440
+ }
441
+ /**
442
+ * Register a method that the parent can call
443
+ * @param method - Method name
444
+ * @param handler - Method handler function
445
+ */
446
+ registerMethod(method, handler) {
447
+ this.server.registerMethod(method, handler);
448
+ }
449
+ /**
450
+ * Send a request to the parent process
451
+ * @param method - Method name
452
+ * @param params - Method parameters
453
+ * @param options - Request options
454
+ * @returns Promise resolving to the response
455
+ */
456
+ async request(method, params, options) {
457
+ if (!this.initialized) {
458
+ throw new Error('Transport not initialized. Call initialize() first.');
459
+ }
460
+ return this.client.request(method, params, options);
461
+ }
462
+ /**
463
+ * Send a notification to the parent process (no response expected)
464
+ * @param method - Method name
465
+ * @param params - Method parameters
466
+ */
467
+ async notify(method, params) {
468
+ if (!this.initialized) {
469
+ throw new Error('Transport not initialized. Call initialize() first.');
470
+ }
471
+ return this.client.notify(method, params);
472
+ }
473
+ /**
474
+ * Get transport statistics
475
+ */
476
+ getStats() {
477
+ return {
478
+ serverMethods: 0,
479
+ pendingRequests: this.client.getStats().pendingRequests,
480
+ initialized: this.initialized
481
+ };
482
+ }
483
+ /**
484
+ * Close the transport and cleanup resources
485
+ */
486
+ async close() {
487
+ await this.client.close();
488
+ this.initialized = false;
489
+ this.removeAllListeners();
490
+ }
491
+ /**
492
+ * Set up stdio communication handlers
493
+ */
494
+ setupStdioCommunication() {
495
+ // Handle incoming data from parent
496
+ process.stdin.on('data', async (data) => {
497
+ this.buffer += data.toString();
498
+ // Process complete JSON messages
499
+ const lines = this.buffer.split('\n');
500
+ this.buffer = lines.pop() ?? ''; // Keep incomplete line in buffer
501
+ for (const line of lines) {
502
+ if (line.trim()) {
503
+ await this.handleIncomingMessage(line.trim());
504
+ }
505
+ }
506
+ });
507
+ // Handle process termination gracefully
508
+ process.on('SIGTERM', () => {
509
+ this.close().finally(() => process.exit(0));
510
+ });
511
+ process.on('SIGINT', () => {
512
+ this.close().finally(() => process.exit(0));
513
+ });
514
+ }
515
+ /**
516
+ * Handle incoming message and route to appropriate handler
517
+ */
518
+ async handleIncomingMessage(messageData) {
519
+ try {
520
+ const message = this.safeParse(messageData);
521
+ if (!message) {
522
+ return;
523
+ }
524
+ // Check if this is a response to our request (has 'result' or 'error' and 'id')
525
+ if (this.isResponse(message)) {
526
+ // This is a response to a request we made - route to client
527
+ this.logger.log(`Routing response to client: ${message.id}`);
528
+ // Manually trigger client's handleIncomingMessage
529
+ await this.client.handleIncomingMessage(messageData);
530
+ }
531
+ else {
532
+ // This is a request or notification for us - route to server
533
+ this.logger.log(`Routing request to server: ${message.method}`);
534
+ const response = await this.server.processMessage(messageData);
535
+ this.logger.log('Sending response to parent process', response);
536
+ // Only send response if there is one (requests get responses, notifications don't)
537
+ if (response) {
538
+ this.sendMessage(JSON.stringify(response));
539
+ }
540
+ }
541
+ }
542
+ catch (error) {
543
+ process.stderr.write(`Error processing message: ${error.message}\n`);
544
+ this.emit('error', error);
545
+ }
546
+ }
547
+ safeParse(message) {
548
+ try {
549
+ return JSON.parse(message);
550
+ }
551
+ catch {
552
+ return undefined;
553
+ }
554
+ }
555
+ /**
556
+ * Check if a message is a JSON-RPC response
557
+ */
558
+ isResponse(message) {
559
+ return message &&
560
+ typeof message === 'object' &&
561
+ ('result' in message || 'error' in message) &&
562
+ 'id' in message &&
563
+ !('method' in message);
564
+ }
565
+ /**
566
+ * Send a message to the parent process
567
+ */
568
+ sendMessage(message) {
569
+ // Log to stderr to avoid contaminating stdout JSON-RPC channel
570
+ this.logger.log(`Sending: ${message}`);
571
+ process.stdout.write(`${message}\n`);
572
+ }
573
+ /**
574
+ * Set up event handlers
575
+ */
576
+ setupEventHandlers() {
577
+ this.server.on('error', (error) => {
578
+ this.logger.error('Server error', error);
579
+ this.emit('error', error);
580
+ });
581
+ this.client.on('error', (error) => {
582
+ this.logger.error('Client error', error);
583
+ this.emit('error', error);
584
+ });
585
+ }
586
+ }
587
+ exports.BidirectionalStdioTransport = BidirectionalStdioTransport;
588
+ class StdioServerTransport {
589
+ constructor(stdio, stdout, server) {
590
+ this.stdio = stdio;
591
+ this.stdout = stdout;
592
+ this.logger = logger_1.Logger.getInstance();
593
+ this.server = server;
594
+ }
595
+ setName(name) {
596
+ this.name = name;
597
+ this.logger.setMetadata({ name });
598
+ }
599
+ get status() {
600
+ return Transport_1.TransportStatus.connected;
601
+ }
602
+ isReady() {
603
+ return true;
604
+ }
605
+ async initialize() {
606
+ this.logger.log('Initializing transport');
607
+ this.stdio.on('data', async (data) => {
608
+ this.logger.log('Received message', data.toString());
609
+ const response = await this.server.processMessage(data.toString());
610
+ await this.send(JSON.stringify(response));
611
+ });
612
+ }
613
+ async send(message) {
614
+ this.logger.log('Sending message', message);
615
+ return new Promise(resolve => {
616
+ const json = JSON.stringify(message);
617
+ if (this.stdout.write(json)) {
618
+ resolve(undefined);
619
+ }
620
+ else {
621
+ this.stdout.once('drain', resolve);
622
+ }
623
+ });
624
+ }
625
+ onMessage() {
626
+ return void 0;
627
+ }
628
+ async close() {
629
+ this.logger.log('Closing transport');
630
+ this.stdio.destroy();
631
+ }
632
+ }
633
+ exports.StdioServerTransport = StdioServerTransport;
634
+ //# sourceMappingURL=StdioTransport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StdioTransport.js","sourceRoot":"","sources":["../../../src/JsExecutor/transport/StdioTransport.ts"],"names":[],"mappings":";;;AAQA,6CAA2C;AAE3C,yCAAsC;AACtC,4CAA8E;AAC9E,4CAAgD;AAChD,sCAA8C;AAE9C,4DAAyD;AACzD,4DAAyD;AAMzD,4CAE0B;AAC1B,4DAAsF;AAGtF,2CAA8C;AAE9C;;;GAGG;AACH,MAAa,cAAe,SAAQ,0BAAY;IAY9C,YAAmB,kBAA0B,EAAE,MAAqB;QAClE,KAAK,EAAE,CAAC;QAZF,YAAO,GAAoB,2BAAe,CAAC,YAAY,CAAC;QAS/C,WAAM,GAAG,eAAM,CAAC,WAAW,EAAE,CAAC;QAI7C,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC7C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,IAAI,6BAAa,EAAE,CAAC;QAClC,IAAI,CAAC,eAAe,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAElD,IAAI,CAA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