modality-kit 0.0.12 → 0.1.0
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 +33 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/util_error.d.ts +11 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -188,10 +188,42 @@ class ModalityLogger {
|
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
var loggerInstance = ModalityLogger.getInstance.bind(ModalityLogger);
|
|
191
|
+
// src/util_error.ts
|
|
192
|
+
var logger = loggerInstance("Error");
|
|
193
|
+
|
|
194
|
+
class ErrorCode extends Error {
|
|
195
|
+
constructor(message) {
|
|
196
|
+
super(message);
|
|
197
|
+
this.name = this.constructor.name;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function withErrorHandling(taskFn, operation) {
|
|
201
|
+
return async (...args) => {
|
|
202
|
+
try {
|
|
203
|
+
return await taskFn(...args);
|
|
204
|
+
} catch (error) {
|
|
205
|
+
if (error instanceof ErrorCode) {
|
|
206
|
+
logger.error(`${operation || "Task operation"} failed: ${error.code}`, {
|
|
207
|
+
message: error.message,
|
|
208
|
+
code: error.code
|
|
209
|
+
});
|
|
210
|
+
} else if (error instanceof Error) {
|
|
211
|
+
logger.error(`${operation || "Error"} failed`, {
|
|
212
|
+
message: error.message
|
|
213
|
+
});
|
|
214
|
+
} else {
|
|
215
|
+
logger.error(`${operation || "Exception"} unexpected error:`, error);
|
|
216
|
+
}
|
|
217
|
+
return formatErrorResponse(error, operation);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
191
221
|
export {
|
|
222
|
+
withErrorHandling,
|
|
192
223
|
setupAITools,
|
|
193
224
|
loggerInstance,
|
|
194
225
|
formatSuccessResponse,
|
|
195
226
|
formatErrorResponse,
|
|
196
|
-
ModalityLogger
|
|
227
|
+
ModalityLogger,
|
|
228
|
+
ErrorCode
|
|
197
229
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { setupAITools } from "./util_mcp_tools_converter";
|
|
|
2
2
|
export type { AITools, AITool } from "./schemas/schemas_tool_config";
|
|
3
3
|
export { formatErrorResponse, formatSuccessResponse } from "./util_response";
|
|
4
4
|
export { ModalityLogger, loggerInstance } from "./util_logger";
|
|
5
|
+
export { withErrorHandling, ErrorCode } from "./util_error";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for task-related errors
|
|
3
|
+
*/
|
|
4
|
+
export declare abstract class ErrorCode extends Error {
|
|
5
|
+
abstract readonly code: string;
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Wrapper for MCP task functions that adds consistent error handling
|
|
10
|
+
*/
|
|
11
|
+
export declare function withErrorHandling<T extends (...args: any[]) => Promise<string>>(taskFn: T, operation?: string): T;
|
package/package.json
CHANGED