modality-kit 0.12.13 → 0.12.15

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/dist/index.js CHANGED
@@ -5180,7 +5180,17 @@ class JSONRPCUtils {
5180
5180
  }
5181
5181
  static deserialize(data) {
5182
5182
  try {
5183
- return JSON.parse(data);
5183
+ let messageStr;
5184
+ if (typeof data !== "string") {
5185
+ if (Buffer.isBuffer(data)) {
5186
+ messageStr = data.toString();
5187
+ } else {
5188
+ return data;
5189
+ }
5190
+ } else {
5191
+ messageStr = data;
5192
+ }
5193
+ return JSON.parse(messageStr);
5184
5194
  } catch {
5185
5195
  return null;
5186
5196
  }
@@ -5489,6 +5499,10 @@ class ERROR_METHOD_NOT_FOUND extends ErrorCode {
5489
5499
  code = -32601 /* METHOD_NOT_FOUND */;
5490
5500
  }
5491
5501
 
5502
+ class ERROR_PARSE_ERROR extends ErrorCode {
5503
+ code = -32700 /* PARSE_ERROR */;
5504
+ }
5505
+
5492
5506
  class JSONRPCManager extends JSONRPCCall {
5493
5507
  methods = new Map;
5494
5508
  config;
@@ -5508,27 +5522,29 @@ class JSONRPCManager extends JSONRPCCall {
5508
5522
  try {
5509
5523
  switch (validation.messageType) {
5510
5524
  case "request":
5511
- return await this.processRequest(validation.message, options);
5525
+ return await this.processMethod(validation.message, options);
5512
5526
  case "notification":
5513
- return this.processNotification(validation.message, options);
5527
+ this.processNotification(validation.message, options);
5528
+ break;
5514
5529
  case "response":
5515
5530
  const response = validation.message;
5516
5531
  logger2.info("Received response message, handling internally", [
5517
5532
  response,
5518
5533
  response.id
5519
5534
  ]);
5520
- return this.handleResponse(response);
5535
+ this.handleResponse(response);
5536
+ break;
5521
5537
  case "batch":
5522
5538
  return await this.processBatchRequest(validation.message, options);
5523
5539
  default:
5524
5540
  return JSONRPCUtils.createErrorResponse(JSONRPCUtils.createError(-32600 /* INVALID_REQUEST */, "Unknown message type"), validation.message.id || null);
5525
5541
  }
5526
5542
  } catch (error) {
5527
- console.error("Error processing JSON-RPC message:", error);
5543
+ logger2.error("Error processing JSON-RPC message:", error);
5528
5544
  return JSONRPCUtils.createErrorResponse(this.config.errorHandler(error), validation.message.id || null);
5529
5545
  }
5530
5546
  }
5531
- async processRequest(request, options = {}) {
5547
+ async processMethod(request, options = {}) {
5532
5548
  const context = {
5533
5549
  ...options,
5534
5550
  request,
@@ -5548,7 +5564,7 @@ class JSONRPCManager extends JSONRPCCall {
5548
5564
  }
5549
5565
  return JSONRPCUtils.createSuccessResponse(result, request.id);
5550
5566
  } catch (error) {
5551
- console.error(`Error executing method '${request.method}':`, error);
5567
+ logger2.error(`Error executing method '${request.method}':`, error);
5552
5568
  const jsonrpcError = this.config.errorHandler(error, context);
5553
5569
  if (this.eventHandlers.onMethodError) {
5554
5570
  this.eventHandlers.onMethodError(request.method, jsonrpcError, context);
@@ -5565,15 +5581,14 @@ class JSONRPCManager extends JSONRPCCall {
5565
5581
  try {
5566
5582
  const methodConfig = this.methods.get(notification.method);
5567
5583
  if (!methodConfig) {
5568
- throw new ERROR_METHOD_NOT_FOUND(`Notification method '${notification.method}' not found`);
5584
+ throw new ERROR_METHOD_NOT_FOUND(`Notification method '${notification.method}' not handled.`);
5569
5585
  }
5570
5586
  if (this.eventHandlers.onMethodCall) {
5571
5587
  this.eventHandlers.onMethodCall(notification.method, notification.params, context);
5572
5588
  }
5573
5589
  return await methodConfig.handler(notification.params, context);
5574
5590
  } catch (error) {
5575
- console.error(`Error executing notification '${notification.method}':`, error);
5576
- throw error;
5591
+ logger2.info(`Notification get exception: '${notification.method}':`, error);
5577
5592
  }
5578
5593
  }
5579
5594
  async processBatchRequest(batchRequest, options = {}) {
@@ -5583,7 +5598,7 @@ class JSONRPCManager extends JSONRPCCall {
5583
5598
  }
5584
5599
  const promises = batchRequest.map((item) => {
5585
5600
  if (JSONRPCUtils.isRequest(item)) {
5586
- return this.processRequest(item, options);
5601
+ return this.processMethod(item, options);
5587
5602
  } else if (JSONRPCUtils.isNotification(item)) {
5588
5603
  return this.processNotification(item, options);
5589
5604
  }
@@ -5605,10 +5620,6 @@ class JSONRPCManager extends JSONRPCCall {
5605
5620
  errorType
5606
5621
  });
5607
5622
  }
5608
- sendMessage(message, options) {
5609
- console.warn("JSONRPCManager.sendMessage not implemented - message not sent:");
5610
- console.dir({ message, options }, { depth: null, color: true });
5611
- }
5612
5623
  sendNotification(method, params, options) {
5613
5624
  const notification = JSONRPCUtils.createNotification(method, params);
5614
5625
  return this.sendMessage(notification, options);
@@ -5622,7 +5633,7 @@ class JSONRPCManager extends JSONRPCCall {
5622
5633
  unregisterMethod(methodName) {
5623
5634
  const removed = this.methods.delete(methodName);
5624
5635
  if (removed) {
5625
- console.log(`Unregistered JSON-RPC method: ${methodName}`);
5636
+ logger2.info(`Unregistered JSON-RPC method: ${methodName}`);
5626
5637
  }
5627
5638
  return removed;
5628
5639
  }
@@ -5636,12 +5647,9 @@ class JSONRPCManager extends JSONRPCCall {
5636
5647
  }
5637
5648
  async validateMessage(data, options = {}) {
5638
5649
  try {
5639
- const messageStr = typeof data === "string" ? data : data.toString();
5640
- const message = JSONRPCUtils.deserialize(messageStr);
5650
+ const message = JSONRPCUtils.deserialize(data);
5641
5651
  if (!message) {
5642
- console.error("Failed to parse JSON-RPC message:", messageStr);
5643
- const errorResponse = JSONRPCUtils.createErrorResponse(JSONRPCUtils.createError(-32700 /* PARSE_ERROR */, "Parse error"), null);
5644
- return this.sendMessage(errorResponse, options);
5652
+ throw new ERROR_PARSE_ERROR("Failed to parse JSON-RPC message");
5645
5653
  }
5646
5654
  const validation = JSONRPCUtils.validateMessage(message);
5647
5655
  if (!validation.valid) {
@@ -5654,7 +5662,7 @@ class JSONRPCManager extends JSONRPCCall {
5654
5662
  }
5655
5663
  } catch (err) {
5656
5664
  const error = err;
5657
- console.error("Error handling validateMessage:", error);
5665
+ logger2.error("Error handling validateMessage:", error);
5658
5666
  const errorResponse = JSONRPCUtils.createErrorResponse(this.config.errorHandler(error), null);
5659
5667
  return this.sendMessage(errorResponse, options);
5660
5668
  }
@@ -70,5 +70,5 @@ export declare class JSONRPCUtils {
70
70
  /**
71
71
  * Deserialize a JSON-RPC message from string
72
72
  */
73
- static deserialize(data: string): JSONRPCMessage | null;
73
+ static deserialize(data: string | Buffer | Record<string, any>): JSONRPCMessage | null;
74
74
  }
@@ -57,7 +57,7 @@ export declare class ERROR_METHOD_NOT_FOUND extends ErrorCode {
57
57
  /**
58
58
  * Central JSON-RPC Manager class
59
59
  */
60
- export declare class JSONRPCManager<TContext> extends JSONRPCCall {
60
+ export declare abstract class JSONRPCManager<TContext> extends JSONRPCCall {
61
61
  private methods;
62
62
  private config;
63
63
  private eventHandlers;
@@ -69,7 +69,7 @@ export declare class JSONRPCManager<TContext> extends JSONRPCCall {
69
69
  /**
70
70
  * Process a JSON-RPC request
71
71
  */
72
- private processRequest;
72
+ private processMethod;
73
73
  /**
74
74
  * Process a JSON-RPC notification
75
75
  */
@@ -85,7 +85,7 @@ export declare class JSONRPCManager<TContext> extends JSONRPCCall {
85
85
  /**
86
86
  * Send a message (to be overridden by implementation)
87
87
  */
88
- protected sendMessage(message: JSONRPCMessage, options?: TContext): any;
88
+ protected abstract sendMessage(message: JSONRPCMessage, options?: TContext): any;
89
89
  /**
90
90
  * Send a JSON-RPC notification (no response expected)
91
91
  */
@@ -113,7 +113,7 @@ export declare class JSONRPCManager<TContext> extends JSONRPCCall {
113
113
  /**
114
114
  * Process incoming WebSocket message
115
115
  */
116
- validateMessage(data: string | Buffer, options?: any): Promise<void>;
116
+ validateMessage(data: string | Buffer | Record<string, any>, options?: any): Promise<void>;
117
117
  /**
118
118
  * Get manager statistics
119
119
  */
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.12.13",
2
+ "version": "0.12.15",
3
3
  "name": "modality-kit",
4
4
  "repository": {
5
5
  "type": "git",
@@ -28,7 +28,7 @@
28
28
  "build:clean": "find ./dist -name '*.*' | xargs rm -rf",
29
29
  "build:types": "bun tsc -p ./",
30
30
  "build:src": "bun build src/index.ts --outdir dist",
31
- "build": "bun run build:clean && bun run build:src && bun run build:types",
31
+ "build": "bun run build:clean && bun run build:types && bun run build:src",
32
32
  "dev": "bunx concurrently 'bun --watch tsc -p ./' 'bun build:src -- --watch --sourcemap=inline'",
33
33
  "test": "bun test",
34
34
  "prepublishOnly": "npm run build && npm run test"