modality-kit 0.0.11 → 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 +38 -5
- 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
|
@@ -117,6 +117,8 @@ class ModalityLogger {
|
|
|
117
117
|
if (categroy) {
|
|
118
118
|
prefix += ` [${categroy}]`;
|
|
119
119
|
}
|
|
120
|
+
console.log(`
|
|
121
|
+
`);
|
|
120
122
|
console.log(prefix);
|
|
121
123
|
return payload;
|
|
122
124
|
}
|
|
@@ -162,18 +164,17 @@ class ModalityLogger {
|
|
|
162
164
|
break;
|
|
163
165
|
}
|
|
164
166
|
console.log(`
|
|
165
|
-
|
|
166
167
|
`);
|
|
167
168
|
}
|
|
168
169
|
debug(message, error) {
|
|
169
170
|
this.log("debug", { message, error });
|
|
170
171
|
}
|
|
171
172
|
info(message, data) {
|
|
172
|
-
const
|
|
173
|
+
const payload = { message };
|
|
173
174
|
if (data) {
|
|
174
|
-
|
|
175
|
+
payload.data = data;
|
|
175
176
|
}
|
|
176
|
-
this.log("info",
|
|
177
|
+
this.log("info", payload);
|
|
177
178
|
}
|
|
178
179
|
warn(message, resolution) {
|
|
179
180
|
this.log("warn", { message, resolution });
|
|
@@ -187,10 +188,42 @@ class ModalityLogger {
|
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
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
|
+
}
|
|
190
221
|
export {
|
|
222
|
+
withErrorHandling,
|
|
191
223
|
setupAITools,
|
|
192
224
|
loggerInstance,
|
|
193
225
|
formatSuccessResponse,
|
|
194
226
|
formatErrorResponse,
|
|
195
|
-
ModalityLogger
|
|
227
|
+
ModalityLogger,
|
|
228
|
+
ErrorCode
|
|
196
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