modality-kit 0.0.2 → 0.0.3
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 +54 -50
- package/dist/types/index.d.ts +1 -1
- package/dist/types/util_logger.d.ts +14 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -56,12 +56,23 @@ function formatErrorResponse(errorData, operation, meta) {
|
|
|
56
56
|
}
|
|
57
57
|
// src/util_logger.ts
|
|
58
58
|
class ModalityLogger {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
static instance;
|
|
60
|
+
options = {};
|
|
61
|
+
logLevel = "info";
|
|
62
|
+
constructor(logOption, logLevel = "info") {
|
|
63
|
+
if (typeof logOption === "string") {
|
|
64
|
+
this.options.name = logOption;
|
|
65
|
+
} else {
|
|
66
|
+
this.options = { ...this.options, ...logOption };
|
|
67
|
+
}
|
|
63
68
|
this.logLevel = logLevel;
|
|
64
69
|
}
|
|
70
|
+
static getInstance(logOption, logLevel) {
|
|
71
|
+
if (!ModalityLogger.instance) {
|
|
72
|
+
ModalityLogger.instance = new ModalityLogger(logOption, logLevel);
|
|
73
|
+
}
|
|
74
|
+
return ModalityLogger.instance;
|
|
75
|
+
}
|
|
65
76
|
getTimestamp() {
|
|
66
77
|
if (this.options.timestampFormat === false)
|
|
67
78
|
return;
|
|
@@ -74,18 +85,11 @@ class ModalityLogger {
|
|
|
74
85
|
const levels = ["debug", "info", "warn", "error", "success"];
|
|
75
86
|
return levels.indexOf(level) >= levels.indexOf(this.logLevel);
|
|
76
87
|
}
|
|
77
|
-
|
|
88
|
+
setLogLevel(level) {
|
|
89
|
+
this.logLevel = level;
|
|
90
|
+
}
|
|
91
|
+
format(level, payload, categroy) {
|
|
78
92
|
const timestamp = this.getTimestamp();
|
|
79
|
-
const ctx = { ...this.options.context || {}, ...context };
|
|
80
|
-
const base = {
|
|
81
|
-
level,
|
|
82
|
-
message,
|
|
83
|
-
...timestamp ? { timestamp } : {},
|
|
84
|
-
...Object.keys(ctx).length ? { context: ctx } : {},
|
|
85
|
-
...extra ? { ...extra } : {}
|
|
86
|
-
};
|
|
87
|
-
if (this.options.json)
|
|
88
|
-
return JSON.stringify(base);
|
|
89
93
|
let prefix = "";
|
|
90
94
|
switch (level) {
|
|
91
95
|
case "debug":
|
|
@@ -106,66 +110,66 @@ class ModalityLogger {
|
|
|
106
110
|
default:
|
|
107
111
|
prefix = "";
|
|
108
112
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
withContext(context) {
|
|
117
|
-
return new ModalityLogger({ ...this.options, context: { ...this.options.context || {}, ...context } }, this.logLevel);
|
|
118
|
-
}
|
|
119
|
-
setLogLevel(level) {
|
|
120
|
-
this.logLevel = level;
|
|
121
|
-
}
|
|
122
|
-
setOptions(options) {
|
|
123
|
-
this.options = { ...this.options, ...options };
|
|
113
|
+
if (timestamp) {
|
|
114
|
+
prefix += ` [${timestamp}]`;
|
|
115
|
+
}
|
|
116
|
+
if (categroy) {
|
|
117
|
+
prefix += ` [${categroy}]`;
|
|
118
|
+
}
|
|
119
|
+
return [prefix, payload];
|
|
124
120
|
}
|
|
125
|
-
log(level,
|
|
121
|
+
log(level, payload, categroy) {
|
|
126
122
|
if (!this.shouldLog(level))
|
|
127
123
|
return;
|
|
128
|
-
const formatted = this.format(level,
|
|
124
|
+
const formatted = this.format(level, payload, categroy);
|
|
129
125
|
switch (level) {
|
|
130
126
|
case "debug":
|
|
131
|
-
|
|
127
|
+
console.debug(formatted);
|
|
132
128
|
break;
|
|
133
129
|
case "info":
|
|
134
|
-
|
|
130
|
+
console.info(formatted);
|
|
135
131
|
break;
|
|
136
132
|
case "warn":
|
|
137
|
-
|
|
133
|
+
console.warn(formatted);
|
|
138
134
|
break;
|
|
139
135
|
case "error":
|
|
140
|
-
|
|
136
|
+
console.error(formatted);
|
|
141
137
|
break;
|
|
142
138
|
case "success":
|
|
143
|
-
|
|
139
|
+
console.log(formatted);
|
|
144
140
|
break;
|
|
145
141
|
default:
|
|
146
|
-
|
|
142
|
+
console.log(formatted);
|
|
143
|
+
break;
|
|
147
144
|
}
|
|
148
145
|
}
|
|
149
|
-
debug(message,
|
|
150
|
-
|
|
151
|
-
this.log("debug", message, context, extra);
|
|
146
|
+
debug(message, error) {
|
|
147
|
+
this.log("debug", { message, error });
|
|
152
148
|
}
|
|
153
|
-
info(message,
|
|
154
|
-
this.log("info", message,
|
|
149
|
+
info(message, data) {
|
|
150
|
+
this.log("info", { message, data });
|
|
155
151
|
}
|
|
156
|
-
warn(message,
|
|
157
|
-
this.log("warn", message,
|
|
152
|
+
warn(message, resolution) {
|
|
153
|
+
this.log("warn", { message, resolution });
|
|
158
154
|
}
|
|
159
|
-
error(message,
|
|
160
|
-
const
|
|
161
|
-
|
|
155
|
+
error(message, error) {
|
|
156
|
+
const data = { message };
|
|
157
|
+
if (error) {
|
|
158
|
+
data.error = {
|
|
159
|
+
message: error.message,
|
|
160
|
+
stack: error.stack
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
this.log("error", data);
|
|
162
164
|
}
|
|
163
|
-
success(message,
|
|
164
|
-
this.log("success", message,
|
|
165
|
+
success(message, data) {
|
|
166
|
+
this.log("success", { message, data });
|
|
165
167
|
}
|
|
166
168
|
}
|
|
169
|
+
var loggerInstance = ModalityLogger.getInstance.bind(ModalityLogger);
|
|
167
170
|
export {
|
|
168
171
|
setupAITools,
|
|
172
|
+
loggerInstance,
|
|
169
173
|
formatSuccessResponse,
|
|
170
174
|
formatErrorResponse,
|
|
171
175
|
ModalityLogger
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
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
|
-
export { ModalityLogger } from "./util_logger";
|
|
4
|
+
export { ModalityLogger, loggerInstance } from "./util_logger";
|
|
@@ -2,27 +2,26 @@
|
|
|
2
2
|
* Storage Logger for structured logging
|
|
3
3
|
* Provides consistent logging across storage operations with configurable levels
|
|
4
4
|
*/
|
|
5
|
-
export type LogLevel =
|
|
5
|
+
export type LogLevel = "debug" | "info" | "warn" | "error" | "success";
|
|
6
6
|
export interface LoggerOptions {
|
|
7
|
-
timestampFormat?:
|
|
8
|
-
|
|
9
|
-
json?: boolean;
|
|
10
|
-
context?: Record<string, any>;
|
|
7
|
+
timestampFormat?: "iso" | "locale" | false;
|
|
8
|
+
name?: string;
|
|
11
9
|
}
|
|
12
10
|
export declare class ModalityLogger {
|
|
11
|
+
private static instance;
|
|
13
12
|
private options;
|
|
14
13
|
private logLevel;
|
|
15
|
-
constructor(
|
|
14
|
+
constructor(logOption: string | LoggerOptions, logLevel?: LogLevel);
|
|
15
|
+
static getInstance(logOption: string | LoggerOptions, logLevel?: LogLevel): ModalityLogger;
|
|
16
16
|
private getTimestamp;
|
|
17
17
|
private shouldLog;
|
|
18
|
-
private format;
|
|
19
|
-
withContext(context: Record<string, any>): ModalityLogger;
|
|
20
18
|
setLogLevel(level: LogLevel): void;
|
|
21
|
-
|
|
22
|
-
log(level: LogLevel,
|
|
23
|
-
debug(message: string,
|
|
24
|
-
info(message: string,
|
|
25
|
-
warn(message: string,
|
|
26
|
-
error(message: string,
|
|
27
|
-
success(message: string,
|
|
19
|
+
private format;
|
|
20
|
+
log(level: LogLevel, payload: any, categroy?: string): void;
|
|
21
|
+
debug(message: string, error?: Error): void;
|
|
22
|
+
info(message: string, data?: any): void;
|
|
23
|
+
warn(message: string, resolution: string): void;
|
|
24
|
+
error(message: string, error?: Error): void;
|
|
25
|
+
success(message: string, data?: any): void;
|
|
28
26
|
}
|
|
27
|
+
export declare const loggerInstance: typeof ModalityLogger.getInstance;
|
package/package.json
CHANGED