@qzhike/agent-search 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +123 -0
- package/dist/adapters/brave-config.js +46 -0
- package/dist/adapters/brave.js +83 -0
- package/dist/adapters/deeproute-mirror.js +31 -0
- package/dist/adapters/exa-config.js +35 -0
- package/dist/adapters/exa.js +91 -0
- package/dist/adapters/jina-config.js +102 -0
- package/dist/adapters/jina-reader.js +83 -0
- package/dist/adapters/jina.js +90 -0
- package/dist/adapters/kimi.js +196 -0
- package/dist/adapters/metaso-config.js +35 -0
- package/dist/adapters/metaso.js +102 -0
- package/dist/adapters/minimax-config.js +54 -0
- package/dist/adapters/minimax.js +85 -0
- package/dist/adapters/provider-auth.js +18 -0
- package/dist/adapters/ragflow-config.js +63 -0
- package/dist/adapters/ragflow.js +170 -0
- package/dist/adapters/searxng-config.js +40 -0
- package/dist/adapters/searxng.js +86 -0
- package/dist/adapters/serper-config.js +35 -0
- package/dist/adapters/serper.js +80 -0
- package/dist/adapters/tavily-config.js +46 -0
- package/dist/adapters/tavily.js +98 -0
- package/dist/adapters/zai-config.js +39 -0
- package/dist/adapters/zai.js +91 -0
- package/dist/config-schema.js +221 -0
- package/dist/http.js +49 -0
- package/dist/index.js +84 -0
- package/dist/plugin-meta.js +11 -0
- package/dist/read-url.js +38 -0
- package/dist/result.js +326 -0
- package/dist/run-provider.js +42 -0
- package/dist/search-concurrent.js +23 -0
- package/dist/search-fallback.js +14 -0
- package/dist/search.js +43 -0
- package/dist/types.js +2 -0
- package/openclaw.plugin.json +547 -0
- package/package.json +25 -0
- package/skills/qzhike-agent-search/SKILL.md +90 -0
package/dist/result.js
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { resolveProviderAuthMode } from "./adapters/provider-auth.js";
|
|
2
|
+
import { parseRagflowDatasetIds } from "./adapters/ragflow-config.js";
|
|
3
|
+
import { EXTERNAL_CONTENT_SOURCE, pluginConfigPath, TOOL_SEARCH, } from "./plugin-meta.js";
|
|
4
|
+
const DEFAULT_MAX_RESULTS = 5;
|
|
5
|
+
const MAX_RESULTS = 10;
|
|
6
|
+
export function clampCount(value, fallback = DEFAULT_MAX_RESULTS) {
|
|
7
|
+
const parsed = typeof value === "number" && Number.isFinite(value)
|
|
8
|
+
? Math.floor(value)
|
|
9
|
+
: fallback;
|
|
10
|
+
return Math.max(1, Math.min(MAX_RESULTS, parsed));
|
|
11
|
+
}
|
|
12
|
+
export function resolveTimeoutSeconds(config) {
|
|
13
|
+
const value = config.timeoutSeconds;
|
|
14
|
+
return typeof value === "number" && value > 0 ? value : 30;
|
|
15
|
+
}
|
|
16
|
+
const DEFAULT_CONCURRENT_MAX = 3;
|
|
17
|
+
const MAX_CONCURRENT_PROVIDERS = 10;
|
|
18
|
+
export function resolveSearchMode(config, override) {
|
|
19
|
+
if (override === "fallback" || override === "concurrent") {
|
|
20
|
+
return override;
|
|
21
|
+
}
|
|
22
|
+
const mode = config.searchMode;
|
|
23
|
+
if (mode === "fallback" || mode === "concurrent") {
|
|
24
|
+
return mode;
|
|
25
|
+
}
|
|
26
|
+
return "fallback";
|
|
27
|
+
}
|
|
28
|
+
export function resolveConcurrentMaxProviders(config) {
|
|
29
|
+
const value = config.concurrentMaxProviders;
|
|
30
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= 1) {
|
|
31
|
+
return Math.min(MAX_CONCURRENT_PROVIDERS, Math.floor(value));
|
|
32
|
+
}
|
|
33
|
+
return DEFAULT_CONCURRENT_MAX;
|
|
34
|
+
}
|
|
35
|
+
export function resolveFallbackOrder(config) {
|
|
36
|
+
const requested = config.fallback ?? [];
|
|
37
|
+
const ordered = [];
|
|
38
|
+
for (const id of requested) {
|
|
39
|
+
if (isProviderConfigured(config, id) && !ordered.includes(id)) {
|
|
40
|
+
ordered.push(id);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return ordered;
|
|
44
|
+
}
|
|
45
|
+
export function resolveConcurrentList(config) {
|
|
46
|
+
const requested = config.concurrent ?? [];
|
|
47
|
+
const max = resolveConcurrentMaxProviders(config);
|
|
48
|
+
const ordered = [];
|
|
49
|
+
for (const id of requested) {
|
|
50
|
+
if (!ordered.includes(id)) {
|
|
51
|
+
ordered.push(id);
|
|
52
|
+
}
|
|
53
|
+
if (ordered.length >= max) {
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return ordered;
|
|
58
|
+
}
|
|
59
|
+
export function isSuccessWithResults(outcome) {
|
|
60
|
+
if (!outcome.ok) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
if (outcome.provider === "kimi") {
|
|
64
|
+
return outcome.content.trim().length > 0;
|
|
65
|
+
}
|
|
66
|
+
return outcome.results.length > 0 || Boolean(outcome.answer?.trim());
|
|
67
|
+
}
|
|
68
|
+
function isProviderExplicitlyDisabled(enabled) {
|
|
69
|
+
return enabled === false;
|
|
70
|
+
}
|
|
71
|
+
function isMirrorProviderConfigured(cfg, directRequiresApiKey = true) {
|
|
72
|
+
if (!cfg || isProviderExplicitlyDisabled(cfg.enabled)) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
const auth = resolveProviderAuthMode(cfg.auth) ?? "direct";
|
|
76
|
+
if (auth === "deeproute") {
|
|
77
|
+
return Boolean(cfg.baseUrl?.trim() && cfg.apiKey?.trim());
|
|
78
|
+
}
|
|
79
|
+
return directRequiresApiKey ? Boolean(cfg.apiKey?.trim()) : true;
|
|
80
|
+
}
|
|
81
|
+
/** Provider blocks omitted from config are disabled by default. */
|
|
82
|
+
export function isProviderConfigured(config, id) {
|
|
83
|
+
const providers = config.providers;
|
|
84
|
+
if (!providers) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
switch (id) {
|
|
88
|
+
case "ragflow": {
|
|
89
|
+
const cfg = providers.ragflow;
|
|
90
|
+
if (!cfg || isProviderExplicitlyDisabled(cfg.enabled)) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
const auth = resolveProviderAuthMode(cfg.auth) ?? "direct";
|
|
94
|
+
if (auth === "deeproute") {
|
|
95
|
+
return Boolean(cfg.baseUrl?.trim() && cfg.apiKey?.trim());
|
|
96
|
+
}
|
|
97
|
+
return Boolean(cfg.baseUrl?.trim() &&
|
|
98
|
+
cfg.apiKey?.trim() &&
|
|
99
|
+
parseRagflowDatasetIds(cfg.datasetIds).length > 0);
|
|
100
|
+
}
|
|
101
|
+
case "serper":
|
|
102
|
+
case "metaso":
|
|
103
|
+
case "zai":
|
|
104
|
+
case "exa":
|
|
105
|
+
case "tavily":
|
|
106
|
+
case "minimax":
|
|
107
|
+
return isMirrorProviderConfigured(providers[id]);
|
|
108
|
+
case "searxng": {
|
|
109
|
+
const cfg = providers.searxng;
|
|
110
|
+
if (!cfg || isProviderExplicitlyDisabled(cfg.enabled)) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
const auth = resolveProviderAuthMode(cfg.auth) ?? "direct";
|
|
114
|
+
if (auth === "deeproute") {
|
|
115
|
+
return Boolean(cfg.baseUrl?.trim() && cfg.apiKey?.trim());
|
|
116
|
+
}
|
|
117
|
+
return Boolean(cfg.baseUrl?.trim());
|
|
118
|
+
}
|
|
119
|
+
case "jina":
|
|
120
|
+
return isMirrorProviderConfigured(providers.jina, true);
|
|
121
|
+
case "brave":
|
|
122
|
+
return isMirrorProviderConfigured(providers.brave);
|
|
123
|
+
case "kimi": {
|
|
124
|
+
const cfg = providers.kimi;
|
|
125
|
+
if (!cfg || isProviderExplicitlyDisabled(cfg.enabled)) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
return Boolean(cfg.baseUrl?.trim() && cfg.apiKey?.trim());
|
|
129
|
+
}
|
|
130
|
+
default: {
|
|
131
|
+
const _exhaustive = id;
|
|
132
|
+
return _exhaustive;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export function providerConfigurationHint(id) {
|
|
137
|
+
const path = pluginConfigPath(`providers.${id}`);
|
|
138
|
+
switch (id) {
|
|
139
|
+
case "jina":
|
|
140
|
+
return (`Provider "jina" is not configured for search. Set ${path} with auth and credentials. ` +
|
|
141
|
+
`Search (${TOOL_SEARCH}) needs apiKey (direct) or baseUrl+apiKey (deeproute) plus a valid Jina key in DeepRoute 扩展服务 for Search.`);
|
|
142
|
+
case "brave":
|
|
143
|
+
return (`Provider "brave" is not configured. Set ${path} with apiKey (direct Brave token) ` +
|
|
144
|
+
"or auth deeproute + baseUrl (Console origin) + apiKey (user sk).");
|
|
145
|
+
default:
|
|
146
|
+
return `Provider "${id}" is not configured. Set ${path} with the required fields (see README).`;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/** Jina Reader: direct works without apiKey; deeproute needs Console origin + user sk. */
|
|
150
|
+
export function isJinaReaderConfigured(config) {
|
|
151
|
+
const cfg = config.providers?.jina;
|
|
152
|
+
if (!cfg || isProviderExplicitlyDisabled(cfg.enabled)) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
const auth = resolveProviderAuthMode(cfg.auth) ?? "direct";
|
|
156
|
+
if (auth === "deeproute") {
|
|
157
|
+
return Boolean(cfg.baseUrl?.trim() && cfg.apiKey?.trim());
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
export function resolveEnabledProviders(config) {
|
|
162
|
+
const ids = [];
|
|
163
|
+
for (const id of [
|
|
164
|
+
"ragflow",
|
|
165
|
+
"serper",
|
|
166
|
+
"metaso",
|
|
167
|
+
"zai",
|
|
168
|
+
"exa",
|
|
169
|
+
"searxng",
|
|
170
|
+
"kimi",
|
|
171
|
+
"brave",
|
|
172
|
+
"tavily",
|
|
173
|
+
"jina",
|
|
174
|
+
"minimax",
|
|
175
|
+
]) {
|
|
176
|
+
if (isProviderConfigured(config, id)) {
|
|
177
|
+
ids.push(id);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return ids;
|
|
181
|
+
}
|
|
182
|
+
export function formatResultsAsContent(results, answer) {
|
|
183
|
+
if (answer?.trim()) {
|
|
184
|
+
return answer.trim();
|
|
185
|
+
}
|
|
186
|
+
if (results.length === 0) {
|
|
187
|
+
return "No search results.";
|
|
188
|
+
}
|
|
189
|
+
return results
|
|
190
|
+
.map((item, index) => {
|
|
191
|
+
const lines = [
|
|
192
|
+
`${index + 1}. ${item.title || "(no title)"}`,
|
|
193
|
+
` ${item.url}`,
|
|
194
|
+
];
|
|
195
|
+
if (item.snippet) {
|
|
196
|
+
lines.push(` ${item.snippet}`);
|
|
197
|
+
}
|
|
198
|
+
return lines.join("\n");
|
|
199
|
+
})
|
|
200
|
+
.join("\n\n");
|
|
201
|
+
}
|
|
202
|
+
export function mergeConcurrentResults(successes, maxResults) {
|
|
203
|
+
const seen = new Set();
|
|
204
|
+
const merged = [];
|
|
205
|
+
const citations = [];
|
|
206
|
+
for (const success of successes) {
|
|
207
|
+
for (const url of success.citations) {
|
|
208
|
+
if (!citations.includes(url)) {
|
|
209
|
+
citations.push(url);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
for (const item of success.results) {
|
|
213
|
+
const key = item.url.trim().toLowerCase();
|
|
214
|
+
if (key && !seen.has(key)) {
|
|
215
|
+
seen.add(key);
|
|
216
|
+
merged.push(item);
|
|
217
|
+
if (merged.length >= maxResults) {
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (merged.length >= maxResults) {
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
let content = "";
|
|
227
|
+
for (const success of successes) {
|
|
228
|
+
if (success.answer?.trim()) {
|
|
229
|
+
content = success.answer.trim();
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (!content) {
|
|
234
|
+
content = formatResultsAsContent(merged);
|
|
235
|
+
}
|
|
236
|
+
return { results: merged, content, citations };
|
|
237
|
+
}
|
|
238
|
+
function mapAttempts(attempts) {
|
|
239
|
+
return attempts.map((attempt) => attempt.ok
|
|
240
|
+
? { provider: attempt.provider, ok: true, tookMs: attempt.tookMs }
|
|
241
|
+
: {
|
|
242
|
+
provider: attempt.provider,
|
|
243
|
+
ok: false,
|
|
244
|
+
error: attempt.error,
|
|
245
|
+
message: attempt.message,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
export function toToolPayload(success, attempts) {
|
|
249
|
+
return {
|
|
250
|
+
query: success.query,
|
|
251
|
+
searchMode: "fallback",
|
|
252
|
+
provider: success.provider,
|
|
253
|
+
tookMs: success.tookMs,
|
|
254
|
+
citations: success.citations,
|
|
255
|
+
results: success.results,
|
|
256
|
+
...(success.answer ? { answer: success.answer } : {}),
|
|
257
|
+
content: success.content,
|
|
258
|
+
externalContent: {
|
|
259
|
+
untrusted: true,
|
|
260
|
+
source: EXTERNAL_CONTENT_SOURCE,
|
|
261
|
+
provider: success.provider,
|
|
262
|
+
},
|
|
263
|
+
attempts: mapAttempts(attempts),
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
export function toConcurrentToolPayload(query, successes, attempts, tookMs, maxResults) {
|
|
267
|
+
const { results, content, citations } = mergeConcurrentResults(successes, maxResults);
|
|
268
|
+
const resultsByProvider = {};
|
|
269
|
+
for (const attempt of attempts) {
|
|
270
|
+
if (attempt.ok) {
|
|
271
|
+
resultsByProvider[attempt.provider] = {
|
|
272
|
+
ok: true,
|
|
273
|
+
tookMs: attempt.tookMs,
|
|
274
|
+
results: attempt.results,
|
|
275
|
+
...(attempt.answer ? { answer: attempt.answer } : {}),
|
|
276
|
+
content: attempt.content,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
resultsByProvider[attempt.provider] = {
|
|
281
|
+
ok: false,
|
|
282
|
+
error: attempt.error,
|
|
283
|
+
message: attempt.message,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
const succeeded = attempts.filter((attempt) => isSuccessWithResults(attempt)).length;
|
|
288
|
+
return {
|
|
289
|
+
query,
|
|
290
|
+
searchMode: "concurrent",
|
|
291
|
+
tookMs,
|
|
292
|
+
content,
|
|
293
|
+
results,
|
|
294
|
+
citations,
|
|
295
|
+
resultsByProvider,
|
|
296
|
+
attempts: mapAttempts(attempts),
|
|
297
|
+
summary: {
|
|
298
|
+
total: attempts.length,
|
|
299
|
+
succeeded,
|
|
300
|
+
failed: attempts.length - succeeded,
|
|
301
|
+
},
|
|
302
|
+
externalContent: {
|
|
303
|
+
untrusted: true,
|
|
304
|
+
source: EXTERNAL_CONTENT_SOURCE,
|
|
305
|
+
providers: successes.map((success) => success.provider),
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
export function failurePayload(query, attempts, options) {
|
|
310
|
+
return {
|
|
311
|
+
error: "all_providers_failed",
|
|
312
|
+
query,
|
|
313
|
+
...(options?.searchMode ? { searchMode: options.searchMode } : {}),
|
|
314
|
+
message: "All configured search providers failed. See attempts for details.",
|
|
315
|
+
attempts: mapAttempts(attempts),
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
export function noProvidersConfiguredPayload(searchMode) {
|
|
319
|
+
const listKey = searchMode === "concurrent" ? "concurrent" : "fallback";
|
|
320
|
+
return {
|
|
321
|
+
error: "no_providers_configured",
|
|
322
|
+
searchMode,
|
|
323
|
+
message: `No providers configured for ${searchMode} mode. Set ${pluginConfigPath(listKey)} with enabled providers.`,
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
//# sourceMappingURL=result.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { searchBrave } from "./adapters/brave.js";
|
|
2
|
+
import { searchExa } from "./adapters/exa.js";
|
|
3
|
+
import { searchJina } from "./adapters/jina.js";
|
|
4
|
+
import { searchKimi } from "./adapters/kimi.js";
|
|
5
|
+
import { searchMetaso } from "./adapters/metaso.js";
|
|
6
|
+
import { searchMinimax } from "./adapters/minimax.js";
|
|
7
|
+
import { searchRagflow } from "./adapters/ragflow.js";
|
|
8
|
+
import { searchSearxng } from "./adapters/searxng.js";
|
|
9
|
+
import { searchSerper } from "./adapters/serper.js";
|
|
10
|
+
import { searchTavily } from "./adapters/tavily.js";
|
|
11
|
+
import { searchZai } from "./adapters/zai.js";
|
|
12
|
+
export async function runProvider(config, provider, query, count, signal, runOptions) {
|
|
13
|
+
switch (provider) {
|
|
14
|
+
case "ragflow":
|
|
15
|
+
return searchRagflow(config, query, count, signal);
|
|
16
|
+
case "serper":
|
|
17
|
+
return searchSerper(config, query, count, signal);
|
|
18
|
+
case "metaso":
|
|
19
|
+
return searchMetaso(config, query, count, signal);
|
|
20
|
+
case "zai":
|
|
21
|
+
return searchZai(config, query, count, signal);
|
|
22
|
+
case "exa":
|
|
23
|
+
return searchExa(config, query, count, signal);
|
|
24
|
+
case "searxng":
|
|
25
|
+
return searchSearxng(config, query, count, signal);
|
|
26
|
+
case "kimi":
|
|
27
|
+
return searchKimi(config, query, count, signal);
|
|
28
|
+
case "brave":
|
|
29
|
+
return searchBrave(config, query, count, signal, runOptions);
|
|
30
|
+
case "tavily":
|
|
31
|
+
return searchTavily(config, query, count, signal, runOptions);
|
|
32
|
+
case "jina":
|
|
33
|
+
return searchJina(config, query, count, signal);
|
|
34
|
+
case "minimax":
|
|
35
|
+
return searchMinimax(config, query, count, signal);
|
|
36
|
+
default: {
|
|
37
|
+
const _exhaustive = provider;
|
|
38
|
+
return _exhaustive;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=run-provider.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { failurePayload, isProviderConfigured, isSuccessWithResults, providerConfigurationHint, toConcurrentToolPayload, } from "./result.js";
|
|
2
|
+
import { runProvider } from "./run-provider.js";
|
|
3
|
+
async function resolveProviderAttempt(config, providerId, query, count, signal, runOptions) {
|
|
4
|
+
if (!isProviderConfigured(config, providerId)) {
|
|
5
|
+
return {
|
|
6
|
+
ok: false,
|
|
7
|
+
provider: providerId,
|
|
8
|
+
error: "provider_not_configured",
|
|
9
|
+
message: providerConfigurationHint(providerId),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
return runProvider(config, providerId, query, count, signal, runOptions);
|
|
13
|
+
}
|
|
14
|
+
export async function executeConcurrentSearch(config, query, count, order, signal, runOptions) {
|
|
15
|
+
const started = Date.now();
|
|
16
|
+
const attempts = await Promise.all(order.map((providerId) => resolveProviderAttempt(config, providerId, query, count, signal, runOptions)));
|
|
17
|
+
const successes = attempts.filter((attempt) => attempt.ok && isSuccessWithResults(attempt));
|
|
18
|
+
if (successes.length === 0) {
|
|
19
|
+
return failurePayload(query, attempts, { searchMode: "concurrent" });
|
|
20
|
+
}
|
|
21
|
+
return toConcurrentToolPayload(query, successes, attempts, Date.now() - started, count);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=search-concurrent.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { failurePayload, isSuccessWithResults, toToolPayload, } from "./result.js";
|
|
2
|
+
import { runProvider } from "./run-provider.js";
|
|
3
|
+
export async function executeFallbackSearch(config, query, count, order, signal, runOptions) {
|
|
4
|
+
const attempts = [];
|
|
5
|
+
for (const providerId of order) {
|
|
6
|
+
const outcome = await runProvider(config, providerId, query, count, signal, runOptions);
|
|
7
|
+
attempts.push(outcome);
|
|
8
|
+
if (outcome.ok && isSuccessWithResults(outcome)) {
|
|
9
|
+
return toToolPayload(outcome, attempts);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return failurePayload(query, attempts, { searchMode: "fallback" });
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=search-fallback.js.map
|
package/dist/search.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { clampCount, isProviderConfigured, noProvidersConfiguredPayload, providerConfigurationHint, resolveConcurrentList, resolveFallbackOrder, resolveSearchMode, } from "./result.js";
|
|
2
|
+
import { executeConcurrentSearch } from "./search-concurrent.js";
|
|
3
|
+
import { executeFallbackSearch } from "./search-fallback.js";
|
|
4
|
+
export async function executeDeepSearch(config, params, signal) {
|
|
5
|
+
const query = params.query.trim();
|
|
6
|
+
if (!query) {
|
|
7
|
+
return { error: "missing_query", message: "query is required." };
|
|
8
|
+
}
|
|
9
|
+
const count = clampCount(params.count ?? config.maxResults);
|
|
10
|
+
const runOptions = {
|
|
11
|
+
brave: {
|
|
12
|
+
country: params.country,
|
|
13
|
+
freshness: params.freshness,
|
|
14
|
+
},
|
|
15
|
+
tavily: {
|
|
16
|
+
searchDepth: params.searchDepth,
|
|
17
|
+
includeAnswer: params.includeAnswer,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
if (params.provider) {
|
|
21
|
+
if (!isProviderConfigured(config, params.provider)) {
|
|
22
|
+
return {
|
|
23
|
+
error: "provider_not_configured",
|
|
24
|
+
message: providerConfigurationHint(params.provider),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return executeFallbackSearch(config, query, count, [params.provider], signal, runOptions);
|
|
28
|
+
}
|
|
29
|
+
const searchMode = resolveSearchMode(config, params.searchMode);
|
|
30
|
+
if (searchMode === "concurrent") {
|
|
31
|
+
const order = resolveConcurrentList(config);
|
|
32
|
+
if (order.length === 0) {
|
|
33
|
+
return noProvidersConfiguredPayload("concurrent");
|
|
34
|
+
}
|
|
35
|
+
return executeConcurrentSearch(config, query, count, order, signal, runOptions);
|
|
36
|
+
}
|
|
37
|
+
const order = resolveFallbackOrder(config);
|
|
38
|
+
if (order.length === 0) {
|
|
39
|
+
return noProvidersConfiguredPayload("fallback");
|
|
40
|
+
}
|
|
41
|
+
return executeFallbackSearch(config, query, count, order, signal, runOptions);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=search.js.map
|
package/dist/types.js
ADDED