mcp-researchpowerpack 3.9.4 → 4.3.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/README.md +116 -208
- package/dist/index.js +280 -337
- package/dist/index.js.map +7 -1
- package/dist/mcp-use.json +7 -0
- package/dist/src/clients/reddit.js +278 -0
- package/dist/src/clients/reddit.js.map +7 -0
- package/dist/src/clients/scraper.js +326 -0
- package/dist/src/clients/scraper.js.map +7 -0
- package/dist/src/clients/search.js +217 -0
- package/dist/src/clients/search.js.map +7 -0
- package/dist/src/config/index.js +138 -0
- package/dist/src/config/index.js.map +7 -0
- package/dist/src/prompts/deep-research.js +41 -0
- package/dist/src/prompts/deep-research.js.map +7 -0
- package/dist/src/prompts/reddit-sentiment.js +47 -0
- package/dist/src/prompts/reddit-sentiment.js.map +7 -0
- package/dist/src/schemas/reddit.js +21 -0
- package/dist/src/schemas/reddit.js.map +7 -0
- package/dist/src/schemas/scrape-links.js +26 -0
- package/dist/src/schemas/scrape-links.js.map +7 -0
- package/dist/src/schemas/start-research.js +17 -0
- package/dist/src/schemas/start-research.js.map +7 -0
- package/dist/src/schemas/web-search.js +53 -0
- package/dist/src/schemas/web-search.js.map +7 -0
- package/dist/src/services/llm-processor.js +675 -0
- package/dist/src/services/llm-processor.js.map +7 -0
- package/dist/src/services/markdown-cleaner.js +62 -0
- package/dist/src/services/markdown-cleaner.js.map +7 -0
- package/dist/src/services/workflow-state.js +116 -0
- package/dist/src/services/workflow-state.js.map +7 -0
- package/dist/src/tools/mcp-helpers.js +50 -0
- package/dist/src/tools/mcp-helpers.js.map +7 -0
- package/dist/src/tools/reddit.js +277 -0
- package/dist/src/tools/reddit.js.map +7 -0
- package/dist/src/tools/registry.js +18 -0
- package/dist/src/tools/registry.js.map +7 -0
- package/dist/src/tools/scrape.js +334 -0
- package/dist/src/tools/scrape.js.map +7 -0
- package/dist/src/tools/search.js +423 -0
- package/dist/src/tools/search.js.map +7 -0
- package/dist/src/tools/start-research.js +199 -0
- package/dist/src/tools/start-research.js.map +7 -0
- package/dist/src/tools/utils.js +29 -0
- package/dist/src/tools/utils.js.map +7 -0
- package/dist/src/utils/bootstrap-guard.js +27 -0
- package/dist/src/utils/bootstrap-guard.js.map +7 -0
- package/dist/src/utils/concurrency.js +62 -0
- package/dist/src/utils/concurrency.js.map +7 -0
- package/dist/src/utils/content-extractor.js +61 -0
- package/dist/src/utils/content-extractor.js.map +7 -0
- package/dist/src/utils/errors.js +211 -0
- package/dist/src/utils/errors.js.map +7 -0
- package/dist/src/utils/logger.js +25 -0
- package/dist/src/utils/logger.js.map +7 -0
- package/dist/src/utils/markdown-formatter.js +15 -0
- package/dist/src/utils/markdown-formatter.js.map +7 -0
- package/dist/src/utils/reddit-keyword-guard.js +29 -0
- package/dist/src/utils/reddit-keyword-guard.js.map +7 -0
- package/dist/src/utils/response.js +81 -0
- package/dist/src/utils/response.js.map +7 -0
- package/dist/src/utils/retry.js +13 -0
- package/dist/src/utils/retry.js.map +7 -0
- package/dist/src/utils/sanitize.js +10 -0
- package/dist/src/utils/sanitize.js.map +7 -0
- package/dist/src/utils/source-type.js +41 -0
- package/dist/src/utils/source-type.js.map +7 -0
- package/dist/src/utils/url-aggregator.js +227 -0
- package/dist/src/utils/url-aggregator.js.map +7 -0
- package/dist/src/utils/workflow-key.js +14 -0
- package/dist/src/utils/workflow-key.js.map +7 -0
- package/dist/src/version.js +32 -0
- package/dist/src/version.js.map +7 -0
- package/package.json +33 -28
- package/dist/clients/reddit.d.ts +0 -69
- package/dist/clients/reddit.d.ts.map +0 -1
- package/dist/clients/reddit.js +0 -369
- package/dist/clients/reddit.js.map +0 -1
- package/dist/clients/research.d.ts +0 -67
- package/dist/clients/research.d.ts.map +0 -1
- package/dist/clients/research.js +0 -290
- package/dist/clients/research.js.map +0 -1
- package/dist/clients/scraper.d.ts +0 -72
- package/dist/clients/scraper.d.ts.map +0 -1
- package/dist/clients/scraper.js +0 -338
- package/dist/clients/scraper.js.map +0 -1
- package/dist/clients/search.d.ts +0 -57
- package/dist/clients/search.d.ts.map +0 -1
- package/dist/clients/search.js +0 -223
- package/dist/clients/search.js.map +0 -1
- package/dist/config/index.d.ts +0 -78
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js +0 -201
- package/dist/config/index.js.map +0 -1
- package/dist/config/loader.d.ts +0 -40
- package/dist/config/loader.d.ts.map +0 -1
- package/dist/config/loader.js +0 -322
- package/dist/config/loader.js.map +0 -1
- package/dist/config/types.d.ts +0 -81
- package/dist/config/types.d.ts.map +0 -1
- package/dist/config/types.js +0 -6
- package/dist/config/types.js.map +0 -1
- package/dist/config/yaml/tools.yaml +0 -146
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/schemas/deep-research.d.ts +0 -64
- package/dist/schemas/deep-research.d.ts.map +0 -1
- package/dist/schemas/deep-research.js +0 -224
- package/dist/schemas/deep-research.js.map +0 -1
- package/dist/schemas/scrape-links.d.ts +0 -32
- package/dist/schemas/scrape-links.d.ts.map +0 -1
- package/dist/schemas/scrape-links.js +0 -34
- package/dist/schemas/scrape-links.js.map +0 -1
- package/dist/schemas/web-search.d.ts +0 -22
- package/dist/schemas/web-search.d.ts.map +0 -1
- package/dist/schemas/web-search.js +0 -21
- package/dist/schemas/web-search.js.map +0 -1
- package/dist/services/file-attachment.d.ts +0 -30
- package/dist/services/file-attachment.d.ts.map +0 -1
- package/dist/services/file-attachment.js +0 -207
- package/dist/services/file-attachment.js.map +0 -1
- package/dist/services/llm-processor.d.ts +0 -29
- package/dist/services/llm-processor.d.ts.map +0 -1
- package/dist/services/llm-processor.js +0 -244
- package/dist/services/llm-processor.js.map +0 -1
- package/dist/services/markdown-cleaner.d.ts +0 -8
- package/dist/services/markdown-cleaner.d.ts.map +0 -1
- package/dist/services/markdown-cleaner.js +0 -74
- package/dist/services/markdown-cleaner.js.map +0 -1
- package/dist/tools/definitions.d.ts +0 -16
- package/dist/tools/definitions.d.ts.map +0 -1
- package/dist/tools/definitions.js +0 -17
- package/dist/tools/definitions.js.map +0 -1
- package/dist/tools/reddit.d.ts +0 -14
- package/dist/tools/reddit.d.ts.map +0 -1
- package/dist/tools/reddit.js +0 -265
- package/dist/tools/reddit.js.map +0 -1
- package/dist/tools/registry.d.ts +0 -71
- package/dist/tools/registry.d.ts.map +0 -1
- package/dist/tools/registry.js +0 -252
- package/dist/tools/registry.js.map +0 -1
- package/dist/tools/research.d.ts +0 -14
- package/dist/tools/research.d.ts.map +0 -1
- package/dist/tools/research.js +0 -196
- package/dist/tools/research.js.map +0 -1
- package/dist/tools/scrape.d.ts +0 -14
- package/dist/tools/scrape.d.ts.map +0 -1
- package/dist/tools/scrape.js +0 -234
- package/dist/tools/scrape.js.map +0 -1
- package/dist/tools/search.d.ts +0 -10
- package/dist/tools/search.d.ts.map +0 -1
- package/dist/tools/search.js +0 -158
- package/dist/tools/search.js.map +0 -1
- package/dist/tools/utils.d.ts +0 -105
- package/dist/tools/utils.d.ts.map +0 -1
- package/dist/tools/utils.js +0 -159
- package/dist/tools/utils.js.map +0 -1
- package/dist/utils/concurrency.d.ts +0 -28
- package/dist/utils/concurrency.d.ts.map +0 -1
- package/dist/utils/concurrency.js +0 -92
- package/dist/utils/concurrency.js.map +0 -1
- package/dist/utils/errors.d.ts +0 -95
- package/dist/utils/errors.d.ts.map +0 -1
- package/dist/utils/errors.js +0 -390
- package/dist/utils/errors.js.map +0 -1
- package/dist/utils/logger.d.ts +0 -39
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -57
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/markdown-formatter.d.ts +0 -5
- package/dist/utils/markdown-formatter.d.ts.map +0 -1
- package/dist/utils/markdown-formatter.js +0 -15
- package/dist/utils/markdown-formatter.js.map +0 -1
- package/dist/utils/response.d.ts +0 -93
- package/dist/utils/response.d.ts.map +0 -1
- package/dist/utils/response.js +0 -170
- package/dist/utils/response.js.map +0 -1
- package/dist/utils/retry.d.ts +0 -43
- package/dist/utils/retry.d.ts.map +0 -1
- package/dist/utils/retry.js +0 -57
- package/dist/utils/retry.js.map +0 -1
- package/dist/utils/url-aggregator.d.ts +0 -90
- package/dist/utils/url-aggregator.d.ts.map +0 -1
- package/dist/utils/url-aggregator.js +0 -538
- package/dist/utils/url-aggregator.js.map +0 -1
- package/dist/version.d.ts +0 -29
- package/dist/version.d.ts.map +0 -1
- package/dist/version.js +0 -55
- package/dist/version.js.map +0 -1
package/dist/utils/errors.js
DELETED
|
@@ -1,390 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Robust error handling utilities for MCP server
|
|
3
|
-
* Ensures the server NEVER crashes and always returns structured responses
|
|
4
|
-
*/
|
|
5
|
-
import { mcpLog } from './logger.js';
|
|
6
|
-
// ============================================================================
|
|
7
|
-
// Error Codes (MCP-compliant)
|
|
8
|
-
// ============================================================================
|
|
9
|
-
export const ErrorCode = {
|
|
10
|
-
// Retryable errors
|
|
11
|
-
RATE_LIMITED: 'RATE_LIMITED',
|
|
12
|
-
TIMEOUT: 'TIMEOUT',
|
|
13
|
-
NETWORK_ERROR: 'NETWORK_ERROR',
|
|
14
|
-
SERVICE_UNAVAILABLE: 'SERVICE_UNAVAILABLE',
|
|
15
|
-
// Non-retryable errors
|
|
16
|
-
AUTH_ERROR: 'AUTH_ERROR',
|
|
17
|
-
INVALID_INPUT: 'INVALID_INPUT',
|
|
18
|
-
NOT_FOUND: 'NOT_FOUND',
|
|
19
|
-
QUOTA_EXCEEDED: 'QUOTA_EXCEEDED',
|
|
20
|
-
// Internal errors
|
|
21
|
-
INTERNAL_ERROR: 'INTERNAL_ERROR',
|
|
22
|
-
PARSE_ERROR: 'PARSE_ERROR',
|
|
23
|
-
UNKNOWN_ERROR: 'UNKNOWN_ERROR',
|
|
24
|
-
};
|
|
25
|
-
// ============================================================================
|
|
26
|
-
// Constants
|
|
27
|
-
// ============================================================================
|
|
28
|
-
const MAX_ERROR_MSG_LENGTH = 500;
|
|
29
|
-
const DEFAULT_RETRY_OPTIONS = {
|
|
30
|
-
maxRetries: 3,
|
|
31
|
-
baseDelayMs: 1000,
|
|
32
|
-
maxDelayMs: 30000,
|
|
33
|
-
retryableStatuses: [408, 429, 500, 502, 503, 504, 510],
|
|
34
|
-
};
|
|
35
|
-
// ============================================================================
|
|
36
|
-
// Error Classification — Atomic Classifiers
|
|
37
|
-
// ============================================================================
|
|
38
|
-
/**
|
|
39
|
-
* Classify DOMException (AbortError from AbortController timeouts)
|
|
40
|
-
*/
|
|
41
|
-
function classifyDomException(error) {
|
|
42
|
-
if (error.name === 'AbortError') {
|
|
43
|
-
return { code: ErrorCode.TIMEOUT, message: 'Request timed out', retryable: true };
|
|
44
|
-
}
|
|
45
|
-
return { code: ErrorCode.UNKNOWN_ERROR, message: error.message.substring(0, MAX_ERROR_MSG_LENGTH), retryable: false };
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Classify by Node.js error codes (ECONNREFUSED, ENOTFOUND, etc.)
|
|
49
|
-
* Returns null if no matching code is found.
|
|
50
|
-
*/
|
|
51
|
-
function classifyByErrorCode(error) {
|
|
52
|
-
const errCode = error.code;
|
|
53
|
-
if (!errCode)
|
|
54
|
-
return null;
|
|
55
|
-
const networkErrorMessages = {
|
|
56
|
-
ECONNREFUSED: 'Connection refused — service may be down',
|
|
57
|
-
ECONNRESET: 'Connection was reset — please retry',
|
|
58
|
-
ECONNABORTED: 'Connection aborted — please retry',
|
|
59
|
-
ENOTFOUND: 'Service not reachable — check your network',
|
|
60
|
-
EPIPE: 'Connection lost — please retry',
|
|
61
|
-
EAI_AGAIN: 'DNS lookup failed — check your network',
|
|
62
|
-
};
|
|
63
|
-
if (errCode === 'ECONNREFUSED' || errCode === 'ENOTFOUND' || errCode === 'ECONNRESET') {
|
|
64
|
-
return { code: ErrorCode.NETWORK_ERROR, message: networkErrorMessages[errCode] || 'Network connection failed', retryable: true, cause: error.message };
|
|
65
|
-
}
|
|
66
|
-
if (errCode === 'ECONNABORTED' || errCode === 'ETIMEDOUT') {
|
|
67
|
-
return { code: ErrorCode.TIMEOUT, message: networkErrorMessages[errCode] || 'Request timed out', retryable: true, cause: error.message };
|
|
68
|
-
}
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Classify by HTTP status code extracted from error objects (axios-style, fetch-style, etc.)
|
|
73
|
-
* Returns null if no status code is found.
|
|
74
|
-
*/
|
|
75
|
-
function classifyByStatusCode(error) {
|
|
76
|
-
const status = error.response?.status || error.status || error.statusCode;
|
|
77
|
-
if (!status)
|
|
78
|
-
return null;
|
|
79
|
-
return classifyHttpError(status, error.message || String(error));
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Classify by error message patterns (timeout, rate-limit, auth, parse errors)
|
|
83
|
-
* Returns null if no pattern matches.
|
|
84
|
-
*/
|
|
85
|
-
function classifyByMessage(message) {
|
|
86
|
-
const lower = message.toLowerCase();
|
|
87
|
-
// Timeout patterns
|
|
88
|
-
if (lower.includes('timeout') || lower.includes('timed out') || lower.includes('aborterror')) {
|
|
89
|
-
return { code: ErrorCode.TIMEOUT, message: 'Request timed out', retryable: true, cause: message };
|
|
90
|
-
}
|
|
91
|
-
// Rate-limit patterns
|
|
92
|
-
if (lower.includes('rate limit') || lower.includes('too many requests')) {
|
|
93
|
-
return { code: ErrorCode.RATE_LIMITED, message: 'Rate limit exceeded', retryable: true, cause: message };
|
|
94
|
-
}
|
|
95
|
-
// API key errors
|
|
96
|
-
if (message.includes('API_KEY') || message.includes('api_key') || message.includes('Invalid API')) {
|
|
97
|
-
return { code: ErrorCode.AUTH_ERROR, message: 'API key missing or invalid', retryable: false, cause: message };
|
|
98
|
-
}
|
|
99
|
-
// Parse errors
|
|
100
|
-
if (message.includes('JSON') || message.includes('parse') || message.includes('Unexpected token')) {
|
|
101
|
-
return { code: ErrorCode.PARSE_ERROR, message: 'Failed to parse response', retryable: false, cause: message };
|
|
102
|
-
}
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Catch-all fallback classification when no other classifier matches.
|
|
107
|
-
*/
|
|
108
|
-
function classifyFallback(message, cause) {
|
|
109
|
-
return {
|
|
110
|
-
code: ErrorCode.UNKNOWN_ERROR,
|
|
111
|
-
message: message.substring(0, MAX_ERROR_MSG_LENGTH),
|
|
112
|
-
retryable: false,
|
|
113
|
-
cause: cause ? String(cause) : undefined,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
// ============================================================================
|
|
117
|
-
// Main Error Classification Pipeline
|
|
118
|
-
// ============================================================================
|
|
119
|
-
/**
|
|
120
|
-
* Classify any error into a structured format.
|
|
121
|
-
* NEVER throws — always returns a valid StructuredError.
|
|
122
|
-
*/
|
|
123
|
-
export function classifyError(error) {
|
|
124
|
-
if (error == null) {
|
|
125
|
-
return { code: ErrorCode.UNKNOWN_ERROR, message: 'An unknown error occurred', retryable: false };
|
|
126
|
-
}
|
|
127
|
-
if (error instanceof DOMException)
|
|
128
|
-
return classifyDomException(error);
|
|
129
|
-
if (!isErrorLike(error)) {
|
|
130
|
-
return { code: ErrorCode.UNKNOWN_ERROR, message: String(error).substring(0, MAX_ERROR_MSG_LENGTH), retryable: false };
|
|
131
|
-
}
|
|
132
|
-
return classifyByErrorCode(error)
|
|
133
|
-
?? classifyByStatusCode(error)
|
|
134
|
-
?? classifyByMessage(error.message ?? String(error))
|
|
135
|
-
?? classifyFallback(error.message ?? String(error), error.cause);
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Type guard for error-like objects with common error properties
|
|
139
|
-
*/
|
|
140
|
-
function isErrorLike(value) {
|
|
141
|
-
return typeof value === 'object' && value !== null;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Classify HTTP status codes into structured errors.
|
|
145
|
-
* Exhaustive switch with grouped default handling for unknown ranges.
|
|
146
|
-
*/
|
|
147
|
-
function classifyHttpError(status, message) {
|
|
148
|
-
switch (status) {
|
|
149
|
-
case 400:
|
|
150
|
-
return { code: ErrorCode.INVALID_INPUT, message: 'Bad request', retryable: false, statusCode: status };
|
|
151
|
-
case 401:
|
|
152
|
-
return { code: ErrorCode.AUTH_ERROR, message: 'Invalid API key', retryable: false, statusCode: status };
|
|
153
|
-
case 403:
|
|
154
|
-
return { code: ErrorCode.QUOTA_EXCEEDED, message: 'Access forbidden or quota exceeded', retryable: false, statusCode: status };
|
|
155
|
-
case 404:
|
|
156
|
-
return { code: ErrorCode.NOT_FOUND, message: 'Resource not found', retryable: false, statusCode: status };
|
|
157
|
-
case 408:
|
|
158
|
-
return { code: ErrorCode.TIMEOUT, message: 'Request timeout', retryable: true, statusCode: status };
|
|
159
|
-
case 429:
|
|
160
|
-
return { code: ErrorCode.RATE_LIMITED, message: 'Rate limit exceeded', retryable: true, statusCode: status };
|
|
161
|
-
case 500:
|
|
162
|
-
return { code: ErrorCode.INTERNAL_ERROR, message: 'Server error', retryable: true, statusCode: status };
|
|
163
|
-
case 502:
|
|
164
|
-
return { code: ErrorCode.SERVICE_UNAVAILABLE, message: 'Bad gateway', retryable: true, statusCode: status };
|
|
165
|
-
case 503:
|
|
166
|
-
return { code: ErrorCode.SERVICE_UNAVAILABLE, message: 'Service unavailable', retryable: true, statusCode: status };
|
|
167
|
-
case 504:
|
|
168
|
-
return { code: ErrorCode.TIMEOUT, message: 'Gateway timeout', retryable: true, statusCode: status };
|
|
169
|
-
case 510:
|
|
170
|
-
return { code: ErrorCode.SERVICE_UNAVAILABLE, message: 'Request canceled', retryable: true, statusCode: status };
|
|
171
|
-
default:
|
|
172
|
-
if (status >= 500) {
|
|
173
|
-
return { code: ErrorCode.SERVICE_UNAVAILABLE, message: `Server error: ${status}`, retryable: true, statusCode: status };
|
|
174
|
-
}
|
|
175
|
-
if (status >= 400) {
|
|
176
|
-
return { code: ErrorCode.INVALID_INPUT, message: `Client error: ${status}`, retryable: false, statusCode: status };
|
|
177
|
-
}
|
|
178
|
-
return { code: ErrorCode.UNKNOWN_ERROR, message: `HTTP ${status}: ${message.substring(0, MAX_ERROR_MSG_LENGTH)}`, retryable: false, statusCode: status };
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
// ============================================================================
|
|
182
|
-
// Retry Logic with Exponential Backoff
|
|
183
|
-
// ============================================================================
|
|
184
|
-
/**
|
|
185
|
-
* Calculate delay with exponential backoff and jitter
|
|
186
|
-
*/
|
|
187
|
-
function calculateBackoff(attempt, options) {
|
|
188
|
-
const exponentialDelay = options.baseDelayMs * Math.pow(2, attempt);
|
|
189
|
-
const jitter = Math.random() * 0.3 * exponentialDelay; // 0-30% jitter
|
|
190
|
-
return Math.min(exponentialDelay + jitter, options.maxDelayMs);
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Sleep utility that respects abort signals
|
|
194
|
-
*/
|
|
195
|
-
export function sleep(ms, signal) {
|
|
196
|
-
return new Promise((resolve, reject) => {
|
|
197
|
-
if (signal?.aborted) {
|
|
198
|
-
reject(new DOMException('Aborted', 'AbortError'));
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
function onAbort() {
|
|
202
|
-
clearTimeout(timeout);
|
|
203
|
-
reject(new DOMException('Aborted', 'AbortError'));
|
|
204
|
-
}
|
|
205
|
-
const timeout = setTimeout(() => {
|
|
206
|
-
if (signal)
|
|
207
|
-
signal.removeEventListener('abort', onAbort);
|
|
208
|
-
resolve();
|
|
209
|
-
}, ms);
|
|
210
|
-
signal?.addEventListener('abort', onAbort, { once: true });
|
|
211
|
-
// Re-check: signal may have aborted between initial check and listener registration
|
|
212
|
-
if (signal?.aborted) {
|
|
213
|
-
onAbort();
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Wrap a fetch call with timeout via AbortController
|
|
219
|
-
*/
|
|
220
|
-
export function fetchWithTimeout(url, options = {}) {
|
|
221
|
-
const { timeoutMs = 30000, signal: externalSignal, ...fetchOptions } = options;
|
|
222
|
-
const controller = new AbortController();
|
|
223
|
-
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
224
|
-
let onExternalAbort;
|
|
225
|
-
if (externalSignal) {
|
|
226
|
-
onExternalAbort = () => controller.abort();
|
|
227
|
-
externalSignal.addEventListener('abort', onExternalAbort, { once: true });
|
|
228
|
-
if (externalSignal.aborted) {
|
|
229
|
-
controller.abort();
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return fetch(url, { ...fetchOptions, signal: controller.signal }).finally(() => {
|
|
233
|
-
clearTimeout(timeoutId);
|
|
234
|
-
if (externalSignal && onExternalAbort) {
|
|
235
|
-
externalSignal.removeEventListener('abort', onExternalAbort);
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
// ============================================================================
|
|
240
|
-
// MCP Tool Error Response Types (for client-facing error responses)
|
|
241
|
-
// ============================================================================
|
|
242
|
-
/**
|
|
243
|
-
* MCP-compliant error codes for tool responses
|
|
244
|
-
* These codes are exposed to clients for programmatic error handling
|
|
245
|
-
*/
|
|
246
|
-
export const MCP_ERROR_CODES = {
|
|
247
|
-
RATE_LIMITED: 'RATE_LIMITED',
|
|
248
|
-
NETWORK_ERROR: 'NETWORK_ERROR',
|
|
249
|
-
TIMEOUT: 'TIMEOUT',
|
|
250
|
-
VALIDATION_ERROR: 'VALIDATION_ERROR',
|
|
251
|
-
AUTH_ERROR: 'AUTH_ERROR',
|
|
252
|
-
NOT_FOUND: 'NOT_FOUND',
|
|
253
|
-
INTERNAL_ERROR: 'INTERNAL_ERROR',
|
|
254
|
-
SERVICE_UNAVAILABLE: 'SERVICE_UNAVAILABLE',
|
|
255
|
-
};
|
|
256
|
-
/**
|
|
257
|
-
* Map internal ErrorCode to client-facing MCP_ERROR_CODES
|
|
258
|
-
*/
|
|
259
|
-
function mapErrorCodeToMCP(code) {
|
|
260
|
-
switch (code) {
|
|
261
|
-
case ErrorCode.RATE_LIMITED:
|
|
262
|
-
case ErrorCode.QUOTA_EXCEEDED:
|
|
263
|
-
return MCP_ERROR_CODES.RATE_LIMITED;
|
|
264
|
-
case ErrorCode.TIMEOUT:
|
|
265
|
-
return MCP_ERROR_CODES.TIMEOUT;
|
|
266
|
-
case ErrorCode.NETWORK_ERROR:
|
|
267
|
-
return MCP_ERROR_CODES.NETWORK_ERROR;
|
|
268
|
-
case ErrorCode.SERVICE_UNAVAILABLE:
|
|
269
|
-
return MCP_ERROR_CODES.SERVICE_UNAVAILABLE;
|
|
270
|
-
case ErrorCode.AUTH_ERROR:
|
|
271
|
-
return MCP_ERROR_CODES.AUTH_ERROR;
|
|
272
|
-
case ErrorCode.NOT_FOUND:
|
|
273
|
-
return MCP_ERROR_CODES.NOT_FOUND;
|
|
274
|
-
case ErrorCode.INVALID_INPUT:
|
|
275
|
-
case ErrorCode.PARSE_ERROR:
|
|
276
|
-
return MCP_ERROR_CODES.VALIDATION_ERROR;
|
|
277
|
-
case ErrorCode.INTERNAL_ERROR:
|
|
278
|
-
case ErrorCode.UNKNOWN_ERROR:
|
|
279
|
-
default:
|
|
280
|
-
return MCP_ERROR_CODES.INTERNAL_ERROR;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Create a standardized MCP tool error response
|
|
285
|
-
* @param message - Human-readable error message
|
|
286
|
-
* @param errorCode - Optional MCP error code for programmatic handling
|
|
287
|
-
* @param retryAfter - Optional seconds to wait before retry (for rate limits)
|
|
288
|
-
*/
|
|
289
|
-
function createToolError(message, errorCode, retryAfter) {
|
|
290
|
-
const response = {
|
|
291
|
-
content: [{ type: 'text', text: message }],
|
|
292
|
-
isError: true,
|
|
293
|
-
};
|
|
294
|
-
if (errorCode) {
|
|
295
|
-
response.errorCode = errorCode;
|
|
296
|
-
}
|
|
297
|
-
if (retryAfter !== undefined && retryAfter > 0) {
|
|
298
|
-
response.retryAfter = retryAfter;
|
|
299
|
-
}
|
|
300
|
-
return response;
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Create a tool error response from a StructuredError
|
|
304
|
-
* Automatically maps error codes and calculates retryAfter for rate limits
|
|
305
|
-
*/
|
|
306
|
-
export function createToolErrorFromStructured(structuredError, attempt = 0) {
|
|
307
|
-
const errorCode = mapErrorCodeToMCP(structuredError.code);
|
|
308
|
-
// Calculate retryAfter for rate-limited errors
|
|
309
|
-
let retryAfter;
|
|
310
|
-
if (structuredError.retryable && errorCode === MCP_ERROR_CODES.RATE_LIMITED) {
|
|
311
|
-
retryAfter = Math.ceil(calculateBackoff(attempt, DEFAULT_RETRY_OPTIONS) / 1000);
|
|
312
|
-
}
|
|
313
|
-
// Format user-friendly error message
|
|
314
|
-
const retryHint = structuredError.retryable
|
|
315
|
-
? '\n\n💡 This error may be temporary. Try again in a moment.'
|
|
316
|
-
: '';
|
|
317
|
-
const errorText = `## ❌ Error\n\n**${structuredError.code}:** ${structuredError.message}${retryHint}\n\nPlease check your input parameters and try again.`;
|
|
318
|
-
return createToolError(errorText, errorCode, retryAfter);
|
|
319
|
-
}
|
|
320
|
-
// ============================================================================
|
|
321
|
-
// Stability Wrappers — Network resilience for LLM API calls
|
|
322
|
-
// ============================================================================
|
|
323
|
-
/**
|
|
324
|
-
* Wrap a promise with a hard deadline timeout.
|
|
325
|
-
* If the promise doesn't resolve/reject within `timeoutMs`, it rejects with a timeout error.
|
|
326
|
-
* Uses AbortController to signal cancellation to the underlying request.
|
|
327
|
-
*/
|
|
328
|
-
export function withRequestTimeout(fn, timeoutMs, label = 'request') {
|
|
329
|
-
const controller = new AbortController();
|
|
330
|
-
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
331
|
-
return fn(controller.signal).finally(() => clearTimeout(timeoutId)).catch((err) => {
|
|
332
|
-
if (controller.signal.aborted && err instanceof DOMException && err.name === 'AbortError') {
|
|
333
|
-
throw Object.assign(new Error('Request timed out — please try again'), {
|
|
334
|
-
code: 'ETIMEDOUT',
|
|
335
|
-
retryable: true,
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
throw err;
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Wrap a non-streaming API call with activity-based timeout detection.
|
|
343
|
-
* If the call hasn't completed within `stallMs`, abort and retry.
|
|
344
|
-
* This catches "stuck" connections where TCP stays open but no data flows.
|
|
345
|
-
*
|
|
346
|
-
* @param fn - Async function that accepts an AbortSignal
|
|
347
|
-
* @param stallMs - Max milliseconds to wait for the call to complete before considering it stuck
|
|
348
|
-
* @param maxAttempts - Max retry attempts for stalled requests
|
|
349
|
-
* @param label - Label for log messages
|
|
350
|
-
* @returns The result of the function
|
|
351
|
-
*/
|
|
352
|
-
export async function withStallProtection(fn, stallMs, maxAttempts = 2, label = 'request') {
|
|
353
|
-
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
354
|
-
const controller = new AbortController();
|
|
355
|
-
let stallTimer;
|
|
356
|
-
const stallPromise = new Promise((_, reject) => {
|
|
357
|
-
stallTimer = setTimeout(() => {
|
|
358
|
-
controller.abort();
|
|
359
|
-
reject(Object.assign(new Error(`Service temporarily unavailable — no response received (attempt ${attempt + 1}/${maxAttempts})`), {
|
|
360
|
-
code: 'ESTALLED',
|
|
361
|
-
retryable: attempt < maxAttempts - 1,
|
|
362
|
-
}));
|
|
363
|
-
}, stallMs);
|
|
364
|
-
});
|
|
365
|
-
let fnPromise;
|
|
366
|
-
try {
|
|
367
|
-
fnPromise = fn(controller.signal);
|
|
368
|
-
const result = await Promise.race([fnPromise, stallPromise]);
|
|
369
|
-
clearTimeout(stallTimer);
|
|
370
|
-
return result;
|
|
371
|
-
}
|
|
372
|
-
catch (err) {
|
|
373
|
-
// Suppress unhandled rejection from the losing promise
|
|
374
|
-
// (e.g. fnPromise rejects after stallPromise wins the race)
|
|
375
|
-
fnPromise?.catch(() => { });
|
|
376
|
-
clearTimeout(stallTimer);
|
|
377
|
-
const isStall = err instanceof Error && err.code === 'ESTALLED';
|
|
378
|
-
if (isStall && attempt < maxAttempts - 1) {
|
|
379
|
-
const backoff = calculateBackoff(attempt, DEFAULT_RETRY_OPTIONS);
|
|
380
|
-
mcpLog('warning', `${label} stalled, retrying in ${backoff}ms (attempt ${attempt + 1})`, 'stability');
|
|
381
|
-
await sleep(backoff);
|
|
382
|
-
continue;
|
|
383
|
-
}
|
|
384
|
-
throw err;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
// Should never reach here, but TypeScript needs it
|
|
388
|
-
throw new Error(`${label} failed after ${maxAttempts} stall-protection attempts`);
|
|
389
|
-
}
|
|
390
|
-
//# sourceMappingURL=errors.js.map
|
package/dist/utils/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,+EAA+E;AAC/E,8BAA8B;AAC9B,+EAA+E;AAE/E,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,mBAAmB;IACnB,YAAY,EAAE,cAAc;IAC5B,OAAO,EAAE,SAAS;IAClB,aAAa,EAAE,eAAe;IAC9B,mBAAmB,EAAE,qBAAqB;IAE1C,uBAAuB;IACvB,UAAU,EAAE,YAAY;IACxB,aAAa,EAAE,eAAe;IAC9B,SAAS,EAAE,WAAW;IACtB,cAAc,EAAE,gBAAgB;IAEhC,kBAAkB;IAClB,cAAc,EAAE,gBAAgB;IAChC,WAAW,EAAE,aAAa;IAC1B,aAAa,EAAE,eAAe;CACtB,CAAC;AAIX,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,MAAM,oBAAoB,GAAG,GAAY,CAAC;AAsB1C,MAAM,qBAAqB,GAAiB;IAC1C,UAAU,EAAE,CAAC;IACb,WAAW,EAAE,IAAI;IACjB,UAAU,EAAE,KAAK;IACjB,iBAAiB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GA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K,iBAAiB,WAAW,4BAA4B,CAAC,CAAC;AACpF,CAAC"}
|
package/dist/utils/logger.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP SDK Structured Logging Utility
|
|
3
|
-
*
|
|
4
|
-
* Sends log messages to MCP clients via server.sendLoggingMessage().
|
|
5
|
-
* Falls back to stderr before the server is initialized.
|
|
6
|
-
*/
|
|
7
|
-
import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
8
|
-
export type LogLevel = 'debug' | 'info' | 'warning' | 'error';
|
|
9
|
-
/**
|
|
10
|
-
* Initialize the logger with an MCP server reference.
|
|
11
|
-
* Must be called after server creation and before any tool execution.
|
|
12
|
-
*/
|
|
13
|
-
export declare function initLogger(server: Server): void;
|
|
14
|
-
/**
|
|
15
|
-
* Log message via MCP SDK structured logging.
|
|
16
|
-
* Falls back to stderr if the server isn't initialized yet.
|
|
17
|
-
* @param level - Log level
|
|
18
|
-
* @param message - Message to log
|
|
19
|
-
* @param tool - Tool/logger name for context
|
|
20
|
-
*/
|
|
21
|
-
export declare function mcpLog(level: LogLevel, message: string, tool?: string): void;
|
|
22
|
-
/**
|
|
23
|
-
* Safe log that catches any errors (never crashes)
|
|
24
|
-
* @param level - Log level
|
|
25
|
-
* @param message - Message to log
|
|
26
|
-
* @param tool - Tool name for context
|
|
27
|
-
*/
|
|
28
|
-
export declare function safeLog(level: LogLevel, message: string, tool?: string): void;
|
|
29
|
-
/**
|
|
30
|
-
* Create a bound logger for a specific tool
|
|
31
|
-
*/
|
|
32
|
-
export declare function createToolLogger(tool: string): {
|
|
33
|
-
debug: (msg: string) => void;
|
|
34
|
-
info: (msg: string) => void;
|
|
35
|
-
warning: (msg: string) => void;
|
|
36
|
-
error: (msg: string) => void;
|
|
37
|
-
};
|
|
38
|
-
export type ToolLogger = ReturnType<typeof createToolLogger>;
|
|
39
|
-
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAExE,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;AAI9D;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE/C;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAQ5E;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAM7E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM;iBAE5B,MAAM;gBACP,MAAM;mBACH,MAAM;iBACR,MAAM;EAEtB;AAED,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC"}
|
package/dist/utils/logger.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP SDK Structured Logging Utility
|
|
3
|
-
*
|
|
4
|
-
* Sends log messages to MCP clients via server.sendLoggingMessage().
|
|
5
|
-
* Falls back to stderr before the server is initialized.
|
|
6
|
-
*/
|
|
7
|
-
let serverRef = null;
|
|
8
|
-
/**
|
|
9
|
-
* Initialize the logger with an MCP server reference.
|
|
10
|
-
* Must be called after server creation and before any tool execution.
|
|
11
|
-
*/
|
|
12
|
-
export function initLogger(server) {
|
|
13
|
-
serverRef = server;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Log message via MCP SDK structured logging.
|
|
17
|
-
* Falls back to stderr if the server isn't initialized yet.
|
|
18
|
-
* @param level - Log level
|
|
19
|
-
* @param message - Message to log
|
|
20
|
-
* @param tool - Tool/logger name for context
|
|
21
|
-
*/
|
|
22
|
-
export function mcpLog(level, message, tool) {
|
|
23
|
-
const logger = tool ?? 'research-powerpack';
|
|
24
|
-
if (serverRef) {
|
|
25
|
-
serverRef.sendLoggingMessage({ level, data: message, logger }).catch(() => { });
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
// Fallback to stderr before MCP transport is connected
|
|
29
|
-
console.error(`[${logger}] ${message}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Safe log that catches any errors (never crashes)
|
|
34
|
-
* @param level - Log level
|
|
35
|
-
* @param message - Message to log
|
|
36
|
-
* @param tool - Tool name for context
|
|
37
|
-
*/
|
|
38
|
-
export function safeLog(level, message, tool) {
|
|
39
|
-
try {
|
|
40
|
-
mcpLog(level, message, tool);
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
// Swallow logging errors - never crash
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Create a bound logger for a specific tool
|
|
48
|
-
*/
|
|
49
|
-
export function createToolLogger(tool) {
|
|
50
|
-
return {
|
|
51
|
-
debug: (msg) => safeLog('debug', msg, tool),
|
|
52
|
-
info: (msg) => safeLog('info', msg, tool),
|
|
53
|
-
warning: (msg) => safeLog('warning', msg, tool),
|
|
54
|
-
error: (msg) => safeLog('error', msg, tool),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=logger.js.map
|
package/dist/utils/logger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,IAAI,SAAS,GAAkB,IAAI,CAAC;AAEpC;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc;IACvC,SA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ot":"","sources":["../../src/utils/markdown-formatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAYtD"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Markdown formatting utilities
|
|
3
|
-
*/
|
|
4
|
-
export function removeMetaTags(content) {
|
|
5
|
-
if (!content || typeof content !== 'string') {
|
|
6
|
-
return content;
|
|
7
|
-
}
|
|
8
|
-
const lines = content.split('\n');
|
|
9
|
-
const filteredLines = lines.filter(line => {
|
|
10
|
-
const trimmed = line.trim();
|
|
11
|
-
return !trimmed.startsWith('- Meta:') && !trimmed.startsWith('Meta:');
|
|
12
|
-
});
|
|
13
|
-
return filteredLines.join('\n');
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=markdown-formatter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"markdown-formatter.js","sourceRoot":"","sources":["../../src/utils/markdown-formatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC5C,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;QACxC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC"}
|
package/dist/utils/response.d.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP Response Formatters - 70/20/10 Pattern
|
|
3
|
-
*
|
|
4
|
-
* All tool responses should follow this structure:
|
|
5
|
-
* - 70% Summary: Key insights, status, metrics
|
|
6
|
-
* - 20% Data: Structured results (lists, tables)
|
|
7
|
-
* - 10% Next Steps: Actionable follow-up commands
|
|
8
|
-
*/
|
|
9
|
-
/** Default maximum items to display in list formatting */
|
|
10
|
-
export declare const DEFAULT_MAX_ITEMS: 20;
|
|
11
|
-
/** Maximum snippet length before truncation in URL aggregator output */
|
|
12
|
-
export declare const MAX_SNIPPET_LENGTH: 200;
|
|
13
|
-
export interface SuccessOptions {
|
|
14
|
-
/** Title/header for the response */
|
|
15
|
-
readonly title: string;
|
|
16
|
-
/** Summary section (70% of content) */
|
|
17
|
-
readonly summary: string;
|
|
18
|
-
/** Optional data section (20% of content) */
|
|
19
|
-
readonly data?: string;
|
|
20
|
-
/** Optional next steps (10% of content) */
|
|
21
|
-
readonly nextSteps?: string[];
|
|
22
|
-
/** Optional metadata footer */
|
|
23
|
-
readonly metadata?: Record<string, string | number>;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Format a successful response using 70/20/10 pattern
|
|
27
|
-
*/
|
|
28
|
-
export declare function formatSuccess(opts: SuccessOptions): string;
|
|
29
|
-
export interface ErrorOptions {
|
|
30
|
-
/** Error code (e.g., RATE_LIMITED, TIMEOUT) */
|
|
31
|
-
readonly code: string;
|
|
32
|
-
/** Human-readable error message */
|
|
33
|
-
readonly message: string;
|
|
34
|
-
/** Is this error retryable? */
|
|
35
|
-
readonly retryable?: boolean;
|
|
36
|
-
/** How to fix the error */
|
|
37
|
-
readonly howToFix?: string[];
|
|
38
|
-
/** Alternative actions */
|
|
39
|
-
readonly alternatives?: string[];
|
|
40
|
-
/** Tool name for context */
|
|
41
|
-
readonly toolName?: string;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Format an error response with recovery guidance
|
|
45
|
-
* Designed to keep agents moving — every error includes actionable alternatives
|
|
46
|
-
*/
|
|
47
|
-
export declare function formatError(opts: ErrorOptions): string;
|
|
48
|
-
export interface BatchHeaderOptions {
|
|
49
|
-
/** Batch operation title */
|
|
50
|
-
readonly title: string;
|
|
51
|
-
/** Total items attempted */
|
|
52
|
-
readonly totalItems: number;
|
|
53
|
-
/** Successfully processed count */
|
|
54
|
-
readonly successful: number;
|
|
55
|
-
/** Failed count */
|
|
56
|
-
readonly failed: number;
|
|
57
|
-
/** Optional tokens per item */
|
|
58
|
-
readonly tokensPerItem?: number;
|
|
59
|
-
/** Optional batch count */
|
|
60
|
-
readonly batches?: number;
|
|
61
|
-
/** Extra stats to include */
|
|
62
|
-
readonly extras?: Record<string, string | number>;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Format a batch operation header with stats
|
|
66
|
-
*/
|
|
67
|
-
export declare function formatBatchHeader(opts: BatchHeaderOptions): string;
|
|
68
|
-
export interface ListItem {
|
|
69
|
-
/** Item title/name */
|
|
70
|
-
readonly title: string;
|
|
71
|
-
/** Optional description */
|
|
72
|
-
readonly description?: string;
|
|
73
|
-
/** Optional metadata */
|
|
74
|
-
readonly meta?: string;
|
|
75
|
-
/** Optional URL */
|
|
76
|
-
readonly url?: string;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Format a numbered list with optional metadata
|
|
80
|
-
*/
|
|
81
|
-
export declare function formatList(items: ListItem[], options?: {
|
|
82
|
-
maxItems?: number;
|
|
83
|
-
numbered?: boolean;
|
|
84
|
-
}): string;
|
|
85
|
-
/**
|
|
86
|
-
* Format duration in human-readable form
|
|
87
|
-
*/
|
|
88
|
-
export declare function formatDuration(ms: number): string;
|
|
89
|
-
/**
|
|
90
|
-
* Truncate text to max length with ellipsis
|
|
91
|
-
*/
|
|
92
|
-
export declare function truncateText(text: string, maxLength: number): string;
|
|
93
|
-
//# sourceMappingURL=response.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
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