modality-kit 0.14.5 → 0.14.6

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
@@ -16,6 +16,100 @@ 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
+ structuredContent: {
45
+ instructions,
46
+ meta,
47
+ ...restData
48
+ },
49
+ content: []
50
+ };
51
+ if (Array.isArray(dataContent)) {
52
+ result.content = dataContent.map((item) => {
53
+ if (typeof item === "string") {
54
+ return { type: "text", text: item };
55
+ } else if (item.type && ContentType.includes(item.type)) {
56
+ return item;
57
+ } else {
58
+ return { type: "text", text: JSON.stringify(item) };
59
+ }
60
+ });
61
+ }
62
+ return result;
63
+ }
64
+ function formatErrorResponse(errorData, operation, meta) {
65
+ let errorResponse;
66
+ let isError = true;
67
+ if (typeof errorData === "string") {
68
+ errorResponse = {
69
+ error: errorData,
70
+ operation,
71
+ meta
72
+ };
73
+ } else if (errorData instanceof ErrorCode) {
74
+ errorResponse = {
75
+ error: errorData.message,
76
+ operation,
77
+ meta,
78
+ code: errorData.code,
79
+ reason: errorData.cause?.message
80
+ };
81
+ } else if (errorData instanceof Error) {
82
+ errorResponse = {
83
+ error: errorData.message,
84
+ operation,
85
+ meta
86
+ };
87
+ } else if (typeof errorData === "object" && errorData !== null && typeof errorData.message === "string") {
88
+ const errObj = errorData;
89
+ isError = !errObj.success;
90
+ errorResponse = {
91
+ error: errObj.message,
92
+ code: errObj.code,
93
+ operation: errObj.operation || operation,
94
+ meta
95
+ };
96
+ } else {
97
+ errorResponse = {
98
+ error: "Unknown error",
99
+ operation,
100
+ meta
101
+ };
102
+ }
103
+ return {
104
+ isError,
105
+ content: [
106
+ {
107
+ type: "text",
108
+ text: JSON.stringify(errorResponse)
109
+ }
110
+ ]
111
+ };
112
+ }
19
113
  // src/util_logger.ts
20
114
  var levels = [null, "debug", "info", "warn", "error", "success"];
21
115
 
@@ -170,20 +264,8 @@ class ModalityLogger {
170
264
  }
171
265
  }
172
266
  var getLoggerInstance = ModalityLogger.getInstance.bind(ModalityLogger);
173
-
174
267
  // src/util_error.ts
175
268
  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
269
  function withErrorHandling(fn, operation) {
188
270
  return async (...args) => {
189
271
  try {
@@ -204,68 +286,6 @@ function withErrorHandling(fn, operation) {
204
286
  }
205
287
  };
206
288
  }
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
289
  // src/schemas/schemas_symbol.ts
270
290
  var exports_schemas_symbol = {};
271
291
  __export(exports_schemas_symbol, {
@@ -0,0 +1,8 @@
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
+ }
@@ -1,6 +1,7 @@
1
1
  export { formatErrorResponse, formatSuccessResponse } from "./util_response";
2
2
  export { getLoggerInstance, type ModalityLogger } from "./util_logger";
3
- export { withErrorHandling, ErrorCode } from "./util_error";
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 "./util_error";
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>): string;
32
+ export declare function formatErrorResponse(errorData: ErrorData | Error | string | unknown, operation?: string, meta?: Record<string, any>): CallToolResult;
41
33
  export {};
@@ -1,5 +1,5 @@
1
1
  import { ModalityLogger } from './util_logger.js';
2
- import { ErrorCode } from './util_error.js';
2
+ import { ErrorCode } from './ErrorCode';
3
3
  export interface CompressionConfig {
4
4
  maxTokens: number;
5
5
  compressionLevel: "light" | "moderate" | "aggressive";
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.14.5",
2
+ "version": "0.14.6",
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"