research-powerpack-mcp 3.4.7 → 3.5.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 +63 -655
- package/dist/clients/reddit.d.ts.map +1 -1
- package/dist/clients/reddit.js +23 -35
- package/dist/clients/reddit.js.map +1 -1
- package/dist/clients/scraper.d.ts +1 -6
- package/dist/clients/scraper.d.ts.map +1 -1
- package/dist/clients/scraper.js +33 -69
- package/dist/clients/scraper.js.map +1 -1
- package/dist/config/env.d.ts +75 -0
- package/dist/config/env.d.ts.map +1 -0
- package/dist/config/env.js +87 -0
- package/dist/config/env.js.map +1 -0
- package/dist/config/yaml/tools-enhanced.yaml +0 -0
- package/dist/index.js +85 -25
- package/dist/index.js.map +1 -1
- package/dist/services/llm-processor.js +0 -25
- package/dist/services/llm-processor.js.map +1 -1
- package/dist/tools/reddit.d.ts.map +1 -1
- package/dist/tools/reddit.js +77 -29
- package/dist/tools/reddit.js.map +1 -1
- package/dist/tools/research.d.ts +2 -6
- package/dist/tools/research.d.ts.map +1 -1
- package/dist/tools/research.js +60 -47
- package/dist/tools/research.js.map +1 -1
- package/dist/tools/scrape.d.ts +1 -5
- package/dist/tools/scrape.d.ts.map +1 -1
- package/dist/tools/scrape.js +107 -64
- package/dist/tools/scrape.js.map +1 -1
- package/dist/tools/search.d.ts +1 -5
- package/dist/tools/search.d.ts.map +1 -1
- package/dist/tools/search.js +26 -16
- package/dist/tools/search.js.map +1 -1
- package/dist/tools/utils.d.ts +20 -59
- package/dist/tools/utils.d.ts.map +1 -1
- package/dist/tools/utils.js +25 -61
- package/dist/tools/utils.js.map +1 -1
- package/dist/utils/logger.d.ts +36 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +40 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/response.d.ts +101 -0
- package/dist/utils/response.d.ts.map +1 -0
- package/dist/utils/response.js +183 -0
- package/dist/utils/response.js.map +1 -0
- package/package.json +8 -2
package/dist/tools/research.js
CHANGED
|
@@ -6,28 +6,10 @@ import { ResearchClient } from '../clients/research.js';
|
|
|
6
6
|
import { FileAttachmentService } from '../services/file-attachment.js';
|
|
7
7
|
import { RESEARCH } from '../config/index.js';
|
|
8
8
|
import { classifyError } from '../utils/errors.js';
|
|
9
|
+
import { safeLog, calculateTokenAllocation, TOKEN_BUDGETS, formatSuccess, formatError, formatBatchHeader, formatDuration, } from './utils.js';
|
|
9
10
|
// Constants
|
|
10
|
-
const TOTAL_TOKEN_BUDGET = 32000;
|
|
11
11
|
const MIN_QUESTIONS = 1; // Allow single question for flexibility
|
|
12
12
|
const MAX_QUESTIONS = 10;
|
|
13
|
-
function calculateTokenAllocation(questionCount) {
|
|
14
|
-
if (questionCount <= 0)
|
|
15
|
-
return TOTAL_TOKEN_BUDGET;
|
|
16
|
-
return Math.floor(TOTAL_TOKEN_BUDGET / questionCount);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Safe logger wrapper - NEVER throws
|
|
20
|
-
*/
|
|
21
|
-
async function safeLog(logger, sessionId, level, message) {
|
|
22
|
-
if (!logger || !sessionId)
|
|
23
|
-
return;
|
|
24
|
-
try {
|
|
25
|
-
await logger(level, message, sessionId);
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
console.error(`[Research Tool] Logger failed: ${message}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
13
|
const SYSTEM_PROMPT = `You are an expert research consultant. Provide evidence-based, multi-perspective analysis.
|
|
32
14
|
|
|
33
15
|
METHODOLOGY:
|
|
@@ -51,21 +33,29 @@ Be dense with insights, light on filler. Use examples and citations.`;
|
|
|
51
33
|
export async function handleDeepResearch(params, options = {}) {
|
|
52
34
|
const { sessionId, logger } = options;
|
|
53
35
|
const questions = params.questions || [];
|
|
54
|
-
|
|
55
|
-
|
|
36
|
+
const startTime = Date.now();
|
|
37
|
+
// Helper to create error response using standardized formatter
|
|
38
|
+
const createErrorResponse = (message, code = 'RESEARCH_ERROR') => {
|
|
39
|
+
const errorContent = formatError({
|
|
40
|
+
code,
|
|
41
|
+
message,
|
|
42
|
+
retryable: false,
|
|
43
|
+
toolName: 'Deep Research',
|
|
44
|
+
});
|
|
56
45
|
return {
|
|
57
|
-
content:
|
|
58
|
-
structuredContent: { error: true, message
|
|
46
|
+
content: errorContent,
|
|
47
|
+
structuredContent: { error: true, message },
|
|
59
48
|
};
|
|
49
|
+
};
|
|
50
|
+
// Validation
|
|
51
|
+
if (questions.length < MIN_QUESTIONS) {
|
|
52
|
+
return createErrorResponse(`Minimum ${MIN_QUESTIONS} research question(s) required. Received: ${questions.length}`, 'INVALID_INPUT');
|
|
60
53
|
}
|
|
61
54
|
if (questions.length > MAX_QUESTIONS) {
|
|
62
|
-
return {
|
|
63
|
-
content: `# ❌ Error\n\nMaximum ${MAX_QUESTIONS} research questions allowed. Received: ${questions.length}`,
|
|
64
|
-
structuredContent: { error: true, message: `Maximum ${MAX_QUESTIONS} questions allowed` },
|
|
65
|
-
};
|
|
55
|
+
return createErrorResponse(`Maximum ${MAX_QUESTIONS} research questions allowed. Received: ${questions.length}`, 'INVALID_INPUT');
|
|
66
56
|
}
|
|
67
|
-
const tokensPerQuestion = calculateTokenAllocation(questions.length);
|
|
68
|
-
await safeLog(logger, sessionId, 'info', `Starting batch research: ${questions.length} questions, ${tokensPerQuestion.toLocaleString()} tokens/question
|
|
57
|
+
const tokensPerQuestion = calculateTokenAllocation(questions.length, TOKEN_BUDGETS.RESEARCH);
|
|
58
|
+
await safeLog(logger, sessionId, 'info', `Starting batch research: ${questions.length} questions, ${tokensPerQuestion.toLocaleString()} tokens/question`, 'Research');
|
|
69
59
|
// Initialize client safely
|
|
70
60
|
let client;
|
|
71
61
|
try {
|
|
@@ -73,10 +63,7 @@ export async function handleDeepResearch(params, options = {}) {
|
|
|
73
63
|
}
|
|
74
64
|
catch (error) {
|
|
75
65
|
const err = classifyError(error);
|
|
76
|
-
return {
|
|
77
|
-
content: `# ❌ Error\n\nFailed to initialize research client: ${err.message}`,
|
|
78
|
-
structuredContent: { error: true, message: `Failed to initialize: ${err.message}` },
|
|
79
|
-
};
|
|
66
|
+
return createErrorResponse(`Failed to initialize research client: ${err.message}`, 'INIT_ERROR');
|
|
80
67
|
}
|
|
81
68
|
const fileService = new FileAttachmentService();
|
|
82
69
|
const results = [];
|
|
@@ -133,37 +120,63 @@ export async function handleDeepResearch(params, options = {}) {
|
|
|
133
120
|
});
|
|
134
121
|
const allResults = await Promise.all(researchPromises);
|
|
135
122
|
results.push(...allResults);
|
|
136
|
-
|
|
123
|
+
const executionTime = Date.now() - startTime;
|
|
124
|
+
// Build statistics
|
|
137
125
|
const successful = results.filter(r => r.success);
|
|
138
126
|
const failed = results.filter(r => !r.success);
|
|
139
127
|
const totalTokens = successful.reduce((sum, r) => sum + (r.tokensUsed || 0), 0);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
128
|
+
await safeLog(logger, sessionId, 'info', `Research completed: ${successful.length}/${questions.length} successful, ${totalTokens.toLocaleString()} tokens`, 'Research');
|
|
129
|
+
// Build header using standardized formatter
|
|
130
|
+
const headerInfo = formatBatchHeader({
|
|
131
|
+
title: 'Deep Research Results',
|
|
132
|
+
totalItems: questions.length,
|
|
133
|
+
successful: successful.length,
|
|
134
|
+
failed: failed.length,
|
|
135
|
+
tokensPerItem: tokensPerQuestion,
|
|
136
|
+
totalBudget: TOKEN_BUDGETS.RESEARCH,
|
|
137
|
+
extras: [`📊 ${totalTokens.toLocaleString()} tokens used`],
|
|
138
|
+
});
|
|
139
|
+
// Build data section with individual results
|
|
140
|
+
const dataSection = results.map((r, i) => {
|
|
141
|
+
const questionPreview = r.question.substring(0, 100) + (r.question.length > 100 ? '...' : '');
|
|
142
|
+
let section = `## Question ${i + 1}: ${questionPreview}\n\n`;
|
|
147
143
|
if (r.success) {
|
|
148
|
-
|
|
144
|
+
section += r.content + '\n\n';
|
|
149
145
|
if (r.tokensUsed) {
|
|
150
|
-
|
|
146
|
+
section += `_Tokens used: ${r.tokensUsed.toLocaleString()}_`;
|
|
151
147
|
}
|
|
152
148
|
}
|
|
153
149
|
else {
|
|
154
|
-
|
|
150
|
+
section += `**❌ Error:** ${r.error}`;
|
|
155
151
|
}
|
|
156
|
-
|
|
152
|
+
return section;
|
|
153
|
+
}).join('\n\n---\n\n');
|
|
154
|
+
// Build next steps
|
|
155
|
+
const nextSteps = [];
|
|
156
|
+
if (successful.length > 0) {
|
|
157
|
+
nextSteps.push('Follow up with more specific questions on interesting findings');
|
|
158
|
+
nextSteps.push('Use `web_search()` to find additional sources on key topics');
|
|
159
|
+
nextSteps.push('Use `scrape_links()` to get full content from cited URLs');
|
|
157
160
|
}
|
|
158
|
-
|
|
161
|
+
if (failed.length > 0) {
|
|
162
|
+
nextSteps.push('Retry failed questions with simpler phrasing');
|
|
163
|
+
nextSteps.push('Check API quota if multiple failures occurred');
|
|
164
|
+
}
|
|
165
|
+
const formattedContent = formatSuccess({
|
|
166
|
+
title: `Deep Research Results (${questions.length} questions)`,
|
|
167
|
+
summary: `${headerInfo}\n\n**Execution Time:** ${formatDuration(executionTime)}`,
|
|
168
|
+
data: dataSection,
|
|
169
|
+
nextSteps,
|
|
170
|
+
});
|
|
159
171
|
return {
|
|
160
|
-
content:
|
|
172
|
+
content: formattedContent,
|
|
161
173
|
structuredContent: {
|
|
162
174
|
totalQuestions: questions.length,
|
|
163
175
|
successful: successful.length,
|
|
164
176
|
failed: failed.length,
|
|
165
177
|
tokensPerQuestion,
|
|
166
178
|
totalTokensUsed: totalTokens,
|
|
179
|
+
executionTimeMs: executionTime,
|
|
167
180
|
results,
|
|
168
181
|
},
|
|
169
182
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"research.js","sourceRoot":"","sources":["../../src/tools/research.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"research.js","s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AI,CAAC,+CAA+C,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,gBAAgB,GAAG,aAAa,CAAC;QACrC,KAAK,EAAE,0BAA0B,SAAS,CAAC,MAAM,aAAa;QAC9D,OAAO,EAAE,GAAG,UAAU,2BAA2B,cAAc,CAAC,aAAa,CAAC,EAAE;QAChF,IAAI,EAAE,WAAW;QACjB,SAAS;KACV,CAAC,CAAC;IAEH,OAAO;QACL,OAAO,EAAE,gBAAgB;QACzB,iBAAiB,EAAE;YACjB,cAAc,EAAE,SAAS,CAAC,MAAM;YAChC,UAAU,EAAE,UAAU,CAAC,MAAM;YAC7B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,iBAAiB;YACjB,eAAe,EAAE,WAAW;YAC5B,eAAe,EAAE,aAAa;YAC9B,OAAO;SACR;KACF,CAAC;AACJ,CAAC"}
|
package/dist/tools/scrape.d.ts
CHANGED
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
* Implements robust error handling that NEVER crashes the MCP server
|
|
4
4
|
*/
|
|
5
5
|
import type { ScrapeLinksParams, ScrapeLinksOutput } from '../schemas/scrape-links.js';
|
|
6
|
-
|
|
7
|
-
sessionId?: string;
|
|
8
|
-
logger?: (level: 'info' | 'error' | 'debug', message: string, sessionId: string) => Promise<void>;
|
|
9
|
-
}
|
|
6
|
+
import { type ToolOptions } from './utils.js';
|
|
10
7
|
/**
|
|
11
8
|
* Handle scrape links request
|
|
12
9
|
* NEVER throws - always returns a valid response with content and metadata
|
|
@@ -15,5 +12,4 @@ export declare function handleScrapeLinks(params: ScrapeLinksParams, options?: T
|
|
|
15
12
|
content: string;
|
|
16
13
|
structuredContent: ScrapeLinksOutput;
|
|
17
14
|
}>;
|
|
18
|
-
export {};
|
|
19
15
|
//# sourceMappingURL=scrape.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrape.d.ts","sourceRoot":"","sources":["../../src/tools/scrape.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"scrape.d.ts","sourceRoot":"","sources":["../../src/tools/scrape.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAQvF,OAAO,EAEL,KAAK,WAAW,EAOjB,MAAM,YAAY,CAAC;AAapB;;;GAGG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,iBAAiB,EACzB,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,iBAAiB,CAAA;CAAE,CAAC,CA0OpE"}
|
package/dist/tools/scrape.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Scrape Links Tool Handler
|
|
3
3
|
* Implements robust error handling that NEVER crashes the MCP server
|
|
4
4
|
*/
|
|
5
|
+
import pLimit from 'p-limit';
|
|
5
6
|
import { ScraperClient } from '../clients/scraper.js';
|
|
6
7
|
import { MarkdownCleaner } from '../services/markdown-cleaner.js';
|
|
7
8
|
import { createLLMProcessor, processContentWithLLM } from '../services/llm-processor.js';
|
|
@@ -9,34 +10,16 @@ import { removeMetaTags } from '../utils/markdown-formatter.js';
|
|
|
9
10
|
import { SCRAPER } from '../config/index.js';
|
|
10
11
|
import { getToolConfig } from '../config/loader.js';
|
|
11
12
|
import { classifyError } from '../utils/errors.js';
|
|
13
|
+
import { safeLog, calculateTokenAllocation, TOKEN_BUDGETS, formatSuccess, formatError, formatBatchHeader, formatDuration, } from './utils.js';
|
|
12
14
|
// Get extraction suffix from YAML config (fallback to hardcoded if not found)
|
|
13
15
|
function getExtractionSuffix() {
|
|
14
16
|
const config = getToolConfig('scrape_links');
|
|
15
17
|
return config?.limits?.extraction_suffix || SCRAPER.EXTRACTION_SUFFIX;
|
|
16
18
|
}
|
|
17
|
-
function calculateTokenAllocation(urlCount) {
|
|
18
|
-
if (urlCount <= 0)
|
|
19
|
-
return SCRAPER.MAX_TOKENS_BUDGET;
|
|
20
|
-
return Math.floor(SCRAPER.MAX_TOKENS_BUDGET / urlCount);
|
|
21
|
-
}
|
|
22
19
|
function enhanceExtractionInstruction(instruction) {
|
|
23
20
|
const base = instruction || 'Extract the main content and key information from this page.';
|
|
24
21
|
return `${base}\n\n${getExtractionSuffix()}`;
|
|
25
22
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Safe logger wrapper - NEVER throws
|
|
28
|
-
*/
|
|
29
|
-
async function safeLog(logger, sessionId, level, message) {
|
|
30
|
-
if (!logger || !sessionId)
|
|
31
|
-
return;
|
|
32
|
-
try {
|
|
33
|
-
await logger(level, message, sessionId);
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
// Silently ignore logger errors - they should never crash the tool
|
|
37
|
-
console.error(`[Scrape Tool] Logger failed: ${message}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
23
|
/**
|
|
41
24
|
* Handle scrape links request
|
|
42
25
|
* NEVER throws - always returns a valid response with content and metadata
|
|
@@ -44,23 +27,32 @@ async function safeLog(logger, sessionId, level, message) {
|
|
|
44
27
|
export async function handleScrapeLinks(params, options = {}) {
|
|
45
28
|
const { sessionId, logger } = options;
|
|
46
29
|
const startTime = Date.now();
|
|
47
|
-
// Helper to create error response
|
|
48
|
-
const createErrorResponse = (message,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
30
|
+
// Helper to create error response using standardized formatter
|
|
31
|
+
const createErrorResponse = (message, code = 'SCRAPE_ERROR') => {
|
|
32
|
+
const executionTime = Date.now() - startTime;
|
|
33
|
+
const errorContent = formatError({
|
|
34
|
+
code,
|
|
35
|
+
message,
|
|
36
|
+
retryable: false,
|
|
37
|
+
toolName: 'Scrape Links',
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
content: errorContent,
|
|
41
|
+
structuredContent: {
|
|
42
|
+
content: errorContent,
|
|
43
|
+
metadata: {
|
|
44
|
+
total_urls: params.urls?.length || 0,
|
|
45
|
+
successful: 0,
|
|
46
|
+
failed: params.urls?.length || 0,
|
|
47
|
+
total_credits: 0,
|
|
48
|
+
execution_time_ms: executionTime,
|
|
49
|
+
},
|
|
58
50
|
},
|
|
59
|
-
}
|
|
60
|
-
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
61
53
|
// Validate params
|
|
62
54
|
if (!params.urls || params.urls.length === 0) {
|
|
63
|
-
return createErrorResponse('No URLs provided',
|
|
55
|
+
return createErrorResponse('No URLs provided', 'INVALID_INPUT');
|
|
64
56
|
}
|
|
65
57
|
// Filter out invalid URLs early
|
|
66
58
|
const validUrls = [];
|
|
@@ -75,11 +67,11 @@ export async function handleScrapeLinks(params, options = {}) {
|
|
|
75
67
|
}
|
|
76
68
|
}
|
|
77
69
|
if (validUrls.length === 0) {
|
|
78
|
-
return createErrorResponse(`All ${params.urls.length} URLs are invalid`,
|
|
70
|
+
return createErrorResponse(`All ${params.urls.length} URLs are invalid`, 'INVALID_INPUT');
|
|
79
71
|
}
|
|
80
|
-
const tokensPerUrl = calculateTokenAllocation(validUrls.length);
|
|
72
|
+
const tokensPerUrl = calculateTokenAllocation(validUrls.length, TOKEN_BUDGETS.SCRAPER);
|
|
81
73
|
const totalBatches = Math.ceil(validUrls.length / SCRAPER.BATCH_SIZE);
|
|
82
|
-
await safeLog(logger, sessionId, 'info', `Starting scrape: ${validUrls.length} URL(s), ${tokensPerUrl} tokens/URL, ${totalBatches} batch(es)
|
|
74
|
+
await safeLog(logger, sessionId, 'info', `Starting scrape: ${validUrls.length} URL(s), ${tokensPerUrl} tokens/URL, ${totalBatches} batch(es)`, 'Scrape');
|
|
83
75
|
// Initialize clients safely
|
|
84
76
|
let client;
|
|
85
77
|
try {
|
|
@@ -87,7 +79,7 @@ export async function handleScrapeLinks(params, options = {}) {
|
|
|
87
79
|
}
|
|
88
80
|
catch (error) {
|
|
89
81
|
const err = classifyError(error);
|
|
90
|
-
return createErrorResponse(`Failed to initialize scraper: ${err.message}`,
|
|
82
|
+
return createErrorResponse(`Failed to initialize scraper: ${err.message}`, 'INIT_ERROR');
|
|
91
83
|
}
|
|
92
84
|
const markdownCleaner = new MarkdownCleaner();
|
|
93
85
|
const llmProcessor = createLLMProcessor(); // Returns null if not configured
|
|
@@ -96,7 +88,7 @@ export async function handleScrapeLinks(params, options = {}) {
|
|
|
96
88
|
: undefined;
|
|
97
89
|
// Scrape URLs - scrapeMultiple NEVER throws
|
|
98
90
|
const results = await client.scrapeMultiple(validUrls, { timeout: params.timeout });
|
|
99
|
-
await safeLog(logger, sessionId, 'info', `Scraping complete. Processing ${results.length} results
|
|
91
|
+
await safeLog(logger, sessionId, 'info', `Scraping complete. Processing ${results.length} results...`, 'Scrape');
|
|
100
92
|
let successful = 0;
|
|
101
93
|
let failed = 0;
|
|
102
94
|
let totalCredits = 0;
|
|
@@ -107,7 +99,7 @@ export async function handleScrapeLinks(params, options = {}) {
|
|
|
107
99
|
failed++;
|
|
108
100
|
contents.push(`## ${invalidUrl}\n\n❌ Invalid URL format`);
|
|
109
101
|
}
|
|
110
|
-
|
|
102
|
+
const processed = [];
|
|
111
103
|
for (let i = 0; i < results.length; i++) {
|
|
112
104
|
const result = results[i];
|
|
113
105
|
if (!result) {
|
|
@@ -115,13 +107,11 @@ export async function handleScrapeLinks(params, options = {}) {
|
|
|
115
107
|
contents.push(`## Unknown URL\n\n❌ No result returned`);
|
|
116
108
|
continue;
|
|
117
109
|
}
|
|
118
|
-
await safeLog(logger, sessionId, 'info', `[${i + 1}/${results.length}] Processing ${result.url}`);
|
|
119
110
|
// Check for errors in result
|
|
120
111
|
if (result.error || result.statusCode < 200 || result.statusCode >= 300) {
|
|
121
112
|
failed++;
|
|
122
113
|
const errorMsg = result.error?.message || result.content || `HTTP ${result.statusCode}`;
|
|
123
114
|
contents.push(`## ${result.url}\n\n❌ Failed to scrape: ${errorMsg}`);
|
|
124
|
-
await safeLog(logger, sessionId, 'error', `[${i + 1}/${results.length}] Failed: ${errorMsg}`);
|
|
125
115
|
continue;
|
|
126
116
|
}
|
|
127
117
|
// Success case
|
|
@@ -133,38 +123,91 @@ export async function handleScrapeLinks(params, options = {}) {
|
|
|
133
123
|
content = markdownCleaner.processContent(result.content);
|
|
134
124
|
}
|
|
135
125
|
catch {
|
|
136
|
-
// If markdown cleaning fails, use raw content
|
|
137
126
|
content = result.content;
|
|
138
127
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
128
|
+
processed.push({ url: result.url, content, isSuccess: true, index: i });
|
|
129
|
+
}
|
|
130
|
+
// Second pass: parallel LLM extraction for successful results
|
|
131
|
+
if (params.use_llm && llmProcessor && processed.length > 0) {
|
|
132
|
+
await safeLog(logger, sessionId, 'info', `Applying LLM extraction to ${processed.length} results (concurrency: 3)...`, 'Scrape');
|
|
133
|
+
const llmLimit = pLimit(3);
|
|
134
|
+
const llmResults = await Promise.allSettled(processed.map(p => llmLimit(async () => {
|
|
135
|
+
const llmResult = await processContentWithLLM(p.content, { use_llm: params.use_llm, what_to_extract: enhancedInstruction, max_tokens: tokensPerUrl }, llmProcessor);
|
|
136
|
+
return { ...p, llmResult };
|
|
137
|
+
})));
|
|
138
|
+
for (const entry of llmResults) {
|
|
139
|
+
if (entry.status === 'fulfilled') {
|
|
140
|
+
const { url, llmResult } = entry.value;
|
|
141
|
+
let content = entry.value.content;
|
|
142
|
+
if (llmResult.processed) {
|
|
143
|
+
content = llmResult.content;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
llmErrors++;
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
content = removeMetaTags(content);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
// If this fails, just use the content as-is
|
|
153
|
+
}
|
|
154
|
+
contents.push(`## ${url}\n\n${content}`);
|
|
146
155
|
}
|
|
147
156
|
else {
|
|
157
|
+
// Safety net — processContentWithLLM never throws, but handle anyway
|
|
148
158
|
llmErrors++;
|
|
149
|
-
|
|
150
|
-
|
|
159
|
+
// We can't easily recover the URL here, so this is a rare edge case
|
|
160
|
+
contents.push(`## Unknown URL\n\n❌ LLM processing failed unexpectedly`);
|
|
151
161
|
}
|
|
152
162
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
// No LLM — just finalize each successful result
|
|
166
|
+
for (const p of processed) {
|
|
167
|
+
let content = p.content;
|
|
168
|
+
try {
|
|
169
|
+
content = removeMetaTags(content);
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
// If this fails, just use the content as-is
|
|
173
|
+
}
|
|
174
|
+
contents.push(`## ${p.url}\n\n${content}`);
|
|
159
175
|
}
|
|
160
|
-
contents.push(`## ${result.url}\n\n${content}`);
|
|
161
176
|
}
|
|
162
177
|
const executionTime = Date.now() - startTime;
|
|
163
|
-
await safeLog(logger, sessionId, 'info', `Completed: ${successful} successful, ${failed} failed, ${totalCredits} credits used
|
|
164
|
-
// Build response
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
178
|
+
await safeLog(logger, sessionId, 'info', `Completed: ${successful} successful, ${failed} failed, ${totalCredits} credits used`, 'Scrape');
|
|
179
|
+
// Build response using standardized formatters
|
|
180
|
+
const headerInfo = formatBatchHeader({
|
|
181
|
+
title: 'Scraped Content',
|
|
182
|
+
totalItems: params.urls.length,
|
|
183
|
+
successful,
|
|
184
|
+
failed,
|
|
185
|
+
tokensPerItem: tokensPerUrl,
|
|
186
|
+
totalBudget: TOKEN_BUDGETS.SCRAPER,
|
|
187
|
+
batches: totalBatches,
|
|
188
|
+
extras: llmErrors > 0 ? [`⚠️ ${llmErrors} LLM extraction failures`] : undefined,
|
|
189
|
+
});
|
|
190
|
+
// Build next steps based on results
|
|
191
|
+
const nextSteps = [];
|
|
192
|
+
if (successful > 0) {
|
|
193
|
+
nextSteps.push('Use `deep_research()` for in-depth analysis of specific topics found');
|
|
194
|
+
nextSteps.push('Run `web_search()` to find related content');
|
|
195
|
+
}
|
|
196
|
+
if (failed > 0) {
|
|
197
|
+
nextSteps.push(`Retry failed URLs with increased timeout: \`scrape_links({urls: [...], timeout: 60})\``);
|
|
198
|
+
}
|
|
199
|
+
const formattedContent = formatSuccess({
|
|
200
|
+
title: `Scraped Content (${params.urls.length} URLs)`,
|
|
201
|
+
summary: `${headerInfo}\n\n**Execution Time:** ${formatDuration(executionTime)} | **Credits Used:** ${totalCredits}`,
|
|
202
|
+
data: contents.join('\n\n---\n\n'),
|
|
203
|
+
nextSteps,
|
|
204
|
+
metadata: {
|
|
205
|
+
'Total URLs': params.urls.length,
|
|
206
|
+
'Successful': successful,
|
|
207
|
+
'Failed': failed,
|
|
208
|
+
'Tokens/URL': tokensPerUrl,
|
|
209
|
+
},
|
|
210
|
+
});
|
|
168
211
|
const metadata = {
|
|
169
212
|
total_urls: params.urls.length,
|
|
170
213
|
successful,
|
|
@@ -172,7 +215,7 @@ export async function handleScrapeLinks(params, options = {}) {
|
|
|
172
215
|
total_credits: totalCredits,
|
|
173
216
|
execution_time_ms: executionTime,
|
|
174
217
|
tokens_per_url: tokensPerUrl,
|
|
175
|
-
total_token_budget: SCRAPER
|
|
218
|
+
total_token_budget: TOKEN_BUDGETS.SCRAPER,
|
|
176
219
|
batches_processed: totalBatches,
|
|
177
220
|
};
|
|
178
221
|
return { content: formattedContent, structuredContent: { content: formattedContent, metadata } };
|
package/dist/tools/scrape.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrape.js","sourceRoot":"","sources":["../../src/tools/scrape.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"scrape.js","sourceRoot":"","sources":["../../src/tools/scrape.ts"],"names":[],"mappings":"AA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5
5
|
import type { WebSearchParams, WebSearchOutput } from '../schemas/web-search.js';
|
|
6
|
-
|
|
7
|
-
sessionId?: string;
|
|
8
|
-
logger?: (level: 'info' | 'error' | 'debug', message: string, sessionId: string) => Promise<void>;
|
|
9
|
-
}
|
|
6
|
+
import { type ToolOptions } from './utils.js';
|
|
10
7
|
export declare function handleWebSearch(params: WebSearchParams, options?: ToolOptions): Promise<{
|
|
11
8
|
content: string;
|
|
12
9
|
structuredContent: WebSearchOutput;
|
|
13
10
|
}>;
|
|
14
|
-
export {};
|
|
15
11
|
//# sourceMappingURL=search.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/tools/search.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/tools/search.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAWjF,OAAO,EAEL,KAAK,WAAW,EAIjB,MAAM,YAAY,CAAC;AASpB,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,EACvB,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,eAAe,CAAA;CAAE,CAAC,CAgKlE"}
|