modality-kit 0.12.11 → 0.12.13
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,11 @@ 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
|
-
|
|
5602
|
+
const code = error?.code || -32603 /* INTERNAL_ERROR */;
|
|
5603
|
+
const errorType = STANDARD_ERROR_MESSAGES[code];
|
|
5604
|
+
return JSONRPCUtils.createError(code, error.message || errorType, {
|
|
5605
|
+
errorType
|
|
5606
|
+
});
|
|
5605
5607
|
}
|
|
5606
5608
|
sendMessage(message, options) {
|
|
5607
5609
|
console.warn("JSONRPCManager.sendMessage not implemented - message not sent:");
|
|
@@ -5609,14 +5611,13 @@ class JSONRPCManager extends JSONRPCCall {
|
|
|
5609
5611
|
}
|
|
5610
5612
|
sendNotification(method, params, options) {
|
|
5611
5613
|
const notification = JSONRPCUtils.createNotification(method, params);
|
|
5612
|
-
this.sendMessage(notification, options);
|
|
5614
|
+
return this.sendMessage(notification, options);
|
|
5613
5615
|
}
|
|
5614
5616
|
registerMethod(methodName, config) {
|
|
5615
5617
|
if (this.methods.has(methodName)) {
|
|
5616
5618
|
throw new Error(`Method '${methodName}' is already registered`);
|
|
5617
5619
|
}
|
|
5618
5620
|
this.methods.set(methodName, config);
|
|
5619
|
-
console.log(`Registered JSON-RPC method: ${methodName}`);
|
|
5620
5621
|
}
|
|
5621
5622
|
unregisterMethod(methodName) {
|
|
5622
5623
|
const removed = this.methods.delete(methodName);
|
|
@@ -5630,8 +5631,8 @@ class JSONRPCManager extends JSONRPCCall {
|
|
|
5630
5631
|
}
|
|
5631
5632
|
handleRequest(method, params, options = {}) {
|
|
5632
5633
|
const { promise, request } = super.handleRequest(method, params, options);
|
|
5633
|
-
this.sendMessage(request, options);
|
|
5634
|
-
return { promise, request };
|
|
5634
|
+
const result = this.sendMessage(request, options);
|
|
5635
|
+
return { promise, request, result };
|
|
5635
5636
|
}
|
|
5636
5637
|
async validateMessage(data, options = {}) {
|
|
5637
5638
|
try {
|
|
@@ -5640,24 +5641,22 @@ class JSONRPCManager extends JSONRPCCall {
|
|
|
5640
5641
|
if (!message) {
|
|
5641
5642
|
console.error("Failed to parse JSON-RPC message:", messageStr);
|
|
5642
5643
|
const errorResponse = JSONRPCUtils.createErrorResponse(JSONRPCUtils.createError(-32700 /* PARSE_ERROR */, "Parse error"), null);
|
|
5643
|
-
this.sendMessage(errorResponse, options);
|
|
5644
|
-
return;
|
|
5644
|
+
return this.sendMessage(errorResponse, options);
|
|
5645
5645
|
}
|
|
5646
5646
|
const validation = JSONRPCUtils.validateMessage(message);
|
|
5647
5647
|
if (!validation.valid) {
|
|
5648
5648
|
const errorResponse = JSONRPCUtils.createErrorResponse(validation.error, message.id || null);
|
|
5649
|
-
this.sendMessage(errorResponse, options);
|
|
5650
|
-
return;
|
|
5649
|
+
return this.sendMessage(errorResponse, options);
|
|
5651
5650
|
}
|
|
5652
5651
|
const response = await this.processMessage(validation, options);
|
|
5653
5652
|
if (response && (!Array.isArray(response) || response.length > 0)) {
|
|
5654
|
-
this.sendMessage(response, options);
|
|
5653
|
+
return this.sendMessage(response, options);
|
|
5655
5654
|
}
|
|
5656
5655
|
} catch (err) {
|
|
5657
5656
|
const error = err;
|
|
5658
|
-
console.error("Error handling
|
|
5659
|
-
const errorResponse = JSONRPCUtils.createErrorResponse(
|
|
5660
|
-
this.sendMessage(errorResponse, options);
|
|
5657
|
+
console.error("Error handling validateMessage:", error);
|
|
5658
|
+
const errorResponse = JSONRPCUtils.createErrorResponse(this.config.errorHandler(error), null);
|
|
5659
|
+
return this.sendMessage(errorResponse, options);
|
|
5661
5660
|
}
|
|
5662
5661
|
}
|
|
5663
5662
|
getStats() {
|
|
@@ -5961,5 +5960,6 @@ export {
|
|
|
5961
5960
|
JSONRPCManager,
|
|
5962
5961
|
JSONRPCErrorCode,
|
|
5963
5962
|
JSONRPCCall,
|
|
5964
|
-
ErrorCode
|
|
5963
|
+
ErrorCode,
|
|
5964
|
+
ERROR_METHOD_NOT_FOUND
|
|
5965
5965
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export { JSONRPCManager } from "./jsonrpc-manager";
|
|
|
18
18
|
export { JSONRPCErrorCode } from "./schemas/jsonrpc";
|
|
19
19
|
export type { JSONRPCManagerEvents, JSONRPCManagerConfig, } from "./jsonrpc-manager";
|
|
20
20
|
export type { JSONRPCMessage, JSONRPCRequest, JSONRPCNotification, JSONRPCResponse, JSONRPCBatchRequest, JSONRPCBatchResponse, JSONRPCErrorResponse, JSONRPCValidationResult, JSONRPCError, JSONRPCParams, CommandExecuteParams, NotificationSendParams, } from "./schemas/jsonrpc";
|
|
21
|
+
export { ERROR_METHOD_NOT_FOUND } from "./jsonrpc-manager";
|
|
21
22
|
/**
|
|
22
23
|
* For test tool
|
|
23
24
|
*/
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* JSON-RPC Manager
|
|
3
3
|
*
|
|
4
|
-
* Clean JSON-RPC 2.0 implementation for
|
|
4
|
+
* Clean JSON-RPC 2.0 implementation for communication.
|
|
5
5
|
* Provides method registration, routing, and lifecycle management.
|
|
6
6
|
*/
|
|
7
|
+
import { ErrorCode } from "./util_error";
|
|
7
8
|
import { JSONRPCCall } from "./util_pending";
|
|
9
|
+
import { JSONRPCErrorCode } from "./schemas/jsonrpc";
|
|
8
10
|
import type { JSONRPCRequest, JSONRPCMessage, JSONRPCError, JSONRPCParams } from "./schemas/jsonrpc";
|
|
9
11
|
/**
|
|
10
12
|
* Method handler function signature
|
|
@@ -49,6 +51,9 @@ export interface JSONRPCManagerEvents<TContext> {
|
|
|
49
51
|
onMethodResponse?: (method: string, result: any, context: TContext) => void;
|
|
50
52
|
onMethodError?: (method: string, error: JSONRPCError, context: TContext) => void;
|
|
51
53
|
}
|
|
54
|
+
export declare class ERROR_METHOD_NOT_FOUND extends ErrorCode {
|
|
55
|
+
readonly code = JSONRPCErrorCode.METHOD_NOT_FOUND;
|
|
56
|
+
}
|
|
52
57
|
/**
|
|
53
58
|
* Central JSON-RPC Manager class
|
|
54
59
|
*/
|
|
@@ -78,9 +83,9 @@ export declare class JSONRPCManager<TContext> extends JSONRPCCall {
|
|
|
78
83
|
*/
|
|
79
84
|
private defaultErrorHandler;
|
|
80
85
|
/**
|
|
81
|
-
* Send a message (to be overridden by
|
|
86
|
+
* Send a message (to be overridden by implementation)
|
|
82
87
|
*/
|
|
83
|
-
protected sendMessage(message: JSONRPCMessage, options
|
|
88
|
+
protected sendMessage(message: JSONRPCMessage, options?: TContext): any;
|
|
84
89
|
/**
|
|
85
90
|
* Send a JSON-RPC notification (no response expected)
|
|
86
91
|
*/
|
|
@@ -103,6 +108,7 @@ export declare class JSONRPCManager<TContext> extends JSONRPCCall {
|
|
|
103
108
|
handleRequest(method: string, params?: any, options?: any): {
|
|
104
109
|
promise: Promise<any>;
|
|
105
110
|
request: JSONRPCRequest;
|
|
111
|
+
result: any;
|
|
106
112
|
};
|
|
107
113
|
/**
|
|
108
114
|
* 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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.12.
|
|
2
|
+
"version": "0.12.13",
|
|
3
3
|
"name": "modality-kit",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"build:types": "bun tsc -p ./",
|
|
30
30
|
"build:src": "bun build src/index.ts --outdir dist",
|
|
31
31
|
"build": "bun run build:clean && bun run build:src && bun run build:types",
|
|
32
|
-
"dev": "bunx concurrently '
|
|
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"
|
|
35
35
|
},
|