modality-kit 0.14.5 → 0.14.7
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 +98 -74
- package/dist/types/ErrorCode.d.ts +8 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/jsonrpc-manager.d.ts +1 -1
- package/dist/types/schemas/schemas_symbol.d.ts +2 -2
- package/dist/types/util_error.d.ts +0 -8
- package/dist/types/util_response.d.ts +3 -11
- package/dist/types/util_text_compression.d.ts +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -16,6 +16,104 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
16
16
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
+
// src/ErrorCode.ts
|
|
20
|
+
class ErrorCode extends Error {
|
|
21
|
+
cause;
|
|
22
|
+
constructor(message, originalError) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = this.constructor.name;
|
|
25
|
+
if (originalError) {
|
|
26
|
+
this.cause = originalError;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/util_response.ts
|
|
32
|
+
var ContentType = [
|
|
33
|
+
"text",
|
|
34
|
+
"image",
|
|
35
|
+
"audio",
|
|
36
|
+
"resource_link",
|
|
37
|
+
"resource"
|
|
38
|
+
];
|
|
39
|
+
function formatSuccessResponse(successData, meta) {
|
|
40
|
+
const data = structuredClone(successData);
|
|
41
|
+
const { instructions, content: dataContent, ...restData } = data;
|
|
42
|
+
const result = {
|
|
43
|
+
isError: false,
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
type: "text",
|
|
47
|
+
text: JSON.stringify({
|
|
48
|
+
instructions,
|
|
49
|
+
meta,
|
|
50
|
+
...restData
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
};
|
|
55
|
+
if (Array.isArray(dataContent)) {
|
|
56
|
+
result.content.push(...dataContent.map((item) => {
|
|
57
|
+
if (typeof item === "string") {
|
|
58
|
+
return { type: "text", text: item };
|
|
59
|
+
} else if (item.type && ContentType.includes(item.type)) {
|
|
60
|
+
return item;
|
|
61
|
+
} else {
|
|
62
|
+
return { type: "text", text: JSON.stringify(item) };
|
|
63
|
+
}
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
function formatErrorResponse(errorData, operation, meta) {
|
|
69
|
+
let errorResponse;
|
|
70
|
+
let isError = true;
|
|
71
|
+
if (typeof errorData === "string") {
|
|
72
|
+
errorResponse = {
|
|
73
|
+
error: errorData,
|
|
74
|
+
operation,
|
|
75
|
+
meta
|
|
76
|
+
};
|
|
77
|
+
} else if (errorData instanceof ErrorCode) {
|
|
78
|
+
errorResponse = {
|
|
79
|
+
error: errorData.message,
|
|
80
|
+
operation,
|
|
81
|
+
meta,
|
|
82
|
+
code: errorData.code,
|
|
83
|
+
reason: errorData.cause?.message
|
|
84
|
+
};
|
|
85
|
+
} else if (errorData instanceof Error) {
|
|
86
|
+
errorResponse = {
|
|
87
|
+
error: errorData.message,
|
|
88
|
+
operation,
|
|
89
|
+
meta
|
|
90
|
+
};
|
|
91
|
+
} else if (typeof errorData === "object" && errorData !== null && typeof errorData.message === "string") {
|
|
92
|
+
const errObj = errorData;
|
|
93
|
+
isError = !errObj.success;
|
|
94
|
+
errorResponse = {
|
|
95
|
+
error: errObj.message,
|
|
96
|
+
code: errObj.code,
|
|
97
|
+
operation: errObj.operation || operation,
|
|
98
|
+
meta
|
|
99
|
+
};
|
|
100
|
+
} else {
|
|
101
|
+
errorResponse = {
|
|
102
|
+
error: "Unknown error",
|
|
103
|
+
operation,
|
|
104
|
+
meta
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
isError,
|
|
109
|
+
content: [
|
|
110
|
+
{
|
|
111
|
+
type: "text",
|
|
112
|
+
text: JSON.stringify(errorResponse)
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
};
|
|
116
|
+
}
|
|
19
117
|
// src/util_logger.ts
|
|
20
118
|
var levels = [null, "debug", "info", "warn", "error", "success"];
|
|
21
119
|
|
|
@@ -170,20 +268,8 @@ class ModalityLogger {
|
|
|
170
268
|
}
|
|
171
269
|
}
|
|
172
270
|
var getLoggerInstance = ModalityLogger.getInstance.bind(ModalityLogger);
|
|
173
|
-
|
|
174
271
|
// src/util_error.ts
|
|
175
272
|
var logger = getLoggerInstance("Safe to Handle");
|
|
176
|
-
|
|
177
|
-
class ErrorCode extends Error {
|
|
178
|
-
cause;
|
|
179
|
-
constructor(message, originalError) {
|
|
180
|
-
super(message);
|
|
181
|
-
this.name = this.constructor.name;
|
|
182
|
-
if (originalError) {
|
|
183
|
-
this.cause = originalError;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
273
|
function withErrorHandling(fn, operation) {
|
|
188
274
|
return async (...args) => {
|
|
189
275
|
try {
|
|
@@ -204,68 +290,6 @@ function withErrorHandling(fn, operation) {
|
|
|
204
290
|
}
|
|
205
291
|
};
|
|
206
292
|
}
|
|
207
|
-
|
|
208
|
-
// src/util_response.ts
|
|
209
|
-
function formatSuccessResponse(content, meta) {
|
|
210
|
-
let otherContent;
|
|
211
|
-
const instructions = content.instructions;
|
|
212
|
-
if (instructions != null) {
|
|
213
|
-
const { instructions: instructions2, ...restContent } = content;
|
|
214
|
-
otherContent = JSON.parse(JSON.stringify(restContent || {}));
|
|
215
|
-
} else {
|
|
216
|
-
otherContent = JSON.parse(JSON.stringify(content || {}));
|
|
217
|
-
}
|
|
218
|
-
return JSON.stringify({
|
|
219
|
-
success: true,
|
|
220
|
-
instructions,
|
|
221
|
-
content: Object.keys(otherContent || {}).length ? otherContent : undefined,
|
|
222
|
-
meta
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
function formatErrorResponse(errorData, operation, meta) {
|
|
226
|
-
let errorResponse;
|
|
227
|
-
if (typeof errorData === "string") {
|
|
228
|
-
errorResponse = {
|
|
229
|
-
success: false,
|
|
230
|
-
error: errorData,
|
|
231
|
-
operation,
|
|
232
|
-
meta
|
|
233
|
-
};
|
|
234
|
-
} else if (errorData instanceof ErrorCode) {
|
|
235
|
-
errorResponse = {
|
|
236
|
-
success: false,
|
|
237
|
-
error: errorData.message,
|
|
238
|
-
code: errorData.code,
|
|
239
|
-
reason: errorData.cause?.message,
|
|
240
|
-
operation,
|
|
241
|
-
meta
|
|
242
|
-
};
|
|
243
|
-
} else if (errorData instanceof Error) {
|
|
244
|
-
errorResponse = {
|
|
245
|
-
success: false,
|
|
246
|
-
error: errorData.message,
|
|
247
|
-
operation,
|
|
248
|
-
meta
|
|
249
|
-
};
|
|
250
|
-
} else if (typeof errorData === "object" && errorData !== null && typeof errorData.message === "string") {
|
|
251
|
-
const errObj = errorData;
|
|
252
|
-
errorResponse = {
|
|
253
|
-
success: errObj.success || false,
|
|
254
|
-
error: errObj.message,
|
|
255
|
-
code: errObj.code,
|
|
256
|
-
operation: errObj.operation || operation,
|
|
257
|
-
meta
|
|
258
|
-
};
|
|
259
|
-
} else {
|
|
260
|
-
errorResponse = {
|
|
261
|
-
success: false,
|
|
262
|
-
error: "Unknown error",
|
|
263
|
-
operation,
|
|
264
|
-
meta
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
return JSON.stringify(errorResponse);
|
|
268
|
-
}
|
|
269
293
|
// src/schemas/schemas_symbol.ts
|
|
270
294
|
var exports_schemas_symbol = {};
|
|
271
295
|
__export(exports_schemas_symbol, {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { formatErrorResponse, formatSuccessResponse } from "./util_response";
|
|
2
2
|
export { getLoggerInstance, type ModalityLogger } from "./util_logger";
|
|
3
|
-
export { withErrorHandling
|
|
3
|
+
export { withErrorHandling } from "./util_error";
|
|
4
|
+
export { ErrorCode } from "./ErrorCode";
|
|
4
5
|
export * as SymbolTypes from "./schemas/schemas_symbol";
|
|
5
6
|
export type { EmptyType } from "./schemas/schemas_empty";
|
|
6
7
|
export { emptySchema } from "./schemas/schemas_empty";
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Clean JSON-RPC 2.0 implementation for communication.
|
|
5
5
|
* Provides method registration, routing, and lifecycle management.
|
|
6
6
|
*/
|
|
7
|
-
import { ErrorCode } from "./
|
|
7
|
+
import { ErrorCode } from "./ErrorCode";
|
|
8
8
|
import { JSONRPCCall } from "./util_pending";
|
|
9
9
|
import { JSONRPCErrorCode } from "./schemas/jsonrpc";
|
|
10
10
|
import type { JSONRPCRequest, JSONRPCMessage, JSONRPCError, JSONRPCParams } from "./schemas/jsonrpc";
|
|
@@ -91,12 +91,12 @@ declare const fileEntrySchema: z.ZodObject<{
|
|
|
91
91
|
type: z.ZodEnum<["file", "directory"]>;
|
|
92
92
|
lastModified: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
|
|
93
93
|
}, "strip", z.ZodTypeAny, {
|
|
94
|
-
path: string;
|
|
95
94
|
type: "file" | "directory";
|
|
95
|
+
path: string;
|
|
96
96
|
lastModified?: number | null | undefined;
|
|
97
97
|
}, {
|
|
98
|
-
path: string;
|
|
99
98
|
type: "file" | "directory";
|
|
99
|
+
path: string;
|
|
100
100
|
lastModified?: number | null | undefined;
|
|
101
101
|
}>;
|
|
102
102
|
export type FileEntryType = z.infer<typeof fileEntrySchema>;
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base class for task-related errors
|
|
3
|
-
*/
|
|
4
|
-
export declare abstract class ErrorCode extends Error {
|
|
5
|
-
abstract readonly code: string | number;
|
|
6
|
-
cause?: Error;
|
|
7
|
-
constructor(message: string, originalError?: unknown);
|
|
8
|
-
}
|
|
9
1
|
/**
|
|
10
2
|
* Wrapper for any functions that adds consistent error handling
|
|
11
3
|
*/
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
1
2
|
/**
|
|
2
3
|
* Utility functions for formatting MCP responses
|
|
3
4
|
*
|
|
4
5
|
* This is a global utility module that should not import domain-specific classes.
|
|
5
6
|
* It provides generic response formatting for any MCP tool.
|
|
6
7
|
*/
|
|
7
|
-
export interface McpSuccessResponse {
|
|
8
|
-
success: true;
|
|
9
|
-
content: any;
|
|
10
|
-
meta?: any;
|
|
11
|
-
}
|
|
12
8
|
export interface McpErrorResponse {
|
|
13
|
-
success: boolean;
|
|
14
9
|
code?: string | number;
|
|
15
10
|
error: string;
|
|
16
11
|
operation?: string;
|
|
@@ -30,12 +25,9 @@ interface ErrorData extends Record<string, any> {
|
|
|
30
25
|
message: string;
|
|
31
26
|
operation?: string;
|
|
32
27
|
}
|
|
33
|
-
|
|
34
|
-
* Format a successful response for MCP tools
|
|
35
|
-
*/
|
|
36
|
-
export declare function formatSuccessResponse(content: SuccessData, meta?: any): string;
|
|
28
|
+
export declare function formatSuccessResponse(successData: SuccessData, meta?: any): CallToolResult;
|
|
37
29
|
/**
|
|
38
30
|
* Format an error response for MCP tools using generic error data
|
|
39
31
|
*/
|
|
40
|
-
export declare function formatErrorResponse(errorData: ErrorData | Error | string | unknown, operation?: string, meta?: Record<string, any>):
|
|
32
|
+
export declare function formatErrorResponse(errorData: ErrorData | Error | string | unknown, operation?: string, meta?: Record<string, any>): CallToolResult;
|
|
41
33
|
export {};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.14.
|
|
2
|
+
"version": "0.14.7",
|
|
3
3
|
"name": "modality-kit",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"author": "Hill <hill@kimo.com>",
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"devDependencies": {
|
|
14
|
+
"@modelcontextprotocol/sdk": "^1.24.2",
|
|
14
15
|
"@types/bun": "^1.2.23",
|
|
15
16
|
"typescript": "^5.9.2",
|
|
16
17
|
"zod": "^3.25.76"
|