modality-kit 0.12.11 → 0.12.12
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
|
@@ -5485,6 +5485,10 @@ class JSONRPCCall {
|
|
|
5485
5485
|
// src/jsonrpc-manager.ts
|
|
5486
5486
|
var logger2 = getLoggerInstance("JSON-RPC-Manager");
|
|
5487
5487
|
|
|
5488
|
+
class ERROR_METHOD_NOT_FOUND extends ErrorCode {
|
|
5489
|
+
code = -32601 /* METHOD_NOT_FOUND */;
|
|
5490
|
+
}
|
|
5491
|
+
|
|
5488
5492
|
class JSONRPCManager extends JSONRPCCall {
|
|
5489
5493
|
methods = new Map;
|
|
5490
5494
|
config;
|
|
@@ -5506,16 +5510,14 @@ class JSONRPCManager extends JSONRPCCall {
|
|
|
5506
5510
|
case "request":
|
|
5507
5511
|
return await this.processRequest(validation.message, options);
|
|
5508
5512
|
case "notification":
|
|
5509
|
-
this.processNotification(validation.message, options);
|
|
5510
|
-
return;
|
|
5513
|
+
return this.processNotification(validation.message, options);
|
|
5511
5514
|
case "response":
|
|
5512
5515
|
const response = validation.message;
|
|
5513
5516
|
logger2.info("Received response message, handling internally", [
|
|
5514
5517
|
response,
|
|
5515
5518
|
response.id
|
|
5516
5519
|
]);
|
|
5517
|
-
this.handleResponse(response);
|
|
5518
|
-
return;
|
|
5520
|
+
return this.handleResponse(response);
|
|
5519
5521
|
case "batch":
|
|
5520
5522
|
return await this.processBatchRequest(validation.message, options);
|
|
5521
5523
|
default:
|
|
@@ -5535,11 +5537,7 @@ class JSONRPCManager extends JSONRPCCall {
|
|
|
5535
5537
|
try {
|
|
5536
5538
|
const methodConfig = this.methods.get(request.method);
|
|
5537
5539
|
if (!methodConfig) {
|
|
5538
|
-
|
|
5539
|
-
if (this.eventHandlers.onMethodError) {
|
|
5540
|
-
this.eventHandlers.onMethodError(request.method, error, context);
|
|
5541
|
-
}
|
|
5542
|
-
return JSONRPCUtils.createErrorResponse(error, request.id);
|
|
5540
|
+
throw new ERROR_METHOD_NOT_FOUND(`Method '${request.method}' not found`);
|
|
5543
5541
|
}
|
|
5544
5542
|
if (this.eventHandlers.onMethodCall) {
|
|
5545
5543
|
this.eventHandlers.onMethodCall(request.method, request.params, context);
|
|
@@ -5567,15 +5565,15 @@ class JSONRPCManager extends JSONRPCCall {
|
|
|
5567
5565
|
try {
|
|
5568
5566
|
const methodConfig = this.methods.get(notification.method);
|
|
5569
5567
|
if (!methodConfig) {
|
|
5570
|
-
|
|
5571
|
-
return;
|
|
5568
|
+
throw new ERROR_METHOD_NOT_FOUND(`Notification method '${notification.method}' not found`);
|
|
5572
5569
|
}
|
|
5573
5570
|
if (this.eventHandlers.onMethodCall) {
|
|
5574
5571
|
this.eventHandlers.onMethodCall(notification.method, notification.params, context);
|
|
5575
5572
|
}
|
|
5576
|
-
await methodConfig.handler(notification.params, context);
|
|
5573
|
+
return await methodConfig.handler(notification.params, context);
|
|
5577
5574
|
} catch (error) {
|
|
5578
5575
|
console.error(`Error executing notification '${notification.method}':`, error);
|
|
5576
|
+
throw error;
|
|
5579
5577
|
}
|
|
5580
5578
|
}
|
|
5581
5579
|
async processBatchRequest(batchRequest, options = {}) {
|
|
@@ -5601,7 +5599,7 @@ class JSONRPCManager extends JSONRPCCall {
|
|
|
5601
5599
|
if (error.message.includes("connection")) {
|
|
5602
5600
|
return JSONRPCUtils.createError(-32002 /* CONNECTION_ERROR */, STANDARD_ERROR_MESSAGES[-32002 /* CONNECTION_ERROR */]);
|
|
5603
5601
|
}
|
|
5604
|
-
return JSONRPCUtils.createError(-32603 /* INTERNAL_ERROR */, STANDARD_ERROR_MESSAGES[-32603 /* INTERNAL_ERROR */], { originalError: error.message });
|
|
5602
|
+
return JSONRPCUtils.createError(error?.code || -32603 /* INTERNAL_ERROR */, STANDARD_ERROR_MESSAGES[-32603 /* INTERNAL_ERROR */], { originalError: error.message });
|
|
5605
5603
|
}
|
|
5606
5604
|
sendMessage(message, options) {
|
|
5607
5605
|
console.warn("JSONRPCManager.sendMessage not implemented - message not sent:");
|
|
@@ -5609,14 +5607,13 @@ class JSONRPCManager extends JSONRPCCall {
|
|
|
5609
5607
|
}
|
|
5610
5608
|
sendNotification(method, params, options) {
|
|
5611
5609
|
const notification = JSONRPCUtils.createNotification(method, params);
|
|
5612
|
-
this.sendMessage(notification, options);
|
|
5610
|
+
return this.sendMessage(notification, options);
|
|
5613
5611
|
}
|
|
5614
5612
|
registerMethod(methodName, config) {
|
|
5615
5613
|
if (this.methods.has(methodName)) {
|
|
5616
5614
|
throw new Error(`Method '${methodName}' is already registered`);
|
|
5617
5615
|
}
|
|
5618
5616
|
this.methods.set(methodName, config);
|
|
5619
|
-
console.log(`Registered JSON-RPC method: ${methodName}`);
|
|
5620
5617
|
}
|
|
5621
5618
|
unregisterMethod(methodName) {
|
|
5622
5619
|
const removed = this.methods.delete(methodName);
|
|
@@ -5630,8 +5627,8 @@ class JSONRPCManager extends JSONRPCCall {
|
|
|
5630
5627
|
}
|
|
5631
5628
|
handleRequest(method, params, options = {}) {
|
|
5632
5629
|
const { promise, request } = super.handleRequest(method, params, options);
|
|
5633
|
-
this.sendMessage(request, options);
|
|
5634
|
-
return { promise, request };
|
|
5630
|
+
const result = this.sendMessage(request, options);
|
|
5631
|
+
return { promise, request, result };
|
|
5635
5632
|
}
|
|
5636
5633
|
async validateMessage(data, options = {}) {
|
|
5637
5634
|
try {
|
|
@@ -5640,24 +5637,22 @@ class JSONRPCManager extends JSONRPCCall {
|
|
|
5640
5637
|
if (!message) {
|
|
5641
5638
|
console.error("Failed to parse JSON-RPC message:", messageStr);
|
|
5642
5639
|
const errorResponse = JSONRPCUtils.createErrorResponse(JSONRPCUtils.createError(-32700 /* PARSE_ERROR */, "Parse error"), null);
|
|
5643
|
-
this.sendMessage(errorResponse, options);
|
|
5644
|
-
return;
|
|
5640
|
+
return this.sendMessage(errorResponse, options);
|
|
5645
5641
|
}
|
|
5646
5642
|
const validation = JSONRPCUtils.validateMessage(message);
|
|
5647
5643
|
if (!validation.valid) {
|
|
5648
5644
|
const errorResponse = JSONRPCUtils.createErrorResponse(validation.error, message.id || null);
|
|
5649
|
-
this.sendMessage(errorResponse, options);
|
|
5650
|
-
return;
|
|
5645
|
+
return this.sendMessage(errorResponse, options);
|
|
5651
5646
|
}
|
|
5652
5647
|
const response = await this.processMessage(validation, options);
|
|
5653
5648
|
if (response && (!Array.isArray(response) || response.length > 0)) {
|
|
5654
|
-
this.sendMessage(response, options);
|
|
5649
|
+
return this.sendMessage(response, options);
|
|
5655
5650
|
}
|
|
5656
5651
|
} catch (err) {
|
|
5657
5652
|
const error = err;
|
|
5658
5653
|
console.error("Error handling WebSocket message:", error);
|
|
5659
5654
|
const errorResponse = JSONRPCUtils.createErrorResponse(JSONRPCUtils.createError(-32603 /* INTERNAL_ERROR */, "Internal error"), null);
|
|
5660
|
-
this.sendMessage(errorResponse, options);
|
|
5655
|
+
return this.sendMessage(errorResponse, options);
|
|
5661
5656
|
}
|
|
5662
5657
|
}
|
|
5663
5658
|
getStats() {
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JSON-RPC Manager
|
|
3
|
-
*
|
|
4
|
-
* Clean JSON-RPC 2.0 implementation for WebSocket communication.
|
|
5
|
-
* Provides method registration, routing, and lifecycle management.
|
|
6
|
-
*/
|
|
7
1
|
import { JSONRPCCall } from "./util_pending";
|
|
8
2
|
import type { JSONRPCRequest, JSONRPCMessage, JSONRPCError, JSONRPCParams } from "./schemas/jsonrpc";
|
|
9
3
|
/**
|
|
@@ -78,9 +72,9 @@ export declare class JSONRPCManager<TContext> extends JSONRPCCall {
|
|
|
78
72
|
*/
|
|
79
73
|
private defaultErrorHandler;
|
|
80
74
|
/**
|
|
81
|
-
* Send a message (to be overridden by
|
|
75
|
+
* Send a message (to be overridden by implementation)
|
|
82
76
|
*/
|
|
83
|
-
protected sendMessage(message: JSONRPCMessage, options: TContext):
|
|
77
|
+
protected sendMessage(message: JSONRPCMessage, options: TContext): any;
|
|
84
78
|
/**
|
|
85
79
|
* Send a JSON-RPC notification (no response expected)
|
|
86
80
|
*/
|
|
@@ -103,6 +97,7 @@ export declare class JSONRPCManager<TContext> extends JSONRPCCall {
|
|
|
103
97
|
handleRequest(method: string, params?: any, options?: any): {
|
|
104
98
|
promise: Promise<any>;
|
|
105
99
|
request: JSONRPCRequest;
|
|
100
|
+
result: any;
|
|
106
101
|
};
|
|
107
102
|
/**
|
|
108
103
|
* Process incoming WebSocket message
|
|
@@ -62,24 +62,6 @@ export interface NotificationSendParams {
|
|
|
62
62
|
* JSON-RPC 2.0 version identifier
|
|
63
63
|
*/
|
|
64
64
|
export declare const JSONRPC_VERSION: "2.0";
|
|
65
|
-
/**
|
|
66
|
-
* Standard JSON-RPC 2.0 error codes as defined in the specification
|
|
67
|
-
*/
|
|
68
|
-
export declare enum JSONRPCErrorCode {
|
|
69
|
-
PARSE_ERROR = -32700,
|
|
70
|
-
INVALID_REQUEST = -32600,
|
|
71
|
-
METHOD_NOT_FOUND = -32601,
|
|
72
|
-
INVALID_PARAMS = -32602,
|
|
73
|
-
INTERNAL_ERROR = -32603,
|
|
74
|
-
SERVER_ERROR_START = -32099,
|
|
75
|
-
SERVER_ERROR_END = -32000,
|
|
76
|
-
TIMEOUT_ERROR = -32001,
|
|
77
|
-
CONNECTION_ERROR = -32002,
|
|
78
|
-
AUTHENTICATION_ERROR = -32003,
|
|
79
|
-
AUTHORIZATION_ERROR = -32004,
|
|
80
|
-
RATE_LIMIT_ERROR = -32005,
|
|
81
|
-
VALIDATION_ERROR = -32006
|
|
82
|
-
}
|
|
83
65
|
/**
|
|
84
66
|
* JSON-RPC 2.0 parameter types - can be object, array, or null
|
|
85
67
|
*
|
|
@@ -153,6 +135,24 @@ export interface JSONRPCValidationResult {
|
|
|
153
135
|
/** Parsed message type */
|
|
154
136
|
messageType?: "request" | "notification" | "response" | "batch";
|
|
155
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Standard JSON-RPC 2.0 error codes as defined in the specification
|
|
140
|
+
*/
|
|
141
|
+
export declare enum JSONRPCErrorCode {
|
|
142
|
+
PARSE_ERROR = -32700,
|
|
143
|
+
INVALID_REQUEST = -32600,
|
|
144
|
+
METHOD_NOT_FOUND = -32601,
|
|
145
|
+
INVALID_PARAMS = -32602,
|
|
146
|
+
INTERNAL_ERROR = -32603,
|
|
147
|
+
SERVER_ERROR_START = -32099,
|
|
148
|
+
SERVER_ERROR_END = -32000,
|
|
149
|
+
TIMEOUT_ERROR = -32001,
|
|
150
|
+
CONNECTION_ERROR = -32002,
|
|
151
|
+
AUTHENTICATION_ERROR = -32003,
|
|
152
|
+
AUTHORIZATION_ERROR = -32004,
|
|
153
|
+
RATE_LIMIT_ERROR = -32005,
|
|
154
|
+
VALIDATION_ERROR = -32006
|
|
155
|
+
}
|
|
156
156
|
/**
|
|
157
157
|
* Standard error messages for common JSON-RPC errors
|
|
158
158
|
*/
|
|
@@ -11,8 +11,8 @@ export interface McpSuccessResponse {
|
|
|
11
11
|
}
|
|
12
12
|
export interface McpErrorResponse {
|
|
13
13
|
success: boolean;
|
|
14
|
+
code?: string | number;
|
|
14
15
|
error: string;
|
|
15
|
-
code?: string;
|
|
16
16
|
operation?: string;
|
|
17
17
|
reason?: string;
|
|
18
18
|
meta?: Record<string, any>;
|
|
@@ -26,8 +26,8 @@ interface SuccessData extends Record<string, any> {
|
|
|
26
26
|
*/
|
|
27
27
|
interface ErrorData extends Record<string, any> {
|
|
28
28
|
success?: boolean;
|
|
29
|
+
code?: string | number;
|
|
29
30
|
message: string;
|
|
30
|
-
code?: string;
|
|
31
31
|
operation?: string;
|
|
32
32
|
}
|
|
33
33
|
/**
|
package/package.json
CHANGED