modality-kit 0.0.12 → 0.1.1
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
|
@@ -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(fn, operation) {
|
|
201
|
+
return async (...args) => {
|
|
202
|
+
try {
|
|
203
|
+
return await fn(...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";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* TypeScript interfaces for tool configuration objects
|
|
3
3
|
*/
|
|
4
|
+
export type AIToolExecutor = (...args: any[]) => Promise<string>;
|
|
4
5
|
/**
|
|
5
6
|
* Tool interface for AI SDK compatibility
|
|
6
7
|
*/
|
|
@@ -9,7 +10,7 @@ export interface AITool {
|
|
|
9
10
|
annotations?: any;
|
|
10
11
|
description: string;
|
|
11
12
|
parameters: any;
|
|
12
|
-
execute:
|
|
13
|
+
execute: AIToolExecutor;
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* Type for a collection of AI tools
|
|
@@ -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 any functions that adds consistent error handling
|
|
10
|
+
*/
|
|
11
|
+
export declare function withErrorHandling<T extends (...args: any[]) => Promise<any>>(fn: T, operation?: string): T;
|
package/package.json
CHANGED