search1api-mcp 0.1.3 → 0.1.5
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 +58 -9
- package/build/index.js +135 -53
- package/build/types.js +77 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,8 @@ https://github.com/user-attachments/assets/58bc98ae-3b6b-442c-a7fc-010508b5f028
|
|
|
11
11
|
- News search functionality
|
|
12
12
|
- Web page content extraction
|
|
13
13
|
- Website sitemap extraction
|
|
14
|
-
-
|
|
14
|
+
- Deep thinking and complex problem solving with DeepSeek R1
|
|
15
|
+
- Seamless integration with Claude Desktop, Cursor and Windsurf
|
|
15
16
|
|
|
16
17
|
## Tools
|
|
17
18
|
|
|
@@ -19,17 +20,25 @@ https://github.com/user-attachments/assets/58bc98ae-3b6b-442c-a7fc-010508b5f028
|
|
|
19
20
|
- Name: `search`
|
|
20
21
|
- Description: Search the web using Search1API
|
|
21
22
|
- Parameters:
|
|
22
|
-
* `query` (required): Search query
|
|
23
|
+
* `query` (required): Search query in natural language. Be specific and concise for better results
|
|
23
24
|
* `max_results` (optional, default: 10): Number of results to return
|
|
24
|
-
* `search_service` (optional, default: "google"): Search service to use
|
|
25
|
+
* `search_service` (optional, default: "google"): Search service to use (google, bing, duckduckgo, yahoo, github, youtube, arxiv, wechat, bilibili, imdb)
|
|
26
|
+
* `crawl_results` (optional, default: 0): Number of results to crawl for full webpage content
|
|
27
|
+
* `include_sites` (optional): List of sites to include in search
|
|
28
|
+
* `exclude_sites` (optional): List of sites to exclude from search
|
|
29
|
+
* `time_range` (optional): Time range for search results ("day", "month", "year")
|
|
25
30
|
|
|
26
31
|
### 2. News Tool
|
|
27
32
|
- Name: `news`
|
|
28
33
|
- Description: Search for news articles using Search1API
|
|
29
34
|
- Parameters:
|
|
30
|
-
* `query` (required): Search query
|
|
35
|
+
* `query` (required): Search query in natural language. Be specific and concise for better results
|
|
31
36
|
* `max_results` (optional, default: 10): Number of results to return
|
|
32
|
-
* `search_service` (optional, default: "
|
|
37
|
+
* `search_service` (optional, default: "bing"): Search service to use (google, bing, duckduckgo, yahoo, hackernews)
|
|
38
|
+
* `crawl_results` (optional, default: 0): Number of results to crawl for full webpage content
|
|
39
|
+
* `include_sites` (optional): List of sites to include in search
|
|
40
|
+
* `exclude_sites` (optional): List of sites to exclude from search
|
|
41
|
+
* `time_range` (optional): Time range for search results ("day", "month", "year")
|
|
33
42
|
|
|
34
43
|
### 3. Crawl Tool
|
|
35
44
|
- Name: `crawl`
|
|
@@ -43,14 +52,20 @@ https://github.com/user-attachments/assets/58bc98ae-3b6b-442c-a7fc-010508b5f028
|
|
|
43
52
|
- Parameters:
|
|
44
53
|
* `url` (required): URL to get sitemap
|
|
45
54
|
|
|
55
|
+
### 5. Reasoning Tool
|
|
56
|
+
- Name: `reasoning`
|
|
57
|
+
- Description: A tool for deep thinking and complex problem solving with fast deepseek r1 model and web search ability(You can change to any other model in search1api website but the speed is not guaranteed)
|
|
58
|
+
- Parameters:
|
|
59
|
+
* `content` (required): The question or problem that needs deep thinking
|
|
60
|
+
|
|
46
61
|
## Setup Guide
|
|
47
62
|
|
|
48
63
|
### 1. Get Search1API Key
|
|
49
|
-
1. Register at [Search1API](https://www.search1api.com
|
|
50
|
-
2.
|
|
51
|
-
3. After payment, copy your API key from the confirmation email
|
|
64
|
+
1. Register at [Search1API](https://www.search1api.com/?utm_source=mcp)
|
|
65
|
+
2. Get your api key and 100 free credits
|
|
52
66
|
|
|
53
|
-
### 2. Configure
|
|
67
|
+
### 2. Configure
|
|
68
|
+
#### 2.1 Claude Desktop
|
|
54
69
|
Update your Claude configuration file (`claude_desktop_config.json`) with the following content:
|
|
55
70
|
|
|
56
71
|
```json
|
|
@@ -71,8 +86,42 @@ Configuration file location:
|
|
|
71
86
|
- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
72
87
|
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
73
88
|
|
|
89
|
+
#### 2.2 Cursor
|
|
90
|
+
Easy way:
|
|
91
|
+
1. Open Cursor Settings to add new MCP server `search1api` with the command `env SEARCH1API_KEY=your-search1api-key npx -y search1api-mcp`
|
|
92
|
+
2. Add your own Search1API key to the command
|
|
93
|
+
|
|
94
|
+
Safe way:
|
|
95
|
+
1. Copy the run.template.sh to your file path and rename it to run.sh
|
|
96
|
+
2. Add your own Search1API key to the run.sh file
|
|
97
|
+
3. Open Cursor Settings to add new MCP server `search1api` with the command `sh ./your_file_path/run.sh`
|
|
98
|
+
|
|
99
|
+
Read the Cursor MCP Server [Official Documentation](https://docs.cursor.com/context/model-context-protocol#adding-an-mcp-server-to-cursor) to get more information.
|
|
100
|
+
|
|
101
|
+
#### 2.3 Windsurf
|
|
102
|
+
Update your Windsurf configuration file (`mcp_config.json`) with the following content:
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"mcpServers": {
|
|
107
|
+
"search1api": {
|
|
108
|
+
"command": "npx",
|
|
109
|
+
"args": ["-y", "search1api-mcp"],
|
|
110
|
+
"env": {
|
|
111
|
+
"SEARCH1API_KEY": "YOUR_SEARCH1API_KEY"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
Read the Windsurf MCP Server [Official Documentation](https://docs.codeium.com/windsurf/mcp) to get more information.
|
|
118
|
+
|
|
119
|
+
**Notice: After the configuration is done, you can close Windsurf offcial web tools to save your credits**
|
|
120
|
+
|
|
74
121
|
## Version History
|
|
75
122
|
|
|
123
|
+
- v0.1.5: Added new search parameters (include_sites, exclude_sites, time_range) and new search services (arxiv, wechat, bilibili, imdb)
|
|
124
|
+
- v0.1.4: Added reasoning tool with deepseek r1 and updated the Cursor and Windsurf configuration guide
|
|
76
125
|
- v0.1.3: Added news search functionality
|
|
77
126
|
- v0.1.2: Added sitemap functionality
|
|
78
127
|
- v0.1.1: Added web crawling functionality
|
package/build/index.js
CHANGED
|
@@ -16,28 +16,56 @@ const API_CONFIG = {
|
|
|
16
16
|
SEARCH: '/search',
|
|
17
17
|
CRAWL: '/crawl',
|
|
18
18
|
SITEMAP: '/sitemap',
|
|
19
|
-
NEWS: '/news'
|
|
19
|
+
NEWS: '/news',
|
|
20
|
+
REASONING: '/v1/chat/completions'
|
|
20
21
|
}
|
|
21
22
|
};
|
|
22
23
|
const SEARCH_TOOL = {
|
|
23
24
|
name: "search",
|
|
24
|
-
description: "
|
|
25
|
+
description: "Search the web for real-time results",
|
|
25
26
|
inputSchema: {
|
|
26
27
|
type: "object",
|
|
27
28
|
properties: {
|
|
28
29
|
query: {
|
|
29
30
|
type: "string",
|
|
30
|
-
description: "Search query"
|
|
31
|
+
description: "Search query in natural language. Be specific and concise for better results"
|
|
31
32
|
},
|
|
32
33
|
max_results: {
|
|
33
34
|
type: "number",
|
|
34
|
-
description: "Maximum number of results to return
|
|
35
|
+
description: "Maximum number of results to return",
|
|
35
36
|
default: 10
|
|
36
37
|
},
|
|
37
38
|
search_service: {
|
|
38
39
|
type: "string",
|
|
39
|
-
description: "
|
|
40
|
-
default: "google"
|
|
40
|
+
description: "Specify the search engine to use. Choose based on your specific needs",
|
|
41
|
+
default: "google",
|
|
42
|
+
enum: ["google", "bing", "duckduckgo", "yahoo", "github", "youtube", "arxiv", "wechat", "bilibili", "imdb"]
|
|
43
|
+
},
|
|
44
|
+
crawl_results: {
|
|
45
|
+
type: "number",
|
|
46
|
+
description: "Number of results to crawl for full webpage content, useful when search result summaries are insufficient for complex queries",
|
|
47
|
+
default: 0
|
|
48
|
+
},
|
|
49
|
+
include_sites: {
|
|
50
|
+
type: "array",
|
|
51
|
+
items: {
|
|
52
|
+
type: "string"
|
|
53
|
+
},
|
|
54
|
+
description: "List of sites to include in search. Only use when you need special results from sites not available in search_service",
|
|
55
|
+
default: []
|
|
56
|
+
},
|
|
57
|
+
exclude_sites: {
|
|
58
|
+
type: "array",
|
|
59
|
+
items: {
|
|
60
|
+
type: "string"
|
|
61
|
+
},
|
|
62
|
+
description: "List of sites to exclude from search. Only use when you need to explicitly filter out specific domains from results",
|
|
63
|
+
default: []
|
|
64
|
+
},
|
|
65
|
+
time_range: {
|
|
66
|
+
type: "string",
|
|
67
|
+
description: "Time range for search results, only use when specific time constraints are required",
|
|
68
|
+
enum: ["day", "month", "year"]
|
|
41
69
|
}
|
|
42
70
|
},
|
|
43
71
|
required: ["query"]
|
|
@@ -51,17 +79,44 @@ const NEWS_TOOL = {
|
|
|
51
79
|
properties: {
|
|
52
80
|
query: {
|
|
53
81
|
type: "string",
|
|
54
|
-
description: "
|
|
82
|
+
description: "Search query in natural language. Be specific and concise for better results"
|
|
55
83
|
},
|
|
56
84
|
max_results: {
|
|
57
85
|
type: "number",
|
|
58
|
-
description: "Maximum number of results to return
|
|
86
|
+
description: "Maximum number of results to return",
|
|
59
87
|
default: 10
|
|
60
88
|
},
|
|
61
89
|
search_service: {
|
|
62
90
|
type: "string",
|
|
63
|
-
description: "
|
|
64
|
-
default: "
|
|
91
|
+
description: "Specify the news engine to use. Choose based on your specific needs",
|
|
92
|
+
default: "bing",
|
|
93
|
+
enum: ["google", "bing", "duckduckgo", "yahoo", "hackernews"]
|
|
94
|
+
},
|
|
95
|
+
crawl_results: {
|
|
96
|
+
type: "number",
|
|
97
|
+
description: "Number of results to crawl for full webpage content, useful when search result summaries are insufficient for complex queries",
|
|
98
|
+
default: 0
|
|
99
|
+
},
|
|
100
|
+
include_sites: {
|
|
101
|
+
type: "array",
|
|
102
|
+
items: {
|
|
103
|
+
type: "string"
|
|
104
|
+
},
|
|
105
|
+
description: "List of sites to include in search. Only use when you need special results from sites not available in search_service",
|
|
106
|
+
default: []
|
|
107
|
+
},
|
|
108
|
+
exclude_sites: {
|
|
109
|
+
type: "array",
|
|
110
|
+
items: {
|
|
111
|
+
type: "string"
|
|
112
|
+
},
|
|
113
|
+
description: "List of sites to exclude from search. Only use when you need to explicitly filter out specific domains from results",
|
|
114
|
+
default: []
|
|
115
|
+
},
|
|
116
|
+
time_range: {
|
|
117
|
+
type: "string",
|
|
118
|
+
description: "Time range for search results, only use when specific time constraints are required",
|
|
119
|
+
enum: ["day", "month", "year"]
|
|
65
120
|
}
|
|
66
121
|
},
|
|
67
122
|
required: ["query"]
|
|
@@ -95,10 +150,24 @@ const SITEMAP_TOOL = {
|
|
|
95
150
|
required: ["url"]
|
|
96
151
|
}
|
|
97
152
|
};
|
|
153
|
+
const REASONING_TOOL = {
|
|
154
|
+
name: "reasoning",
|
|
155
|
+
description: "Deep thinking and complex problem solving",
|
|
156
|
+
inputSchema: {
|
|
157
|
+
type: "object",
|
|
158
|
+
properties: {
|
|
159
|
+
content: {
|
|
160
|
+
type: "string",
|
|
161
|
+
description: "The question or problem that needs deep thinking"
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
required: ["content"]
|
|
165
|
+
}
|
|
166
|
+
};
|
|
98
167
|
// Server implementation
|
|
99
168
|
const server = new Server({
|
|
100
169
|
name: "search1api-mcp",
|
|
101
|
-
version: "0.1.
|
|
170
|
+
version: "0.1.5",
|
|
102
171
|
}, {
|
|
103
172
|
capabilities: {
|
|
104
173
|
resources: {
|
|
@@ -116,64 +185,52 @@ const server = new Server({
|
|
|
116
185
|
},
|
|
117
186
|
sitemap: {
|
|
118
187
|
description: "Sitemap extraction functionality"
|
|
188
|
+
},
|
|
189
|
+
reasoning: {
|
|
190
|
+
description: "Deep thinking and complex problem solving"
|
|
119
191
|
}
|
|
120
192
|
},
|
|
121
193
|
},
|
|
122
194
|
});
|
|
123
|
-
//
|
|
195
|
+
// Add server event listeners
|
|
124
196
|
server.onerror = (error) => {
|
|
125
197
|
log('MCP Server Error:', error);
|
|
126
198
|
};
|
|
127
199
|
server.onclose = () => {
|
|
128
200
|
log('MCP Server Connection Closed');
|
|
129
201
|
};
|
|
130
|
-
//
|
|
202
|
+
// Add asynchronous request function
|
|
131
203
|
async function makeRequest(endpoint, data) {
|
|
132
204
|
const startTime = Date.now();
|
|
133
|
-
//
|
|
205
|
+
// Ensure BASE_URL has no trailing slash and endpoint starts with slash
|
|
134
206
|
const baseUrl = API_CONFIG.BASE_URL.replace(/\/+$/, '');
|
|
135
207
|
const path = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
|
|
136
208
|
const url = `${baseUrl}${path}`;
|
|
137
|
-
log(`Starting request to ${url}`);
|
|
138
209
|
try {
|
|
139
|
-
const controller = new AbortController();
|
|
140
|
-
const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 seconds timeout
|
|
141
210
|
const response = await fetch(url, {
|
|
142
211
|
method: 'POST',
|
|
143
212
|
headers: {
|
|
144
213
|
'Authorization': `Bearer ${API_KEY}`,
|
|
145
214
|
'Content-Type': 'application/json',
|
|
146
215
|
},
|
|
147
|
-
body: JSON.stringify(data)
|
|
148
|
-
signal: controller.signal
|
|
216
|
+
body: JSON.stringify(data)
|
|
149
217
|
});
|
|
150
|
-
clearTimeout(timeoutId);
|
|
151
218
|
if (!response.ok) {
|
|
152
219
|
const errorData = await response.json().catch(() => ({}));
|
|
153
220
|
throw new Error(`API error: ${response.status} ${errorData.message || response.statusText}`);
|
|
154
221
|
}
|
|
155
222
|
const result = await response.json();
|
|
156
|
-
const
|
|
157
|
-
log(`
|
|
223
|
+
const duration = Date.now() - startTime;
|
|
224
|
+
log(`API request to ${endpoint} completed in ${duration}ms`);
|
|
158
225
|
return result;
|
|
159
226
|
}
|
|
160
227
|
catch (error) {
|
|
161
|
-
const
|
|
162
|
-
log(`
|
|
163
|
-
if (error instanceof Error) {
|
|
164
|
-
if (error.name === 'AbortError') {
|
|
165
|
-
throw new Error('Request timeout after 30 seconds');
|
|
166
|
-
}
|
|
167
|
-
// 添加更多网络错误的详细信息
|
|
168
|
-
const networkError = error;
|
|
169
|
-
if (networkError.code) {
|
|
170
|
-
throw new Error(`Network error (${networkError.code}): ${networkError.message}`);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
228
|
+
const duration = Date.now() - startTime;
|
|
229
|
+
log(`API request to ${endpoint} failed after ${duration}ms:`, error);
|
|
173
230
|
throw error;
|
|
174
231
|
}
|
|
175
232
|
}
|
|
176
|
-
//
|
|
233
|
+
// Add error handling utility function
|
|
177
234
|
function formatError(error) {
|
|
178
235
|
if (error instanceof Error) {
|
|
179
236
|
return error.message;
|
|
@@ -222,7 +279,7 @@ server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
|
222
279
|
});
|
|
223
280
|
// Tool handlers
|
|
224
281
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
225
|
-
tools: [SEARCH_TOOL, CRAWL_TOOL, SITEMAP_TOOL, NEWS_TOOL],
|
|
282
|
+
tools: [SEARCH_TOOL, CRAWL_TOOL, SITEMAP_TOOL, NEWS_TOOL, REASONING_TOOL],
|
|
226
283
|
}));
|
|
227
284
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
228
285
|
try {
|
|
@@ -235,12 +292,20 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
235
292
|
if (!isValidSearchArgs(args)) {
|
|
236
293
|
throw new McpError(ErrorCode.InvalidParams, "Invalid search arguments");
|
|
237
294
|
}
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
295
|
+
const response = await makeRequest(API_CONFIG.ENDPOINTS.SEARCH, args);
|
|
296
|
+
return {
|
|
297
|
+
content: [{
|
|
298
|
+
type: "text",
|
|
299
|
+
mimeType: "application/json",
|
|
300
|
+
text: JSON.stringify(response.results, null, 2)
|
|
301
|
+
}]
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
case "news": {
|
|
305
|
+
if (!isValidNewsArgs(args)) {
|
|
306
|
+
throw new McpError(ErrorCode.InvalidParams, "Invalid news arguments");
|
|
307
|
+
}
|
|
308
|
+
const response = await makeRequest(API_CONFIG.ENDPOINTS.NEWS, args);
|
|
244
309
|
return {
|
|
245
310
|
content: [{
|
|
246
311
|
type: "text",
|
|
@@ -298,21 +363,38 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
298
363
|
throw formatError(error);
|
|
299
364
|
}
|
|
300
365
|
}
|
|
301
|
-
case "
|
|
302
|
-
if (!
|
|
303
|
-
throw new
|
|
366
|
+
case "reasoning": {
|
|
367
|
+
if (!args) {
|
|
368
|
+
throw new Error("No arguments provided");
|
|
304
369
|
}
|
|
305
|
-
const {
|
|
306
|
-
const response = await
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
370
|
+
const { content } = args;
|
|
371
|
+
const response = await fetch(`${API_CONFIG.BASE_URL}${API_CONFIG.ENDPOINTS.REASONING}`, {
|
|
372
|
+
method: 'POST',
|
|
373
|
+
headers: {
|
|
374
|
+
'Authorization': `Bearer ${API_KEY}`,
|
|
375
|
+
'Content-Type': 'application/json',
|
|
376
|
+
},
|
|
377
|
+
body: JSON.stringify({
|
|
378
|
+
model: "deepseek-r1-70b-fast-online",
|
|
379
|
+
messages: [
|
|
380
|
+
{
|
|
381
|
+
role: "user",
|
|
382
|
+
content: content
|
|
383
|
+
}
|
|
384
|
+
],
|
|
385
|
+
stream: false
|
|
386
|
+
})
|
|
310
387
|
});
|
|
388
|
+
if (!response.ok) {
|
|
389
|
+
const errorData = await response.json().catch(() => ({}));
|
|
390
|
+
throw new Error(`API error: ${response.status} ${errorData.message || response.statusText}`);
|
|
391
|
+
}
|
|
392
|
+
const result = await response.json();
|
|
311
393
|
return {
|
|
312
394
|
content: [{
|
|
313
395
|
type: "text",
|
|
314
396
|
mimeType: "application/json",
|
|
315
|
-
text: JSON.stringify(
|
|
397
|
+
text: JSON.stringify(result.choices[0].message)
|
|
316
398
|
}]
|
|
317
399
|
};
|
|
318
400
|
}
|
|
@@ -332,7 +414,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
332
414
|
};
|
|
333
415
|
}
|
|
334
416
|
});
|
|
335
|
-
//
|
|
417
|
+
// Add logging utility function
|
|
336
418
|
function log(message, ...args) {
|
|
337
419
|
const timestamp = new Date().toISOString();
|
|
338
420
|
console.error(`[${timestamp}] ${message}`, ...args);
|
|
@@ -340,7 +422,7 @@ function log(message, ...args) {
|
|
|
340
422
|
async function runServer() {
|
|
341
423
|
const transport = new StdioServerTransport();
|
|
342
424
|
log("Starting Search1API MCP Server...");
|
|
343
|
-
//
|
|
425
|
+
// Add global error handling
|
|
344
426
|
process.on('uncaughtException', (error) => {
|
|
345
427
|
log('Uncaught Exception:', error);
|
|
346
428
|
});
|
package/build/types.js
CHANGED
|
@@ -1,17 +1,62 @@
|
|
|
1
|
+
export var SearchService;
|
|
2
|
+
(function (SearchService) {
|
|
3
|
+
SearchService["GOOGLE"] = "google";
|
|
4
|
+
SearchService["BING"] = "bing";
|
|
5
|
+
SearchService["DUCKDUCKGO"] = "duckduckgo";
|
|
6
|
+
SearchService["YAHOO"] = "yahoo";
|
|
7
|
+
SearchService["GITHUB"] = "github";
|
|
8
|
+
SearchService["YOUTUBE"] = "youtube";
|
|
9
|
+
SearchService["ARXIV"] = "arxiv";
|
|
10
|
+
SearchService["WECHAT"] = "wechat";
|
|
11
|
+
SearchService["BILIBILI"] = "bilibili";
|
|
12
|
+
SearchService["IMDB"] = "imdb";
|
|
13
|
+
})(SearchService || (SearchService = {}));
|
|
14
|
+
export var NewsService;
|
|
15
|
+
(function (NewsService) {
|
|
16
|
+
NewsService["GOOGLE"] = "google";
|
|
17
|
+
NewsService["BING"] = "bing";
|
|
18
|
+
NewsService["DUCKDUCKGO"] = "duckduckgo";
|
|
19
|
+
NewsService["YAHOO"] = "yahoo";
|
|
20
|
+
NewsService["HACKERNEWS"] = "hackernews";
|
|
21
|
+
})(NewsService || (NewsService = {}));
|
|
22
|
+
export var TimeRange;
|
|
23
|
+
(function (TimeRange) {
|
|
24
|
+
TimeRange["DAY"] = "day";
|
|
25
|
+
TimeRange["MONTH"] = "month";
|
|
26
|
+
TimeRange["YEAR"] = "year";
|
|
27
|
+
})(TimeRange || (TimeRange = {}));
|
|
1
28
|
export function isValidSearchArgs(args) {
|
|
2
29
|
if (typeof args !== 'object' || args === null) {
|
|
3
30
|
return false;
|
|
4
31
|
}
|
|
5
|
-
const { query, max_results, search_service } = args;
|
|
32
|
+
const { query, max_results, search_service, crawl_results, include_sites, exclude_sites, time_range } = args;
|
|
6
33
|
if (typeof query !== 'string' || query.trim().length === 0) {
|
|
7
34
|
return false;
|
|
8
35
|
}
|
|
9
36
|
if (max_results !== undefined && (typeof max_results !== 'number' || max_results < 1 || max_results > 50)) {
|
|
10
37
|
return false;
|
|
11
38
|
}
|
|
12
|
-
if (search_service !== undefined
|
|
39
|
+
if (search_service !== undefined) {
|
|
40
|
+
const validServices = Object.values(SearchService);
|
|
41
|
+
if (!validServices.includes(search_service)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (crawl_results !== undefined && (typeof crawl_results !== 'number' || crawl_results < 0)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (include_sites !== undefined && (!Array.isArray(include_sites) || !include_sites.every(site => typeof site === 'string'))) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (exclude_sites !== undefined && (!Array.isArray(exclude_sites) || !exclude_sites.every(site => typeof site === 'string'))) {
|
|
13
52
|
return false;
|
|
14
53
|
}
|
|
54
|
+
if (time_range !== undefined) {
|
|
55
|
+
const validTimeRanges = Object.values(TimeRange);
|
|
56
|
+
if (!validTimeRanges.includes(time_range)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
15
60
|
return true;
|
|
16
61
|
}
|
|
17
62
|
export function isValidCrawlArgs(args) {
|
|
@@ -38,14 +83,42 @@ export function isValidNewsArgs(args) {
|
|
|
38
83
|
if (typeof args !== 'object' || args === null) {
|
|
39
84
|
return false;
|
|
40
85
|
}
|
|
41
|
-
const { query, max_results, search_service } = args;
|
|
86
|
+
const { query, max_results, search_service, crawl_results, include_sites, exclude_sites, time_range } = args;
|
|
42
87
|
if (typeof query !== 'string' || query.trim().length === 0) {
|
|
43
88
|
return false;
|
|
44
89
|
}
|
|
45
90
|
if (max_results !== undefined && (typeof max_results !== 'number' || max_results < 1 || max_results > 50)) {
|
|
46
91
|
return false;
|
|
47
92
|
}
|
|
48
|
-
if (search_service !== undefined
|
|
93
|
+
if (search_service !== undefined) {
|
|
94
|
+
const validServices = Object.values(NewsService);
|
|
95
|
+
if (!validServices.includes(search_service)) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (crawl_results !== undefined && (typeof crawl_results !== 'number' || crawl_results < 0)) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (include_sites !== undefined && (!Array.isArray(include_sites) || !include_sites.every(site => typeof site === 'string'))) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
if (exclude_sites !== undefined && (!Array.isArray(exclude_sites) || !exclude_sites.every(site => typeof site === 'string'))) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if (time_range !== undefined) {
|
|
109
|
+
const validTimeRanges = Object.values(TimeRange);
|
|
110
|
+
if (!validTimeRanges.includes(time_range)) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
export function isValidReasoningArgs(args) {
|
|
117
|
+
if (typeof args !== 'object' || args === null) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
const { content } = args;
|
|
121
|
+
if (typeof content !== 'string' || content.trim().length === 0) {
|
|
49
122
|
return false;
|
|
50
123
|
}
|
|
51
124
|
return true;
|