modality-kit 0.9.0 → 0.9.2
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 +62 -58
- package/dist/types/jsonrpc-manager.d.ts +25 -25
- package/dist/types/websocket-client.d.ts +3 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5474,62 +5474,6 @@ class JSONRPCManager extends JSONRPCCall {
|
|
|
5474
5474
|
};
|
|
5475
5475
|
this.eventHandlers = eventHandlers;
|
|
5476
5476
|
}
|
|
5477
|
-
registerMethod(methodName, config) {
|
|
5478
|
-
if (this.methods.has(methodName)) {
|
|
5479
|
-
throw new Error(`Method '${methodName}' is already registered`);
|
|
5480
|
-
}
|
|
5481
|
-
this.methods.set(methodName, config);
|
|
5482
|
-
console.log(`Registered JSON-RPC method: ${methodName}`);
|
|
5483
|
-
}
|
|
5484
|
-
unregisterMethod(methodName) {
|
|
5485
|
-
const removed = this.methods.delete(methodName);
|
|
5486
|
-
if (removed) {
|
|
5487
|
-
console.log(`Unregistered JSON-RPC method: ${methodName}`);
|
|
5488
|
-
}
|
|
5489
|
-
return removed;
|
|
5490
|
-
}
|
|
5491
|
-
getRegisteredMethods() {
|
|
5492
|
-
return Array.from(this.methods.keys());
|
|
5493
|
-
}
|
|
5494
|
-
handleRequest(method, params, options = {}) {
|
|
5495
|
-
const { promise, request } = super.handleRequest(method, params, options);
|
|
5496
|
-
this.sendMessage(request, options);
|
|
5497
|
-
return { promise, request };
|
|
5498
|
-
}
|
|
5499
|
-
sendNotification(method, params, options) {
|
|
5500
|
-
const notification = JSONRPCUtils.createNotification(method, params);
|
|
5501
|
-
this.sendMessage(notification, options);
|
|
5502
|
-
}
|
|
5503
|
-
sendMessage(message, options) {
|
|
5504
|
-
console.warn("JSONRPCManager.sendMessage not implemented - message not sent:", message, options);
|
|
5505
|
-
}
|
|
5506
|
-
async validateMessage(data, options = {}) {
|
|
5507
|
-
try {
|
|
5508
|
-
const messageStr = typeof data === "string" ? data : data.toString();
|
|
5509
|
-
const message = JSONRPCUtils.deserialize(messageStr);
|
|
5510
|
-
if (!message) {
|
|
5511
|
-
console.error("Failed to parse JSON-RPC message:", messageStr);
|
|
5512
|
-
const errorResponse = JSONRPCUtils.createErrorResponse(JSONRPCUtils.createError(-32700 /* PARSE_ERROR */, "Parse error"), null);
|
|
5513
|
-
this.sendMessage(errorResponse, options);
|
|
5514
|
-
return;
|
|
5515
|
-
}
|
|
5516
|
-
const validation = JSONRPCUtils.validateMessage(message);
|
|
5517
|
-
if (!validation.valid) {
|
|
5518
|
-
const errorResponse = JSONRPCUtils.createErrorResponse(validation.error, message.id || null);
|
|
5519
|
-
this.sendMessage(errorResponse, options);
|
|
5520
|
-
return;
|
|
5521
|
-
}
|
|
5522
|
-
const response = await this.processMessage(validation, options);
|
|
5523
|
-
if (response && (!Array.isArray(response) || response.length > 0)) {
|
|
5524
|
-
this.sendMessage(response, options);
|
|
5525
|
-
}
|
|
5526
|
-
} catch (err) {
|
|
5527
|
-
const error = err;
|
|
5528
|
-
console.error("Error handling WebSocket message:", error);
|
|
5529
|
-
const errorResponse = JSONRPCUtils.createErrorResponse(JSONRPCUtils.createError(-32603 /* INTERNAL_ERROR */, "Internal error"), null);
|
|
5530
|
-
this.sendMessage(errorResponse, options);
|
|
5531
|
-
}
|
|
5532
|
-
}
|
|
5533
5477
|
async processMessage(validation, options = {}) {
|
|
5534
5478
|
try {
|
|
5535
5479
|
switch (validation.messageType) {
|
|
@@ -5633,6 +5577,62 @@ class JSONRPCManager extends JSONRPCCall {
|
|
|
5633
5577
|
}
|
|
5634
5578
|
return JSONRPCUtils.createError(-32603 /* INTERNAL_ERROR */, STANDARD_ERROR_MESSAGES[-32603 /* INTERNAL_ERROR */], { originalError: error.message });
|
|
5635
5579
|
}
|
|
5580
|
+
sendMessage(message, options) {
|
|
5581
|
+
console.warn("JSONRPCManager.sendMessage not implemented - message not sent:", message, options);
|
|
5582
|
+
}
|
|
5583
|
+
sendNotification(method, params, options) {
|
|
5584
|
+
const notification = JSONRPCUtils.createNotification(method, params);
|
|
5585
|
+
this.sendMessage(notification, options);
|
|
5586
|
+
}
|
|
5587
|
+
registerMethod(methodName, config) {
|
|
5588
|
+
if (this.methods.has(methodName)) {
|
|
5589
|
+
throw new Error(`Method '${methodName}' is already registered`);
|
|
5590
|
+
}
|
|
5591
|
+
this.methods.set(methodName, config);
|
|
5592
|
+
console.log(`Registered JSON-RPC method: ${methodName}`);
|
|
5593
|
+
}
|
|
5594
|
+
unregisterMethod(methodName) {
|
|
5595
|
+
const removed = this.methods.delete(methodName);
|
|
5596
|
+
if (removed) {
|
|
5597
|
+
console.log(`Unregistered JSON-RPC method: ${methodName}`);
|
|
5598
|
+
}
|
|
5599
|
+
return removed;
|
|
5600
|
+
}
|
|
5601
|
+
getRegisteredMethods() {
|
|
5602
|
+
return Array.from(this.methods.keys());
|
|
5603
|
+
}
|
|
5604
|
+
handleRequest(method, params, options = {}) {
|
|
5605
|
+
const { promise, request } = super.handleRequest(method, params, options);
|
|
5606
|
+
this.sendMessage(request, options);
|
|
5607
|
+
return { promise, request };
|
|
5608
|
+
}
|
|
5609
|
+
async validateMessage(data, options = {}) {
|
|
5610
|
+
try {
|
|
5611
|
+
const messageStr = typeof data === "string" ? data : data.toString();
|
|
5612
|
+
const message = JSONRPCUtils.deserialize(messageStr);
|
|
5613
|
+
if (!message) {
|
|
5614
|
+
console.error("Failed to parse JSON-RPC message:", messageStr);
|
|
5615
|
+
const errorResponse = JSONRPCUtils.createErrorResponse(JSONRPCUtils.createError(-32700 /* PARSE_ERROR */, "Parse error"), null);
|
|
5616
|
+
this.sendMessage(errorResponse, options);
|
|
5617
|
+
return;
|
|
5618
|
+
}
|
|
5619
|
+
const validation = JSONRPCUtils.validateMessage(message);
|
|
5620
|
+
if (!validation.valid) {
|
|
5621
|
+
const errorResponse = JSONRPCUtils.createErrorResponse(validation.error, message.id || null);
|
|
5622
|
+
this.sendMessage(errorResponse, options);
|
|
5623
|
+
return;
|
|
5624
|
+
}
|
|
5625
|
+
const response = await this.processMessage(validation, options);
|
|
5626
|
+
if (response && (!Array.isArray(response) || response.length > 0)) {
|
|
5627
|
+
this.sendMessage(response, options);
|
|
5628
|
+
}
|
|
5629
|
+
} catch (err) {
|
|
5630
|
+
const error = err;
|
|
5631
|
+
console.error("Error handling WebSocket message:", error);
|
|
5632
|
+
const errorResponse = JSONRPCUtils.createErrorResponse(JSONRPCUtils.createError(-32603 /* INTERNAL_ERROR */, "Internal error"), null);
|
|
5633
|
+
this.sendMessage(errorResponse, options);
|
|
5634
|
+
}
|
|
5635
|
+
}
|
|
5636
5636
|
getStats() {
|
|
5637
5637
|
const parentStats = super.getStats();
|
|
5638
5638
|
return {
|
|
@@ -5656,7 +5656,7 @@ class WebSocketClient {
|
|
|
5656
5656
|
initialReconnectDelay: 1000,
|
|
5657
5657
|
maxReconnectDelay: 30000,
|
|
5658
5658
|
maxReconnectAttempts: 10,
|
|
5659
|
-
|
|
5659
|
+
lastReconnectDelay: 300000,
|
|
5660
5660
|
heartbeatInterval: 30000,
|
|
5661
5661
|
enableKeepAlive: true,
|
|
5662
5662
|
handleMessage: (_validMessage, _ws) => {}
|
|
@@ -5674,6 +5674,7 @@ class WebSocketClient {
|
|
|
5674
5674
|
this.config = { ...this.config, ...config };
|
|
5675
5675
|
this.url = url;
|
|
5676
5676
|
this.reconnectDelay = this.config.initialReconnectDelay;
|
|
5677
|
+
this.send = this.send.bind(this);
|
|
5677
5678
|
}
|
|
5678
5679
|
isValidWebSocketUrl(url) {
|
|
5679
5680
|
try {
|
|
@@ -5720,7 +5721,7 @@ class WebSocketClient {
|
|
|
5720
5721
|
this.reconnectAttempts = 0;
|
|
5721
5722
|
this.reconnectDelay = this.config.initialReconnectDelay;
|
|
5722
5723
|
this.attemptReconnect();
|
|
5723
|
-
},
|
|
5724
|
+
}, this.config.lastReconnectDelay);
|
|
5724
5725
|
}
|
|
5725
5726
|
}
|
|
5726
5727
|
onOpen(event) {
|
|
@@ -5811,6 +5812,9 @@ class WebSocketClient {
|
|
|
5811
5812
|
}
|
|
5812
5813
|
};
|
|
5813
5814
|
this.ws.onmessage = (event) => {
|
|
5815
|
+
if (this.config.onReceiveMessage) {
|
|
5816
|
+
event = this.config.onReceiveMessage(event);
|
|
5817
|
+
}
|
|
5814
5818
|
logger3.info("WebSocket message received:", event.data);
|
|
5815
5819
|
try {
|
|
5816
5820
|
const message = JSONRPCUtils.deserialize(event.data);
|
|
@@ -58,56 +58,56 @@ export declare class JSONRPCManager<TContext> extends JSONRPCCall {
|
|
|
58
58
|
private eventHandlers;
|
|
59
59
|
constructor(config?: JSONRPCManagerConfig<TContext>, eventHandlers?: JSONRPCManagerEvents<TContext>);
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
61
|
+
* Process incoming JSON-RPC message (supports batch requests)
|
|
62
62
|
*/
|
|
63
|
-
|
|
63
|
+
private processMessage;
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
65
|
+
* Process a JSON-RPC request
|
|
66
66
|
*/
|
|
67
|
-
|
|
67
|
+
private processRequest;
|
|
68
68
|
/**
|
|
69
|
-
*
|
|
69
|
+
* Process a JSON-RPC notification
|
|
70
70
|
*/
|
|
71
|
-
|
|
71
|
+
private processNotification;
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
73
|
+
* Process a JSON-RPC batch request
|
|
74
74
|
*/
|
|
75
|
-
|
|
76
|
-
promise: Promise<any>;
|
|
77
|
-
request: JSONRPCRequest;
|
|
78
|
-
};
|
|
75
|
+
private processBatchRequest;
|
|
79
76
|
/**
|
|
80
|
-
*
|
|
77
|
+
* Default error handler
|
|
81
78
|
*/
|
|
82
|
-
|
|
79
|
+
private defaultErrorHandler;
|
|
83
80
|
/**
|
|
84
81
|
* Send a message (to be overridden by WebSocket implementation)
|
|
85
82
|
*/
|
|
86
83
|
protected sendMessage(message: JSONRPCMessage, options: TContext): void;
|
|
87
84
|
/**
|
|
88
|
-
*
|
|
85
|
+
* Send a JSON-RPC notification (no response expected)
|
|
89
86
|
*/
|
|
90
|
-
|
|
87
|
+
sendNotification(method: string, params: any, options: TContext): void;
|
|
91
88
|
/**
|
|
92
|
-
*
|
|
89
|
+
* Register a JSON-RPC method
|
|
93
90
|
*/
|
|
94
|
-
|
|
91
|
+
registerMethod<T = JSONRPCParams>(methodName: string, config: JSONRPCMethodConfig<TContext, T>): void;
|
|
95
92
|
/**
|
|
96
|
-
*
|
|
93
|
+
* Unregister a JSON-RPC method
|
|
97
94
|
*/
|
|
98
|
-
|
|
95
|
+
unregisterMethod(methodName: string): boolean;
|
|
99
96
|
/**
|
|
100
|
-
*
|
|
97
|
+
* Get registered method names
|
|
101
98
|
*/
|
|
102
|
-
|
|
99
|
+
getRegisteredMethods(): string[];
|
|
103
100
|
/**
|
|
104
|
-
*
|
|
101
|
+
* Send a JSON-RPC request and return a promise for the response
|
|
105
102
|
*/
|
|
106
|
-
|
|
103
|
+
handleRequest(method: string, params?: any, options?: any): {
|
|
104
|
+
promise: Promise<any>;
|
|
105
|
+
request: JSONRPCRequest;
|
|
106
|
+
};
|
|
107
107
|
/**
|
|
108
|
-
*
|
|
108
|
+
* Process incoming WebSocket message
|
|
109
109
|
*/
|
|
110
|
-
|
|
110
|
+
validateMessage(data: string | Buffer, options?: any): Promise<void>;
|
|
111
111
|
/**
|
|
112
112
|
* Get manager statistics
|
|
113
113
|
*/
|
|
@@ -3,10 +3,11 @@ interface WebSocketConfig {
|
|
|
3
3
|
maxReconnectAttempts: number;
|
|
4
4
|
initialReconnectDelay: number;
|
|
5
5
|
maxReconnectDelay: number;
|
|
6
|
-
|
|
6
|
+
lastReconnectDelay: number;
|
|
7
7
|
heartbeatInterval: number;
|
|
8
8
|
enableKeepAlive: boolean;
|
|
9
9
|
handleMessage: (validMessage: JSONRPCValidationResult, ws: WebSocketClient) => void;
|
|
10
|
+
onReceiveMessage?: (event: any) => any;
|
|
10
11
|
}
|
|
11
12
|
interface WebSocketInfo {
|
|
12
13
|
url: string;
|
|
@@ -25,7 +26,7 @@ export declare class WebSocketClient {
|
|
|
25
26
|
private reconnectAttempts;
|
|
26
27
|
private reconnectDelay;
|
|
27
28
|
private heartbeatInterval;
|
|
28
|
-
constructor(url: string, config?:
|
|
29
|
+
constructor(url: string, config?: Partial<WebSocketConfig>);
|
|
29
30
|
private isValidWebSocketUrl;
|
|
30
31
|
private stopCleanupInterval;
|
|
31
32
|
private stopHeartbeat;
|
package/package.json
CHANGED