mcp-server-rocketchat-threads 1.0.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/LICENSE +21 -0
- package/README.md +332 -0
- package/dist/api/client.d.ts +119 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +305 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/index.d.ts +6 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +22 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/schemas.d.ts +10636 -0
- package/dist/api/schemas.d.ts.map +1 -0
- package/dist/api/schemas.js +267 -0
- package/dist/api/schemas.js.map +1 -0
- package/dist/api/types.d.ts +263 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +7 -0
- package/dist/api/types.js.map +1 -0
- package/dist/config/config.d.ts +37 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +79 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +21 -0
- package/dist/config/index.js.map +1 -0
- package/dist/di/container.d.ts +101 -0
- package/dist/di/container.d.ts.map +1 -0
- package/dist/di/container.js +214 -0
- package/dist/di/container.js.map +1 -0
- package/dist/di/index.d.ts +6 -0
- package/dist/di/index.d.ts.map +1 -0
- package/dist/di/index.js +12 -0
- package/dist/di/index.js.map +1 -0
- package/dist/formatters/index.d.ts +6 -0
- package/dist/formatters/index.d.ts.map +1 -0
- package/dist/formatters/index.js +22 -0
- package/dist/formatters/index.js.map +1 -0
- package/dist/formatters/message-formatter.d.ts +64 -0
- package/dist/formatters/message-formatter.d.ts.map +1 -0
- package/dist/formatters/message-formatter.js +161 -0
- package/dist/formatters/message-formatter.js.map +1 -0
- package/dist/formatters/response-builder.d.ts +60 -0
- package/dist/formatters/response-builder.d.ts.map +1 -0
- package/dist/formatters/response-builder.js +108 -0
- package/dist/formatters/response-builder.js.map +1 -0
- package/dist/guards/index.d.ts +12 -0
- package/dist/guards/index.d.ts.map +1 -0
- package/dist/guards/index.js +42 -0
- package/dist/guards/index.js.map +1 -0
- package/dist/guards/input-validator.d.ts +89 -0
- package/dist/guards/input-validator.d.ts.map +1 -0
- package/dist/guards/input-validator.js +266 -0
- package/dist/guards/input-validator.js.map +1 -0
- package/dist/guards/rate-limiter.d.ts +115 -0
- package/dist/guards/rate-limiter.d.ts.map +1 -0
- package/dist/guards/rate-limiter.js +226 -0
- package/dist/guards/rate-limiter.js.map +1 -0
- package/dist/guards/sanitizer.d.ts +35 -0
- package/dist/guards/sanitizer.d.ts.map +1 -0
- package/dist/guards/sanitizer.js +111 -0
- package/dist/guards/sanitizer.js.map +1 -0
- package/dist/guards/write-guard.d.ts +33 -0
- package/dist/guards/write-guard.d.ts.map +1 -0
- package/dist/guards/write-guard.js +90 -0
- package/dist/guards/write-guard.js.map +1 -0
- package/dist/http-server.d.ts +9 -0
- package/dist/http-server.d.ts.map +1 -0
- package/dist/http-server.js +190 -0
- package/dist/http-server.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +114 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/base.d.ts +85 -0
- package/dist/tools/base.d.ts.map +1 -0
- package/dist/tools/base.js +184 -0
- package/dist/tools/base.js.map +1 -0
- package/dist/tools/channel-tools.d.ts +18 -0
- package/dist/tools/channel-tools.d.ts.map +1 -0
- package/dist/tools/channel-tools.js +151 -0
- package/dist/tools/channel-tools.js.map +1 -0
- package/dist/tools/handler-utils.d.ts +75 -0
- package/dist/tools/handler-utils.d.ts.map +1 -0
- package/dist/tools/handler-utils.js +105 -0
- package/dist/tools/handler-utils.js.map +1 -0
- package/dist/tools/index.d.ts +17 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +40 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/message-tools.d.ts +20 -0
- package/dist/tools/message-tools.d.ts.map +1 -0
- package/dist/tools/message-tools.js +194 -0
- package/dist/tools/message-tools.js.map +1 -0
- package/dist/tools/thread-tools.d.ts +23 -0
- package/dist/tools/thread-tools.d.ts.map +1 -0
- package/dist/tools/thread-tools.js +243 -0
- package/dist/tools/thread-tools.js.map +1 -0
- package/dist/tools/user-tools.d.ts +14 -0
- package/dist/tools/user-tools.d.ts.map +1 -0
- package/dist/tools/user-tools.js +120 -0
- package/dist/tools/user-tools.js.map +1 -0
- package/dist/tools/write-tools.d.ts +15 -0
- package/dist/tools/write-tools.d.ts.map +1 -0
- package/dist/tools/write-tools.js +181 -0
- package/dist/tools/write-tools.js.map +1 -0
- package/dist/utils/cache.d.ts +47 -0
- package/dist/utils/cache.d.ts.map +1 -0
- package/dist/utils/cache.js +116 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/error-handler.d.ts +64 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +148 -0
- package/dist/utils/error-handler.js.map +1 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +33 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +50 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +118 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/time-parser.d.ts +37 -0
- package/dist/utils/time-parser.d.ts.map +1 -0
- package/dist/utils/time-parser.js +98 -0
- package/dist/utils/time-parser.js.map +1 -0
- package/dist/utils/token-counter.d.ts +42 -0
- package/dist/utils/token-counter.d.ts.map +1 -0
- package/dist/utils/token-counter.js +81 -0
- package/dist/utils/token-counter.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Centralized Error Handling Utilities
|
|
4
|
+
* Provides consistent error handling across all MCP tools
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ErrorSuggestions = exports.ErrorCodes = void 0;
|
|
8
|
+
exports.extractErrorMessage = extractErrorMessage;
|
|
9
|
+
exports.extractErrorDetails = extractErrorDetails;
|
|
10
|
+
exports.createErrorInfo = createErrorInfo;
|
|
11
|
+
exports.httpStatusToErrorCode = httpStatusToErrorCode;
|
|
12
|
+
exports.withErrorHandling = withErrorHandling;
|
|
13
|
+
exports.isErrorInfo = isErrorInfo;
|
|
14
|
+
exports.enrichErrorInfo = enrichErrorInfo;
|
|
15
|
+
const client_js_1 = require("../api/client.js");
|
|
16
|
+
/**
|
|
17
|
+
* Error codes used across the MCP server
|
|
18
|
+
*/
|
|
19
|
+
exports.ErrorCodes = {
|
|
20
|
+
API_ERROR: 'API_ERROR',
|
|
21
|
+
VALIDATION_ERROR: 'VALIDATION_ERROR',
|
|
22
|
+
NOT_FOUND: 'NOT_FOUND',
|
|
23
|
+
PERMISSION_DENIED: 'PERMISSION_DENIED',
|
|
24
|
+
RATE_LIMITED: 'RATE_LIMITED',
|
|
25
|
+
WRITE_DISABLED: 'WRITE_DISABLED',
|
|
26
|
+
ROOM_NOT_ALLOWED: 'ROOM_NOT_ALLOWED',
|
|
27
|
+
UNKNOWN_ERROR: 'UNKNOWN_ERROR'
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Extract a meaningful error message from any error type
|
|
31
|
+
*/
|
|
32
|
+
function extractErrorMessage(error) {
|
|
33
|
+
if (error instanceof client_js_1.RocketChatApiError) {
|
|
34
|
+
return `${error.message} (Status: ${error.statusCode})`;
|
|
35
|
+
}
|
|
36
|
+
if (error instanceof Error) {
|
|
37
|
+
return error.message;
|
|
38
|
+
}
|
|
39
|
+
if (typeof error === 'string') {
|
|
40
|
+
return error;
|
|
41
|
+
}
|
|
42
|
+
return 'Unknown error occurred';
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Extract error details (stack trace or additional info)
|
|
46
|
+
*/
|
|
47
|
+
function extractErrorDetails(error) {
|
|
48
|
+
if (error instanceof client_js_1.RocketChatApiError) {
|
|
49
|
+
try {
|
|
50
|
+
const body = JSON.parse(error.responseBody);
|
|
51
|
+
return body.error || body.message || error.responseBody;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return error.responseBody;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (error instanceof Error && error.stack) {
|
|
58
|
+
// Only include stack in development
|
|
59
|
+
if (process.env.DEBUG === 'true') {
|
|
60
|
+
return error.stack;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create an error info object from any error
|
|
67
|
+
*/
|
|
68
|
+
function createErrorInfo(code, defaultMessage, error) {
|
|
69
|
+
const message = error ? extractErrorMessage(error) : defaultMessage;
|
|
70
|
+
const details = error ? extractErrorDetails(error) : undefined;
|
|
71
|
+
return {
|
|
72
|
+
code,
|
|
73
|
+
message,
|
|
74
|
+
details
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Map HTTP status codes to error codes
|
|
79
|
+
*/
|
|
80
|
+
function httpStatusToErrorCode(status) {
|
|
81
|
+
switch (status) {
|
|
82
|
+
case 400:
|
|
83
|
+
return exports.ErrorCodes.VALIDATION_ERROR;
|
|
84
|
+
case 401:
|
|
85
|
+
case 403:
|
|
86
|
+
return exports.ErrorCodes.PERMISSION_DENIED;
|
|
87
|
+
case 404:
|
|
88
|
+
return exports.ErrorCodes.NOT_FOUND;
|
|
89
|
+
case 429:
|
|
90
|
+
return exports.ErrorCodes.RATE_LIMITED;
|
|
91
|
+
default:
|
|
92
|
+
return exports.ErrorCodes.API_ERROR;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Wrapper for async handler functions with consistent error handling
|
|
97
|
+
* @param handler - The async handler function to wrap
|
|
98
|
+
* @param errorCode - Default error code to use
|
|
99
|
+
* @param errorMessage - Default error message
|
|
100
|
+
* @returns A wrapped function that catches errors and returns error results
|
|
101
|
+
*/
|
|
102
|
+
function withErrorHandling(handler, errorCode, errorMessage) {
|
|
103
|
+
return async (params) => {
|
|
104
|
+
try {
|
|
105
|
+
return await handler(params);
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
return createErrorInfo(errorCode, errorMessage, error);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Helper to check if a result is an error info
|
|
114
|
+
*/
|
|
115
|
+
function isErrorInfo(result) {
|
|
116
|
+
return (typeof result === 'object' &&
|
|
117
|
+
result !== null &&
|
|
118
|
+
'code' in result &&
|
|
119
|
+
'message' in result &&
|
|
120
|
+
typeof result.code === 'string' &&
|
|
121
|
+
typeof result.message === 'string');
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Standard suggestions for common errors
|
|
125
|
+
*/
|
|
126
|
+
exports.ErrorSuggestions = {
|
|
127
|
+
[exports.ErrorCodes.API_ERROR]: 'Check that the Rocket.Chat server is accessible and credentials are valid.',
|
|
128
|
+
[exports.ErrorCodes.VALIDATION_ERROR]: 'Review the input parameters and ensure they match the expected format.',
|
|
129
|
+
[exports.ErrorCodes.NOT_FOUND]: 'Verify that the resource exists and you have permission to access it.',
|
|
130
|
+
[exports.ErrorCodes.PERMISSION_DENIED]: 'Ensure you have the required permissions for this operation.',
|
|
131
|
+
[exports.ErrorCodes.RATE_LIMITED]: 'Too many requests. Please wait and try again.',
|
|
132
|
+
[exports.ErrorCodes.WRITE_DISABLED]: 'Set ROCKETCHAT_WRITE_ENABLED=true to enable write operations.',
|
|
133
|
+
[exports.ErrorCodes.ROOM_NOT_ALLOWED]: 'Check ROCKETCHAT_WRITE_ROOMS configuration for allowed rooms.',
|
|
134
|
+
[exports.ErrorCodes.UNKNOWN_ERROR]: 'An unexpected error occurred. Check the server logs for details.'
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Add suggestion to error info based on error code
|
|
138
|
+
*/
|
|
139
|
+
function enrichErrorInfo(errorInfo) {
|
|
140
|
+
if (!errorInfo.suggestion && exports.ErrorSuggestions[errorInfo.code]) {
|
|
141
|
+
return {
|
|
142
|
+
...errorInfo,
|
|
143
|
+
suggestion: exports.ErrorSuggestions[errorInfo.code]
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return errorInfo;
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../src/utils/error-handler.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAiCH,kDAWC;AAKD,kDAgBC;AAKD,0CAaC;AAKD,sDAcC;AASD,8CAYC;AAKD,kCASC;AAmBD,0CAQC;AAlKD,gDAAsD;AAEtD;;GAEG;AACU,QAAA,UAAU,GAAG;IACtB,SAAS,EAAE,WAAW;IACtB,gBAAgB,EAAE,kBAAkB;IACpC,SAAS,EAAE,WAAW;IACtB,iBAAiB,EAAE,mBAAmB;IACtC,YAAY,EAAE,cAAc;IAC5B,cAAc,EAAE,gBAAgB;IAChC,gBAAgB,EAAE,kBAAkB;IACpC,aAAa,EAAE,eAAe;CACxB,CAAC;AAcX;;GAEG;AACH,SAAgB,mBAAmB,CAAC,KAAc;IAC9C,IAAI,KAAK,YAAY,8BAAkB,EAAE,CAAC;QACtC,OAAO,GAAG,KAAK,CAAC,OAAO,aAAa,KAAK,CAAC,UAAU,GAAG,CAAC;IAC5D,CAAC;IACD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,OAAO,CAAC;IACzB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,wBAAwB,CAAC;AACpC,CAAC;AAED;;GAEG;AACH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CAAC,SAAS,CAAC,UAAU,IAAI,wBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5D,OAAO;YACH,GAAG,SAAS;YACZ,UAAU,EAAE,wBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC;SAC/C,CAAC;IACN,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utils module - Common utilities
|
|
3
|
+
*/
|
|
4
|
+
export { LRUCache } from './cache.js';
|
|
5
|
+
export { ErrorCodes, ErrorSuggestions, extractErrorMessage, extractErrorDetails, createErrorInfo, enrichErrorInfo, isErrorInfo } from './error-handler.js';
|
|
6
|
+
export type { ErrorCode, ErrorInfo } from './error-handler.js';
|
|
7
|
+
export { Logger, getLogger, resetLogger } from './logger.js';
|
|
8
|
+
export type { LogLevel } from './logger.js';
|
|
9
|
+
export { parseTimeExpression, toRocketChatTimestamp, formatDate, timeAgo } from './time-parser.js';
|
|
10
|
+
export type { TimeRange } from './time-parser.js';
|
|
11
|
+
export { TokenCounter } from './token-counter.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,OAAO,EACH,UAAU,EACV,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,WAAW,EACd,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/D,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC7D,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACnG,YAAY,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utils module - Common utilities
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TokenCounter = exports.timeAgo = exports.formatDate = exports.toRocketChatTimestamp = exports.parseTimeExpression = exports.resetLogger = exports.getLogger = exports.Logger = exports.isErrorInfo = exports.enrichErrorInfo = exports.createErrorInfo = exports.extractErrorDetails = exports.extractErrorMessage = exports.ErrorSuggestions = exports.ErrorCodes = exports.LRUCache = void 0;
|
|
7
|
+
// Cache
|
|
8
|
+
var cache_js_1 = require("./cache.js");
|
|
9
|
+
Object.defineProperty(exports, "LRUCache", { enumerable: true, get: function () { return cache_js_1.LRUCache; } });
|
|
10
|
+
// Error handler
|
|
11
|
+
var error_handler_js_1 = require("./error-handler.js");
|
|
12
|
+
Object.defineProperty(exports, "ErrorCodes", { enumerable: true, get: function () { return error_handler_js_1.ErrorCodes; } });
|
|
13
|
+
Object.defineProperty(exports, "ErrorSuggestions", { enumerable: true, get: function () { return error_handler_js_1.ErrorSuggestions; } });
|
|
14
|
+
Object.defineProperty(exports, "extractErrorMessage", { enumerable: true, get: function () { return error_handler_js_1.extractErrorMessage; } });
|
|
15
|
+
Object.defineProperty(exports, "extractErrorDetails", { enumerable: true, get: function () { return error_handler_js_1.extractErrorDetails; } });
|
|
16
|
+
Object.defineProperty(exports, "createErrorInfo", { enumerable: true, get: function () { return error_handler_js_1.createErrorInfo; } });
|
|
17
|
+
Object.defineProperty(exports, "enrichErrorInfo", { enumerable: true, get: function () { return error_handler_js_1.enrichErrorInfo; } });
|
|
18
|
+
Object.defineProperty(exports, "isErrorInfo", { enumerable: true, get: function () { return error_handler_js_1.isErrorInfo; } });
|
|
19
|
+
// Logger
|
|
20
|
+
var logger_js_1 = require("./logger.js");
|
|
21
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_js_1.Logger; } });
|
|
22
|
+
Object.defineProperty(exports, "getLogger", { enumerable: true, get: function () { return logger_js_1.getLogger; } });
|
|
23
|
+
Object.defineProperty(exports, "resetLogger", { enumerable: true, get: function () { return logger_js_1.resetLogger; } });
|
|
24
|
+
// Time parser
|
|
25
|
+
var time_parser_js_1 = require("./time-parser.js");
|
|
26
|
+
Object.defineProperty(exports, "parseTimeExpression", { enumerable: true, get: function () { return time_parser_js_1.parseTimeExpression; } });
|
|
27
|
+
Object.defineProperty(exports, "toRocketChatTimestamp", { enumerable: true, get: function () { return time_parser_js_1.toRocketChatTimestamp; } });
|
|
28
|
+
Object.defineProperty(exports, "formatDate", { enumerable: true, get: function () { return time_parser_js_1.formatDate; } });
|
|
29
|
+
Object.defineProperty(exports, "timeAgo", { enumerable: true, get: function () { return time_parser_js_1.timeAgo; } });
|
|
30
|
+
// Token counter
|
|
31
|
+
var token_counter_js_1 = require("./token-counter.js");
|
|
32
|
+
Object.defineProperty(exports, "TokenCounter", { enumerable: true, get: function () { return token_counter_js_1.TokenCounter; } });
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,QAAQ;AACR,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AAEjB,gBAAgB;AAChB,uDAQ4B;AAPxB,8GAAA,UAAU,OAAA;AACV,oHAAA,gBAAgB,OAAA;AAChB,uHAAA,mBAAmB,OAAA;AACnB,uHAAA,mBAAmB,OAAA;AACnB,mHAAA,eAAe,OAAA;AACf,mHAAA,eAAe,OAAA;AACf,+GAAA,WAAW,OAAA;AAIf,SAAS;AACT,yCAA6D;AAApD,mGAAA,MAAM,OAAA;AAAE,sGAAA,SAAS,OAAA;AAAE,wGAAA,WAAW,OAAA;AAGvC,cAAc;AACd,mDAAmG;AAA1F,qHAAA,mBAAmB,OAAA;AAAE,uHAAA,qBAAqB,OAAA;AAAE,4GAAA,UAAU,OAAA;AAAE,yGAAA,OAAO,OAAA;AAGxE,gBAAgB;AAChB,uDAAkD;AAAzC,gHAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple Logger Utility
|
|
3
|
+
* Provides consistent logging with debug mode support
|
|
4
|
+
*/
|
|
5
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
6
|
+
/**
|
|
7
|
+
* Logger class with level filtering
|
|
8
|
+
*/
|
|
9
|
+
export declare class Logger {
|
|
10
|
+
private debugMode;
|
|
11
|
+
private context;
|
|
12
|
+
constructor(context?: string, debugMode?: boolean);
|
|
13
|
+
/**
|
|
14
|
+
* Log a debug message (only in debug mode)
|
|
15
|
+
*/
|
|
16
|
+
debug(message: string, data?: unknown): void;
|
|
17
|
+
/**
|
|
18
|
+
* Log an info message
|
|
19
|
+
*/
|
|
20
|
+
info(message: string, data?: unknown): void;
|
|
21
|
+
/**
|
|
22
|
+
* Log a warning message
|
|
23
|
+
*/
|
|
24
|
+
warn(message: string, data?: unknown): void;
|
|
25
|
+
/**
|
|
26
|
+
* Log an error message
|
|
27
|
+
*/
|
|
28
|
+
error(message: string, error?: unknown): void;
|
|
29
|
+
/**
|
|
30
|
+
* Internal log method
|
|
31
|
+
*/
|
|
32
|
+
private log;
|
|
33
|
+
/**
|
|
34
|
+
* Format log entry for output
|
|
35
|
+
*/
|
|
36
|
+
private formatEntry;
|
|
37
|
+
/**
|
|
38
|
+
* Create a child logger with a sub-context
|
|
39
|
+
*/
|
|
40
|
+
child(subContext: string): Logger;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get the default logger instance
|
|
44
|
+
*/
|
|
45
|
+
export declare function getLogger(context?: string): Logger;
|
|
46
|
+
/**
|
|
47
|
+
* Reset the default logger (for testing)
|
|
48
|
+
*/
|
|
49
|
+
export declare function resetLogger(): void;
|
|
50
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAU3D;;GAEG;AACH,qBAAa,MAAM;IACf,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,GAAE,MAAc,EAAE,SAAS,CAAC,EAAE,OAAO;IAKxD;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAM5C;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAI3C;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAI3C;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI;IAO7C;;OAEG;IACH,OAAO,CAAC,GAAG;IAuBX;;OAEG;IACH,OAAO,CAAC,WAAW;IAkBnB;;OAEG;IACH,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;CAGpC;AAKD;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAQlD;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAElC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Simple Logger Utility
|
|
4
|
+
* Provides consistent logging with debug mode support
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.Logger = void 0;
|
|
8
|
+
exports.getLogger = getLogger;
|
|
9
|
+
exports.resetLogger = resetLogger;
|
|
10
|
+
/**
|
|
11
|
+
* Logger class with level filtering
|
|
12
|
+
*/
|
|
13
|
+
class Logger {
|
|
14
|
+
debugMode;
|
|
15
|
+
context;
|
|
16
|
+
constructor(context = 'MCP', debugMode) {
|
|
17
|
+
this.context = context;
|
|
18
|
+
this.debugMode = debugMode ?? process.env.DEBUG === 'true';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Log a debug message (only in debug mode)
|
|
22
|
+
*/
|
|
23
|
+
debug(message, data) {
|
|
24
|
+
if (this.debugMode) {
|
|
25
|
+
this.log('debug', message, data);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Log an info message
|
|
30
|
+
*/
|
|
31
|
+
info(message, data) {
|
|
32
|
+
this.log('info', message, data);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Log a warning message
|
|
36
|
+
*/
|
|
37
|
+
warn(message, data) {
|
|
38
|
+
this.log('warn', message, data);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Log an error message
|
|
42
|
+
*/
|
|
43
|
+
error(message, error) {
|
|
44
|
+
const data = error instanceof Error
|
|
45
|
+
? { message: error.message, stack: error.stack }
|
|
46
|
+
: error;
|
|
47
|
+
this.log('error', message, data);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Internal log method
|
|
51
|
+
*/
|
|
52
|
+
log(level, message, data) {
|
|
53
|
+
const entry = {
|
|
54
|
+
level,
|
|
55
|
+
message,
|
|
56
|
+
context: this.context,
|
|
57
|
+
timestamp: new Date().toISOString(),
|
|
58
|
+
data
|
|
59
|
+
};
|
|
60
|
+
const output = this.formatEntry(entry);
|
|
61
|
+
switch (level) {
|
|
62
|
+
case 'error':
|
|
63
|
+
console.error(output);
|
|
64
|
+
break;
|
|
65
|
+
case 'warn':
|
|
66
|
+
console.warn(output);
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
console.log(output);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Format log entry for output
|
|
74
|
+
*/
|
|
75
|
+
formatEntry(entry) {
|
|
76
|
+
const parts = [
|
|
77
|
+
`[${entry.timestamp}]`,
|
|
78
|
+
`[${entry.level.toUpperCase()}]`,
|
|
79
|
+
`[${entry.context}]`,
|
|
80
|
+
entry.message
|
|
81
|
+
];
|
|
82
|
+
if (entry.data !== undefined) {
|
|
83
|
+
parts.push('-');
|
|
84
|
+
parts.push(typeof entry.data === 'string'
|
|
85
|
+
? entry.data
|
|
86
|
+
: JSON.stringify(entry.data));
|
|
87
|
+
}
|
|
88
|
+
return parts.join(' ');
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Create a child logger with a sub-context
|
|
92
|
+
*/
|
|
93
|
+
child(subContext) {
|
|
94
|
+
return new Logger(`${this.context}:${subContext}`, this.debugMode);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.Logger = Logger;
|
|
98
|
+
// Default logger instance
|
|
99
|
+
let defaultLogger = null;
|
|
100
|
+
/**
|
|
101
|
+
* Get the default logger instance
|
|
102
|
+
*/
|
|
103
|
+
function getLogger(context) {
|
|
104
|
+
if (context) {
|
|
105
|
+
return new Logger(context);
|
|
106
|
+
}
|
|
107
|
+
if (!defaultLogger) {
|
|
108
|
+
defaultLogger = new Logger();
|
|
109
|
+
}
|
|
110
|
+
return defaultLogger;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Reset the default logger (for testing)
|
|
114
|
+
*/
|
|
115
|
+
function resetLogger() {
|
|
116
|
+
defaultLogger = null;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAsHH,8BAQC;AAKD,kCAEC;AAzHD;;GAEG;AACH,MAAa,MAAM;IACP,SAAS,CAAU;IACnB,OAAO,CAAS;IAExB,YAAY,UAAkB,KAAK,EAAE,SAAmB;QACpD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,KAAK,MAAM,CAAC;IAC/D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAe,EAAE,IAAc;QACjC,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACjB,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QACrC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,IAAI,CAAC,OAAe,EAAE,IAAc;QAChC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,IAAI,CAAC,OAAe,EAAE,IAAc;QAChC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAe,EAAE,KAAe;QAClC,MAAM,IAAI,GAAG,KAAK,YAAY,KAAK;YAC/B,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE;YAChD,CAAC,CAAC,KAAK,CAAC;QACZ,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACK,GAAG,CAAC,KAAe,EAAE,OAAe,EAAE,IAAc;QACxD,MA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;AA/FD,wBA+FC;AAED,0BAA0B;AAC1B,IAAI,aAAa,GAAkB,IAAI,CAAC;AAExC;;GAEG;AACH,SAAgB,SAAS,CAAC,OAAgB;IACtC,IAAI,OAAO,EAAE,CAAC;QACV,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IACD,IAAI,CAAC,aAAa,EAAE,CAAC;QACjB,aAAa,GAAG,IAAI,MAAM,EAAE,CAAC;IACjC,CAAC;IACD,OAAO,aAAa,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,SAAgB,WAAW;IACvB,aAAa,GAAG,IAAI,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time expression parser
|
|
3
|
+
* Supports: 1d, 7d, 1w, 1m, ISO dates
|
|
4
|
+
*/
|
|
5
|
+
export interface TimeRange {
|
|
6
|
+
oldest: Date;
|
|
7
|
+
latest: Date;
|
|
8
|
+
start: Date;
|
|
9
|
+
end: Date;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parse time expression to date range
|
|
13
|
+
*
|
|
14
|
+
* @param expr - Time expression: "1d", "7d", "1w", "1m", or ISO date
|
|
15
|
+
* @returns TimeRange with oldest and latest dates
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* parseTimeExpression("1d") // Today since midnight
|
|
19
|
+
* parseTimeExpression("7d") // Last 7 days
|
|
20
|
+
* parseTimeExpression("1w") // Last week (same as 7d)
|
|
21
|
+
* parseTimeExpression("1m") // Last month
|
|
22
|
+
* parseTimeExpression("2024-01-01") // Since specific date
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseTimeExpression(expr: string): TimeRange;
|
|
25
|
+
/**
|
|
26
|
+
* Convert Date to Rocket.Chat timestamp format
|
|
27
|
+
*/
|
|
28
|
+
export declare function toRocketChatTimestamp(date: Date): string;
|
|
29
|
+
/**
|
|
30
|
+
* Format date for display
|
|
31
|
+
*/
|
|
32
|
+
export declare function formatDate(date: Date): string;
|
|
33
|
+
/**
|
|
34
|
+
* Format relative time ago
|
|
35
|
+
*/
|
|
36
|
+
export declare function timeAgo(date: Date): string;
|
|
37
|
+
//# sourceMappingURL=time-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-parser.d.ts","sourceRoot":"","sources":["../../src/utils/time-parser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,SAAS;IACtB,MAAM,EAAE,IAAI,CAAC;IACb,MAAM,EAAE,IAAI,CAAC;IACb,KAAK,EAAE,IAAI,CAAC;IACZ,GAAG,EAAE,IAAI,CAAC;CACb;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAkD3D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAExD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAY1C"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Time expression parser
|
|
4
|
+
* Supports: 1d, 7d, 1w, 1m, ISO dates
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.parseTimeExpression = parseTimeExpression;
|
|
8
|
+
exports.toRocketChatTimestamp = toRocketChatTimestamp;
|
|
9
|
+
exports.formatDate = formatDate;
|
|
10
|
+
exports.timeAgo = timeAgo;
|
|
11
|
+
/**
|
|
12
|
+
* Parse time expression to date range
|
|
13
|
+
*
|
|
14
|
+
* @param expr - Time expression: "1d", "7d", "1w", "1m", or ISO date
|
|
15
|
+
* @returns TimeRange with oldest and latest dates
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* parseTimeExpression("1d") // Today since midnight
|
|
19
|
+
* parseTimeExpression("7d") // Last 7 days
|
|
20
|
+
* parseTimeExpression("1w") // Last week (same as 7d)
|
|
21
|
+
* parseTimeExpression("1m") // Last month
|
|
22
|
+
* parseTimeExpression("2024-01-01") // Since specific date
|
|
23
|
+
*/
|
|
24
|
+
function parseTimeExpression(expr) {
|
|
25
|
+
const now = new Date();
|
|
26
|
+
const startOfToday = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
27
|
+
// Relative time: 1d, 7d, 1w, 1m
|
|
28
|
+
const relativeMatch = expr.match(/^(\d+)([dwm])$/);
|
|
29
|
+
if (relativeMatch) {
|
|
30
|
+
const num = parseInt(relativeMatch[1], 10);
|
|
31
|
+
const unit = relativeMatch[2];
|
|
32
|
+
let oldest;
|
|
33
|
+
switch (unit) {
|
|
34
|
+
case 'd':
|
|
35
|
+
oldest = new Date(startOfToday.getTime() - (num - 1) * 24 * 60 * 60 * 1000);
|
|
36
|
+
break;
|
|
37
|
+
case 'w':
|
|
38
|
+
oldest = new Date(startOfToday.getTime() - (num * 7 - 1) * 24 * 60 * 60 * 1000);
|
|
39
|
+
break;
|
|
40
|
+
case 'm':
|
|
41
|
+
oldest = new Date(startOfToday);
|
|
42
|
+
oldest.setMonth(oldest.getMonth() - num);
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
throw new Error(`Invalid time unit: ${unit}`);
|
|
46
|
+
}
|
|
47
|
+
return { oldest, latest: now, start: oldest, end: now };
|
|
48
|
+
}
|
|
49
|
+
// ISO date: 2024-01-01
|
|
50
|
+
const dateMatch = expr.match(/^(\d{4}-\d{2}-\d{2})$/);
|
|
51
|
+
if (dateMatch) {
|
|
52
|
+
const oldest = new Date(dateMatch[1]);
|
|
53
|
+
if (isNaN(oldest.getTime())) {
|
|
54
|
+
throw new Error(`Invalid date format: ${expr}`);
|
|
55
|
+
}
|
|
56
|
+
return { oldest, latest: now, start: oldest, end: now };
|
|
57
|
+
}
|
|
58
|
+
// Unix timestamp (10 digits)
|
|
59
|
+
const unixMatch = expr.match(/^(\d{10})$/);
|
|
60
|
+
if (unixMatch) {
|
|
61
|
+
const oldest = new Date(parseInt(unixMatch[1], 10) * 1000);
|
|
62
|
+
return { oldest, latest: now, start: oldest, end: now };
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`Invalid time expression: "${expr}". ` +
|
|
65
|
+
`Use formats like "1d", "7d", "1w", "1m", or ISO date "2024-01-01"`);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Convert Date to Rocket.Chat timestamp format
|
|
69
|
+
*/
|
|
70
|
+
function toRocketChatTimestamp(date) {
|
|
71
|
+
return date.toISOString();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Format date for display
|
|
75
|
+
*/
|
|
76
|
+
function formatDate(date) {
|
|
77
|
+
return date.toISOString().replace('T', ' ').substring(0, 19);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Format relative time ago
|
|
81
|
+
*/
|
|
82
|
+
function timeAgo(date) {
|
|
83
|
+
const now = new Date();
|
|
84
|
+
const diffMs = now.getTime() - date.getTime();
|
|
85
|
+
const diffMins = Math.floor(diffMs / 60000);
|
|
86
|
+
const diffHours = Math.floor(diffMins / 60);
|
|
87
|
+
const diffDays = Math.floor(diffHours / 24);
|
|
88
|
+
if (diffMins < 1)
|
|
89
|
+
return 'just now';
|
|
90
|
+
if (diffMins < 60)
|
|
91
|
+
return `${diffMins}m ago`;
|
|
92
|
+
if (diffHours < 24)
|
|
93
|
+
return `${diffHours}h ago`;
|
|
94
|
+
if (diffDays < 7)
|
|
95
|
+
return `${diffDays}d ago`;
|
|
96
|
+
return formatDate(date);
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=time-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-parser.js","sourceRoot":"","sources":["../../src/utils/time-parser.ts"],"names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EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACjE,CAAC;AAED;;GAEG;AACH,SAAgB,OAAO,CAAC,IAAU;IAC9B,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC9C,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;IAC5C,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,EAAE,CAAC,CAAC;IAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,EAAE,CAAC,CAAC;IAE5C,IAAI,QAAQ,GAAG,CAAC;QAAE,OAAO,UAAU,CAAC;IACpC,IAAI,QAAQ,GAAG,EAAE;QAAE,OAAO,GAAG,QAAQ,OAAO,CAAC;IAC7C,IAAI,SAAS,GAAG,EAAE;QAAE,OAAO,GAAG,SAAS,OAAO,CAAC;IAC/C,IAAI,QAAQ,GAAG,CAAC;QAAE,OAAO,GAAG,QAAQ,OAAO,CAAC;IAC5C,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token counting utility for preventing response size overflow
|
|
3
|
+
* Estimates token count based on character length (rough approximation)
|
|
4
|
+
*/
|
|
5
|
+
export interface TruncateResult<T> {
|
|
6
|
+
items: T[];
|
|
7
|
+
truncated: boolean;
|
|
8
|
+
originalCount: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class TokenCounter {
|
|
11
|
+
private static readonly CHARS_PER_TOKEN;
|
|
12
|
+
private static readonly MAX_RESPONSE_CHARS;
|
|
13
|
+
private static readonly SAFETY_BUFFER;
|
|
14
|
+
/**
|
|
15
|
+
* Estimate token count from text
|
|
16
|
+
*/
|
|
17
|
+
static estimateTokens(text: string): number;
|
|
18
|
+
/**
|
|
19
|
+
* Check if text would exceed token limit
|
|
20
|
+
*/
|
|
21
|
+
static wouldExceedLimit(text: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Get maximum safe character count
|
|
24
|
+
*/
|
|
25
|
+
static getMaxSafeChars(): number;
|
|
26
|
+
/**
|
|
27
|
+
* Get safe limit for number of items based on average item size
|
|
28
|
+
*/
|
|
29
|
+
static getSafeItemLimit(sampleItem: unknown, maxItems?: number): number;
|
|
30
|
+
/**
|
|
31
|
+
* Truncate array to fit within token limit
|
|
32
|
+
*/
|
|
33
|
+
static truncateToFit<T>(items: T[], stringify?: (item: T) => string): TruncateResult<T>;
|
|
34
|
+
/**
|
|
35
|
+
* Truncate text to fit within limit
|
|
36
|
+
*/
|
|
37
|
+
static truncateText(text: string, maxChars?: number): {
|
|
38
|
+
text: string;
|
|
39
|
+
truncated: boolean;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=token-counter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-counter.d.ts","sourceRoot":"","sources":["../../src/utils/token-counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,cAAc,CAAC,CAAC;IAC7B,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,YAAY;IAErB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAK;IAG5C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAU;IAGpD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAQ;IAE7C;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI3C;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI9C;;OAEG;IACH,MAAM,CAAC,eAAe,IAAI,MAAM;IAIhC;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,GAAE,MAAY,GAAG,MAAM;IAS5E;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,CAAC,EAClB,KAAK,EAAE,CAAC,EAAE,EACV,SAAS,GAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAuB,GAChD,cAAc,CAAC,CAAC,CAAC;IAyBpB;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE;CAU7F"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Token counting utility for preventing response size overflow
|
|
4
|
+
* Estimates token count based on character length (rough approximation)
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.TokenCounter = void 0;
|
|
8
|
+
class TokenCounter {
|
|
9
|
+
// Rough estimation: 1 token ≈ 4 characters
|
|
10
|
+
static CHARS_PER_TOKEN = 4;
|
|
11
|
+
// MCP response character limit (~25,000 tokens)
|
|
12
|
+
static MAX_RESPONSE_CHARS = 100000;
|
|
13
|
+
// Safety buffer to ensure we don't exceed limits
|
|
14
|
+
static SAFETY_BUFFER = 4000;
|
|
15
|
+
/**
|
|
16
|
+
* Estimate token count from text
|
|
17
|
+
*/
|
|
18
|
+
static estimateTokens(text) {
|
|
19
|
+
return Math.ceil(text.length / this.CHARS_PER_TOKEN);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Check if text would exceed token limit
|
|
23
|
+
*/
|
|
24
|
+
static wouldExceedLimit(text) {
|
|
25
|
+
return text.length > (this.MAX_RESPONSE_CHARS - this.SAFETY_BUFFER);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get maximum safe character count
|
|
29
|
+
*/
|
|
30
|
+
static getMaxSafeChars() {
|
|
31
|
+
return this.MAX_RESPONSE_CHARS - this.SAFETY_BUFFER;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get safe limit for number of items based on average item size
|
|
35
|
+
*/
|
|
36
|
+
static getSafeItemLimit(sampleItem, maxItems = 100) {
|
|
37
|
+
const sampleText = JSON.stringify(sampleItem);
|
|
38
|
+
const charsPerItem = sampleText.length;
|
|
39
|
+
const maxChars = this.MAX_RESPONSE_CHARS - this.SAFETY_BUFFER;
|
|
40
|
+
const safeItemCount = Math.floor(maxChars / charsPerItem);
|
|
41
|
+
return Math.min(safeItemCount, maxItems);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Truncate array to fit within token limit
|
|
45
|
+
*/
|
|
46
|
+
static truncateToFit(items, stringify = JSON.stringify) {
|
|
47
|
+
const maxChars = this.MAX_RESPONSE_CHARS - this.SAFETY_BUFFER;
|
|
48
|
+
let totalSize = 0;
|
|
49
|
+
const safeItems = [];
|
|
50
|
+
for (const item of items) {
|
|
51
|
+
const itemSize = stringify(item).length;
|
|
52
|
+
if (totalSize + itemSize > maxChars) {
|
|
53
|
+
return {
|
|
54
|
+
items: safeItems,
|
|
55
|
+
truncated: true,
|
|
56
|
+
originalCount: items.length
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
safeItems.push(item);
|
|
60
|
+
totalSize += itemSize;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
items: safeItems,
|
|
64
|
+
truncated: false,
|
|
65
|
+
originalCount: items.length
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Truncate text to fit within limit
|
|
70
|
+
*/
|
|
71
|
+
static truncateText(text, maxChars) {
|
|
72
|
+
const limit = maxChars || (this.MAX_RESPONSE_CHARS - this.SAFETY_BUFFER);
|
|
73
|
+
if (text.length <= limit) {
|
|
74
|
+
return { text, truncated: false };
|
|
75
|
+
}
|
|
76
|
+
const truncatedText = text.substring(0, limit - 20) + '... [truncated]';
|
|
77
|
+
return { text: truncatedText, truncated: true };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.TokenCounter = TokenCounter;
|
|
81
|
+
//# sourceMappingURL=token-counter.js.map
|