@j0hanz/superfetch 1.1.2 → 1.1.4
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 +52 -30
- package/dist/config/formatting.d.ts +9 -0
- package/dist/config/formatting.d.ts.map +1 -0
- package/dist/config/formatting.js +11 -0
- package/dist/config/formatting.js.map +1 -0
- package/dist/config/index.d.ts +11 -2
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +35 -13
- package/dist/config/index.js.map +1 -1
- package/dist/config/types/content.d.ts +107 -0
- package/dist/config/types/content.d.ts.map +1 -0
- package/dist/config/types/content.js +2 -0
- package/dist/config/types/content.js.map +1 -0
- package/dist/config/types/runtime.d.ts +78 -0
- package/dist/config/types/runtime.d.ts.map +1 -0
- package/dist/config/types/runtime.js +2 -0
- package/dist/config/types/runtime.js.map +1 -0
- package/dist/config/types/tools.d.ts +99 -0
- package/dist/config/types/tools.d.ts.map +1 -0
- package/dist/config/types/tools.js +2 -0
- package/dist/config/types/tools.js.map +1 -0
- package/dist/config/types.d.ts +3 -297
- package/dist/config/types.d.ts.map +1 -1
- package/dist/http/auth.d.ts +3 -0
- package/dist/http/auth.d.ts.map +1 -0
- package/dist/http/auth.js +34 -0
- package/dist/http/auth.js.map +1 -0
- package/dist/http/cors.d.ts +8 -0
- package/dist/http/cors.d.ts.map +1 -0
- package/dist/http/cors.js +47 -0
- package/dist/http/cors.js.map +1 -0
- package/dist/http/mcp-routes.d.ts +5 -0
- package/dist/http/mcp-routes.d.ts.map +1 -0
- package/dist/http/mcp-routes.js +110 -0
- package/dist/http/mcp-routes.js.map +1 -0
- package/dist/http/mcp-session.d.ts +12 -0
- package/dist/http/mcp-session.d.ts.map +1 -0
- package/dist/http/mcp-session.js +209 -0
- package/dist/http/mcp-session.js.map +1 -0
- package/dist/http/mcp-validation.d.ts +3 -0
- package/dist/http/mcp-validation.d.ts.map +1 -0
- package/dist/http/mcp-validation.js +34 -0
- package/dist/http/mcp-validation.js.map +1 -0
- package/dist/http/rate-limit.d.ts +13 -0
- package/dist/http/rate-limit.d.ts.map +1 -0
- package/dist/http/rate-limit.js +91 -0
- package/dist/http/rate-limit.js.map +1 -0
- package/dist/http/server.d.ts +4 -0
- package/dist/http/server.d.ts.map +1 -0
- package/dist/http/server.js +183 -0
- package/dist/http/server.js.map +1 -0
- package/dist/http/sessions.d.ts +15 -0
- package/dist/http/sessions.d.ts.map +1 -0
- package/dist/http/sessions.js +64 -0
- package/dist/http/sessions.js.map +1 -0
- package/dist/index.js +26 -341
- package/dist/index.js.map +1 -1
- package/dist/middleware/error-handler.d.ts +2 -2
- package/dist/middleware/error-handler.d.ts.map +1 -1
- package/dist/middleware/error-handler.js +46 -15
- package/dist/middleware/error-handler.js.map +1 -1
- package/dist/resources/cached-content.d.ts.map +1 -1
- package/dist/resources/cached-content.js +104 -44
- package/dist/resources/cached-content.js.map +1 -1
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/index.js +77 -69
- package/dist/resources/index.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +9 -3
- package/dist/server.js.map +1 -1
- package/dist/services/cache.d.ts +13 -1
- package/dist/services/cache.d.ts.map +1 -1
- package/dist/services/cache.js +89 -16
- package/dist/services/cache.js.map +1 -1
- package/dist/services/context.d.ts +1 -1
- package/dist/services/context.d.ts.map +1 -1
- package/dist/services/context.js +1 -1
- package/dist/services/context.js.map +1 -1
- package/dist/services/extractor.d.ts.map +1 -1
- package/dist/services/extractor.js +122 -87
- package/dist/services/extractor.js.map +1 -1
- package/dist/services/fetcher/agents.d.ts +4 -0
- package/dist/services/fetcher/agents.d.ts.map +1 -0
- package/dist/services/fetcher/agents.js +111 -0
- package/dist/services/fetcher/agents.js.map +1 -0
- package/dist/services/fetcher/errors.d.ts +5 -0
- package/dist/services/fetcher/errors.d.ts.map +1 -0
- package/dist/services/fetcher/errors.js +71 -0
- package/dist/services/fetcher/errors.js.map +1 -0
- package/dist/services/fetcher/headers.d.ts +2 -0
- package/dist/services/fetcher/headers.d.ts.map +1 -0
- package/dist/services/fetcher/headers.js +28 -0
- package/dist/services/fetcher/headers.js.map +1 -0
- package/dist/services/fetcher/interceptors.d.ts +10 -0
- package/dist/services/fetcher/interceptors.d.ts.map +1 -0
- package/dist/services/fetcher/interceptors.js +82 -0
- package/dist/services/fetcher/interceptors.js.map +1 -0
- package/dist/services/fetcher/redirects.d.ts +6 -0
- package/dist/services/fetcher/redirects.d.ts.map +1 -0
- package/dist/services/fetcher/redirects.js +67 -0
- package/dist/services/fetcher/redirects.js.map +1 -0
- package/dist/services/fetcher/response.d.ts +5 -0
- package/dist/services/fetcher/response.d.ts.map +1 -0
- package/dist/services/fetcher/response.js +39 -0
- package/dist/services/fetcher/response.js.map +1 -0
- package/dist/services/fetcher/retry-policy.d.ts +28 -0
- package/dist/services/fetcher/retry-policy.d.ts.map +1 -0
- package/dist/services/fetcher/retry-policy.js +138 -0
- package/dist/services/fetcher/retry-policy.js.map +1 -0
- package/dist/services/fetcher.d.ts +2 -1
- package/dist/services/fetcher.d.ts.map +1 -1
- package/dist/services/fetcher.js +62 -315
- package/dist/services/fetcher.js.map +1 -1
- package/dist/services/logger.js +4 -4
- package/dist/services/logger.js.map +1 -1
- package/dist/services/parser.d.ts +1 -0
- package/dist/services/parser.d.ts.map +1 -1
- package/dist/services/parser.js +55 -35
- package/dist/services/parser.js.map +1 -1
- package/dist/tools/handlers/fetch-links/link-extractor.d.ts +4 -0
- package/dist/tools/handlers/fetch-links/link-extractor.d.ts.map +1 -0
- package/dist/tools/handlers/fetch-links/link-extractor.js +163 -0
- package/dist/tools/handlers/fetch-links/link-extractor.js.map +1 -0
- package/dist/tools/handlers/fetch-links.tool.d.ts.map +1 -1
- package/dist/tools/handlers/fetch-links.tool.js +78 -116
- package/dist/tools/handlers/fetch-links.tool.js.map +1 -1
- package/dist/tools/handlers/fetch-markdown.tool.d.ts +3 -13
- package/dist/tools/handlers/fetch-markdown.tool.d.ts.map +1 -1
- package/dist/tools/handlers/fetch-markdown.tool.js +74 -83
- package/dist/tools/handlers/fetch-markdown.tool.js.map +1 -1
- package/dist/tools/handlers/fetch-single.shared.d.ts +26 -0
- package/dist/tools/handlers/fetch-single.shared.d.ts.map +1 -0
- package/dist/tools/handlers/fetch-single.shared.js +49 -0
- package/dist/tools/handlers/fetch-single.shared.js.map +1 -0
- package/dist/tools/handlers/fetch-url.tool.d.ts.map +1 -1
- package/dist/tools/handlers/fetch-url.tool.js +82 -54
- package/dist/tools/handlers/fetch-url.tool.js.map +1 -1
- package/dist/tools/handlers/fetch-urls/processor.d.ts +13 -0
- package/dist/tools/handlers/fetch-urls/processor.d.ts.map +1 -0
- package/dist/tools/handlers/fetch-urls/processor.js +153 -0
- package/dist/tools/handlers/fetch-urls/processor.js.map +1 -0
- package/dist/tools/handlers/fetch-urls/response.d.ts +3 -0
- package/dist/tools/handlers/fetch-urls/response.d.ts.map +1 -0
- package/dist/tools/handlers/fetch-urls/response.js +58 -0
- package/dist/tools/handlers/fetch-urls/response.js.map +1 -0
- package/dist/tools/handlers/fetch-urls/validation.d.ts +6 -0
- package/dist/tools/handlers/fetch-urls/validation.d.ts.map +1 -0
- package/dist/tools/handlers/fetch-urls/validation.js +18 -0
- package/dist/tools/handlers/fetch-urls/validation.js.map +1 -0
- package/dist/tools/handlers/fetch-urls.tool.d.ts.map +1 -1
- package/dist/tools/handlers/fetch-urls.tool.js +104 -202
- package/dist/tools/handlers/fetch-urls.tool.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +36 -237
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/schemas.d.ts +357 -0
- package/dist/tools/schemas.d.ts.map +1 -0
- package/dist/tools/schemas.js +272 -0
- package/dist/tools/schemas.js.map +1 -0
- package/dist/tools/utils/cache-vary.d.ts +3 -0
- package/dist/tools/utils/cache-vary.d.ts.map +1 -0
- package/dist/tools/utils/cache-vary.js +44 -0
- package/dist/tools/utils/cache-vary.js.map +1 -0
- package/dist/tools/utils/common.d.ts +2 -2
- package/dist/tools/utils/common.d.ts.map +1 -1
- package/dist/tools/utils/common.js +5 -1
- package/dist/tools/utils/common.js.map +1 -1
- package/dist/tools/utils/content-transform.d.ts +16 -0
- package/dist/tools/utils/content-transform.d.ts.map +1 -0
- package/dist/tools/utils/content-transform.js +49 -0
- package/dist/tools/utils/content-transform.js.map +1 -0
- package/dist/tools/utils/fetch-pipeline.d.ts.map +1 -1
- package/dist/tools/utils/fetch-pipeline.js +32 -18
- package/dist/tools/utils/fetch-pipeline.js.map +1 -1
- package/dist/tools/utils/inline-content.d.ts +11 -0
- package/dist/tools/utils/inline-content.d.ts.map +1 -0
- package/dist/tools/utils/inline-content.js +39 -0
- package/dist/tools/utils/inline-content.js.map +1 -0
- package/dist/tools/utils/markdown-toc.d.ts +3 -0
- package/dist/tools/utils/markdown-toc.d.ts.map +1 -0
- package/dist/tools/utils/markdown-toc.js +35 -0
- package/dist/tools/utils/markdown-toc.js.map +1 -0
- package/dist/tools/utils/tool-response.d.ts +9 -0
- package/dist/tools/utils/tool-response.d.ts.map +1 -0
- package/dist/tools/utils/tool-response.js +19 -0
- package/dist/tools/utils/tool-response.js.map +1 -0
- package/dist/transformers/jsonl.transformer.d.ts.map +1 -1
- package/dist/transformers/jsonl.transformer.js +51 -28
- package/dist/transformers/jsonl.transformer.js.map +1 -1
- package/dist/transformers/markdown.transformer.d.ts.map +1 -1
- package/dist/transformers/markdown.transformer.js +82 -111
- package/dist/transformers/markdown.transformer.js.map +1 -1
- package/dist/utils/header-normalizer.d.ts +5 -0
- package/dist/utils/header-normalizer.d.ts.map +1 -0
- package/dist/utils/header-normalizer.js +25 -0
- package/dist/utils/header-normalizer.js.map +1 -0
- package/dist/utils/tool-error-handler.d.ts +1 -0
- package/dist/utils/tool-error-handler.d.ts.map +1 -1
- package/dist/utils/tool-error-handler.js +29 -1
- package/dist/utils/tool-error-handler.js.map +1 -1
- package/dist/utils/url-validator.d.ts +0 -3
- package/dist/utils/url-validator.d.ts.map +1 -1
- package/dist/utils/url-validator.js +97 -18
- package/dist/utils/url-validator.js.map +1 -1
- package/package.json +11 -6
|
@@ -1,222 +1,124 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { extractContent } from '../../services/extractor.js';
|
|
3
|
-
import { fetchUrlWithRetry } from '../../services/fetcher.js';
|
|
4
|
-
import { logDebug, logError, logWarn } from '../../services/logger.js';
|
|
5
|
-
import { parseHtml } from '../../services/parser.js';
|
|
1
|
+
import { logDebug, logError } from '../../services/logger.js';
|
|
6
2
|
import { createToolErrorResponse } from '../../utils/tool-error-handler.js';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { htmlToMarkdown } from '../../transformers/markdown.transformer.js';
|
|
11
|
-
const MAX_URLS_PER_BATCH = 10;
|
|
12
|
-
const DEFAULT_CONCURRENCY = 3;
|
|
13
|
-
const MAX_CONCURRENCY = 5;
|
|
3
|
+
import { processSingleUrl, } from './fetch-urls/processor.js';
|
|
4
|
+
import { createBatchResponse } from './fetch-urls/response.js';
|
|
5
|
+
import { DEFAULT_CONCURRENCY, MAX_CONCURRENCY, validateBatchInput, } from './fetch-urls/validation.js';
|
|
14
6
|
export const FETCH_URLS_TOOL_NAME = 'fetch-urls';
|
|
15
7
|
export const FETCH_URLS_TOOL_DESCRIPTION = 'Fetches multiple URLs in parallel and converts them to AI-readable format (JSONL or Markdown). Supports concurrency control and continues on individual failures.';
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
total: results.length,
|
|
19
|
-
successful: results.filter((result) => result.success).length,
|
|
20
|
-
failed: results.filter((result) => !result.success).length,
|
|
21
|
-
cached: results.filter((result) => result.cached).length,
|
|
22
|
-
totalContentBlocks: results.reduce((sum, result) => sum + (result.contentBlocks ?? 0), 0),
|
|
23
|
-
};
|
|
24
|
-
const structuredContent = {
|
|
25
|
-
results,
|
|
26
|
-
summary,
|
|
27
|
-
fetchedAt: new Date().toISOString(),
|
|
28
|
-
};
|
|
29
|
-
return {
|
|
30
|
-
content: [
|
|
31
|
-
{
|
|
32
|
-
type: 'text',
|
|
33
|
-
text: JSON.stringify(structuredContent, null, 2),
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
structuredContent,
|
|
37
|
-
};
|
|
8
|
+
function extractRejectionMessage({ reason }) {
|
|
9
|
+
return toErrorMessage(reason);
|
|
38
10
|
}
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
logDebug('Batch cache hit', { url: normalizedUrl });
|
|
48
|
-
return {
|
|
49
|
-
url: normalizedUrl,
|
|
50
|
-
success: true,
|
|
51
|
-
content: cached.content,
|
|
52
|
-
cached: true,
|
|
53
|
-
};
|
|
11
|
+
function toErrorMessage(reason) {
|
|
12
|
+
if (reason instanceof Error)
|
|
13
|
+
return reason.message;
|
|
14
|
+
if (typeof reason === 'string')
|
|
15
|
+
return reason;
|
|
16
|
+
if (hasMessage(reason))
|
|
17
|
+
return reason.message;
|
|
18
|
+
return 'Unknown error';
|
|
54
19
|
}
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
content: htmlToMarkdown(html, metadata),
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
const blocks = parseHtml(html);
|
|
62
|
-
return {
|
|
63
|
-
content: toJsonl(blocks, metadata),
|
|
64
|
-
contentBlocks: blocks.length,
|
|
65
|
-
};
|
|
20
|
+
function isRecord(value) {
|
|
21
|
+
return value !== null && typeof value === 'object';
|
|
66
22
|
}
|
|
67
|
-
function
|
|
68
|
-
if (!
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
};
|
|
23
|
+
function hasMessage(value) {
|
|
24
|
+
if (!isRecord(value))
|
|
25
|
+
return false;
|
|
26
|
+
return typeof value.message === 'string';
|
|
27
|
+
}
|
|
28
|
+
function normalizeConcurrency(input, urlCount) {
|
|
29
|
+
const requested = input.concurrency ?? DEFAULT_CONCURRENCY;
|
|
30
|
+
return Math.min(Math.max(1, requested), MAX_CONCURRENCY, urlCount);
|
|
31
|
+
}
|
|
32
|
+
async function processBatch(urls, options, batchIndex, total) {
|
|
33
|
+
logDebug('Processing batch', {
|
|
34
|
+
batch: batchIndex,
|
|
35
|
+
urls: urls.length,
|
|
36
|
+
total,
|
|
37
|
+
});
|
|
38
|
+
const tasks = urls.map((url) => processSingleUrl(url, options));
|
|
39
|
+
return Promise.allSettled(tasks);
|
|
85
40
|
}
|
|
86
|
-
async function
|
|
41
|
+
export async function fetchUrlsToolHandler(input) {
|
|
87
42
|
try {
|
|
88
|
-
|
|
89
|
-
const cachedResult = attemptCacheRetrievalForUrl(normalizedUrl, options.format);
|
|
90
|
-
if (cachedResult)
|
|
91
|
-
return cachedResult;
|
|
92
|
-
const html = await fetchUrlWithRetry(normalizedUrl, options.requestOptions, options.maxRetries);
|
|
93
|
-
const { sourceHtml, title, metadata } = processContentExtraction(html, normalizedUrl, options);
|
|
94
|
-
const { content, contentBlocks } = transformContentForFormat(sourceHtml, normalizedUrl, metadata, options.format);
|
|
95
|
-
const { content: finalContent } = enforceContentLengthLimit(content, options.maxContentLength);
|
|
96
|
-
const cacheNamespace = options.format === 'markdown' ? 'markdown' : 'url';
|
|
97
|
-
const cacheKey = cache.createCacheKey(cacheNamespace, normalizedUrl);
|
|
98
|
-
if (cacheKey) {
|
|
99
|
-
cache.set(cacheKey, finalContent);
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
url: normalizedUrl,
|
|
103
|
-
success: true,
|
|
104
|
-
title,
|
|
105
|
-
content: finalContent,
|
|
106
|
-
contentBlocks,
|
|
107
|
-
cached: false,
|
|
108
|
-
};
|
|
43
|
+
return await executeFetchUrls(input);
|
|
109
44
|
}
|
|
110
45
|
catch (error) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
'code' in error &&
|
|
114
|
-
typeof error.code === 'string'
|
|
115
|
-
? error.code
|
|
116
|
-
: 'FETCH_ERROR';
|
|
117
|
-
logWarn('Batch URL processing failed', { url, error: errorMessage });
|
|
118
|
-
return {
|
|
119
|
-
url,
|
|
120
|
-
success: false,
|
|
121
|
-
cached: false,
|
|
122
|
-
error: errorMessage,
|
|
123
|
-
errorCode,
|
|
124
|
-
};
|
|
46
|
+
logError('fetch-urls tool error', error instanceof Error ? error : undefined);
|
|
47
|
+
return createToolErrorResponse(error instanceof Error ? error.message : 'Failed to fetch URLs', '', 'BATCH_ERROR');
|
|
125
48
|
}
|
|
126
49
|
}
|
|
127
|
-
function
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
50
|
+
async function executeFetchUrls(input) {
|
|
51
|
+
const validUrls = resolveValidUrls(input);
|
|
52
|
+
if (!Array.isArray(validUrls))
|
|
53
|
+
return validUrls;
|
|
54
|
+
const batchConfig = buildBatchConfig(input, validUrls.length);
|
|
55
|
+
logDebug('Starting batch URL fetch', {
|
|
56
|
+
urlCount: validUrls.length,
|
|
57
|
+
concurrency: batchConfig.concurrency,
|
|
58
|
+
format: batchConfig.format,
|
|
59
|
+
});
|
|
60
|
+
const processOptions = buildSingleUrlOptions(input, batchConfig.format);
|
|
61
|
+
const results = await collectBatchResults(validUrls, processOptions, batchConfig.concurrency, batchConfig.continueOnError);
|
|
62
|
+
if (!batchConfig.continueOnError) {
|
|
63
|
+
const failureResponse = buildBatchFailure(results);
|
|
64
|
+
if (failureResponse)
|
|
65
|
+
return failureResponse;
|
|
133
66
|
}
|
|
134
|
-
|
|
135
|
-
typeof reason === 'object' &&
|
|
136
|
-
'message' in reason &&
|
|
137
|
-
typeof reason.message === 'string') {
|
|
138
|
-
const msg = reason.message;
|
|
139
|
-
return msg;
|
|
140
|
-
}
|
|
141
|
-
return 'Unknown error';
|
|
67
|
+
return createBatchResponse(results);
|
|
142
68
|
}
|
|
143
|
-
function
|
|
144
|
-
|
|
145
|
-
return createToolErrorResponse('At least one URL is required', '', 'VALIDATION_ERROR');
|
|
146
|
-
}
|
|
147
|
-
if (input.urls.length > MAX_URLS_PER_BATCH) {
|
|
148
|
-
return createToolErrorResponse(`Maximum ${MAX_URLS_PER_BATCH} URLs allowed per batch`, '', 'VALIDATION_ERROR');
|
|
149
|
-
}
|
|
150
|
-
const validUrls = input.urls.filter((url) => typeof url === 'string' && url.trim().length > 0);
|
|
151
|
-
if (validUrls.length === 0) {
|
|
152
|
-
return createToolErrorResponse('No valid URLs provided', '', 'VALIDATION_ERROR');
|
|
153
|
-
}
|
|
154
|
-
return validUrls;
|
|
69
|
+
function resolveValidUrls(input) {
|
|
70
|
+
return validateBatchInput(input);
|
|
155
71
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
72
|
+
function buildBatchConfig(input, urlCount) {
|
|
73
|
+
return {
|
|
74
|
+
concurrency: normalizeConcurrency(input, urlCount),
|
|
75
|
+
continueOnError: input.continueOnError ?? true,
|
|
76
|
+
format: input.format ?? 'jsonl',
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function buildSingleUrlOptions(input, format) {
|
|
80
|
+
return {
|
|
81
|
+
extractMainContent: input.extractMainContent ?? true,
|
|
82
|
+
includeMetadata: input.includeMetadata ?? true,
|
|
83
|
+
maxContentLength: input.maxContentLength,
|
|
84
|
+
format,
|
|
85
|
+
requestOptions: {
|
|
86
|
+
customHeaders: input.customHeaders,
|
|
87
|
+
timeout: input.timeout,
|
|
88
|
+
},
|
|
89
|
+
maxRetries: input.retries,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function mapSettledResults(batch, settledResults) {
|
|
93
|
+
return settledResults.map((result, index) => result.status === 'fulfilled'
|
|
94
|
+
? result.value
|
|
95
|
+
: {
|
|
96
|
+
url: batch[index] ?? 'unknown',
|
|
97
|
+
success: false,
|
|
98
|
+
cached: false,
|
|
99
|
+
error: extractRejectionMessage(result),
|
|
100
|
+
errorCode: 'PROMISE_REJECTED',
|
|
170
101
|
});
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
// Process URLs in batches using native Promise.allSettled
|
|
183
|
-
const results = [];
|
|
184
|
-
const batchSize = Math.min(concurrency, validUrls.length);
|
|
185
|
-
for (let i = 0; i < validUrls.length; i += batchSize) {
|
|
186
|
-
const batch = validUrls.slice(i, i + batchSize);
|
|
187
|
-
const batchTasks = batch.map((url) => processSingleUrl(url, processOptions));
|
|
188
|
-
logDebug('Processing batch', {
|
|
189
|
-
batch: i / batchSize + 1,
|
|
190
|
-
urls: batch.length,
|
|
191
|
-
total: validUrls.length,
|
|
192
|
-
});
|
|
193
|
-
const settledResults = await Promise.allSettled(batchTasks);
|
|
194
|
-
const batchResults = settledResults.map((result, index) => {
|
|
195
|
-
if (result.status === 'fulfilled') {
|
|
196
|
-
return result.value;
|
|
197
|
-
}
|
|
198
|
-
return {
|
|
199
|
-
url: batch[index] ?? 'unknown',
|
|
200
|
-
success: false,
|
|
201
|
-
cached: false,
|
|
202
|
-
error: extractRejectionMessage(result),
|
|
203
|
-
errorCode: 'PROMISE_REJECTED',
|
|
204
|
-
};
|
|
205
|
-
});
|
|
206
|
-
results.push(...batchResults);
|
|
207
|
-
}
|
|
208
|
-
if (!continueOnError) {
|
|
209
|
-
const firstError = results.find((result) => !result.success);
|
|
210
|
-
if (firstError && !firstError.success) {
|
|
211
|
-
const errorMsg = firstError.error ?? 'Unknown error';
|
|
212
|
-
return createToolErrorResponse(`Batch failed: ${errorMsg}`, firstError.url, firstError.errorCode ?? 'BATCH_ERROR');
|
|
213
|
-
}
|
|
102
|
+
}
|
|
103
|
+
async function collectBatchResults(validUrls, processOptions, concurrency, continueOnError) {
|
|
104
|
+
const results = [];
|
|
105
|
+
const batchSize = Math.min(concurrency, validUrls.length);
|
|
106
|
+
for (let i = 0; i < validUrls.length; i += batchSize) {
|
|
107
|
+
const batch = validUrls.slice(i, i + batchSize);
|
|
108
|
+
const settledResults = await processBatch(batch, processOptions, i / batchSize + 1, validUrls.length);
|
|
109
|
+
const mapped = mapSettledResults(batch, settledResults);
|
|
110
|
+
results.push(...mapped);
|
|
111
|
+
if (!continueOnError && mapped.some((result) => !result.success)) {
|
|
112
|
+
break;
|
|
214
113
|
}
|
|
215
|
-
return createBatchResponse(results);
|
|
216
|
-
}
|
|
217
|
-
catch (error) {
|
|
218
|
-
logError('fetch-urls tool error', error instanceof Error ? error : undefined);
|
|
219
|
-
return createToolErrorResponse(error instanceof Error ? error.message : 'Failed to fetch URLs', '', 'BATCH_ERROR');
|
|
220
114
|
}
|
|
115
|
+
return results;
|
|
116
|
+
}
|
|
117
|
+
function buildBatchFailure(results) {
|
|
118
|
+
const firstError = results.find((result) => !result.success);
|
|
119
|
+
if (!firstError)
|
|
120
|
+
return null;
|
|
121
|
+
const errorMsg = firstError.error ?? 'Unknown error';
|
|
122
|
+
return createToolErrorResponse(`Batch failed: ${errorMsg}`, firstError.url, firstError.errorCode ?? 'BATCH_ERROR');
|
|
221
123
|
}
|
|
222
124
|
//# sourceMappingURL=fetch-urls.tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-urls.tool.js","sourceRoot":"","sources":["../../../src/tools/handlers/fetch-urls.tool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetch-urls.tool.js","sourceRoot":"","sources":["../../../src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IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAyB;IAClD,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC7D,IAAI,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC;IAC7B,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,IAAI,eAAe,CAAC;IACrD,OAAO,uBAAuB,CAC5B,iBAAiB,QAAQ,EAAE,EAC3B,UAAU,CAAC,GAAG,EACd,UAAU,CAAC,SAAS,IAAI,aAAa,CACtC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAoEzE,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAarD"}
|