@corbat-tech/coco 2.28.0 → 2.28.2
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/dist/cli/index.js +63 -14
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21977,6 +21977,11 @@ var DEFAULT_SEARCH_TIMEOUT_MS = 15e3;
|
|
|
21977
21977
|
var MAX_QUERY_LENGTH = 500;
|
|
21978
21978
|
var MIN_REQUEST_INTERVAL_MS = 1e3;
|
|
21979
21979
|
var lastRequestTime = 0;
|
|
21980
|
+
function isEngineConfigured(engine) {
|
|
21981
|
+
if (engine === "duckduckgo") return true;
|
|
21982
|
+
if (engine === "brave") return !!process.env.BRAVE_SEARCH_API_KEY;
|
|
21983
|
+
return !!process.env.SERPAPI_KEY;
|
|
21984
|
+
}
|
|
21980
21985
|
function sanitizeQuery(query) {
|
|
21981
21986
|
const cleaned = query.replace(/[\x00-\x1F\x7F]/g, " ").trim();
|
|
21982
21987
|
return cleaned.slice(0, MAX_QUERY_LENGTH);
|
|
@@ -22178,7 +22183,9 @@ Examples:
|
|
|
22178
22183
|
await enforceRateLimit();
|
|
22179
22184
|
try {
|
|
22180
22185
|
let results;
|
|
22181
|
-
|
|
22186
|
+
const requestedEngine = engine;
|
|
22187
|
+
const effectiveEngine = isEngineConfigured(requestedEngine) ? requestedEngine : "duckduckgo";
|
|
22188
|
+
switch (effectiveEngine) {
|
|
22182
22189
|
case "brave":
|
|
22183
22190
|
results = await searchBrave(sanitizedQuery, maxResults, DEFAULT_SEARCH_TIMEOUT_MS);
|
|
22184
22191
|
break;
|
|
@@ -22193,7 +22200,7 @@ Examples:
|
|
|
22193
22200
|
return {
|
|
22194
22201
|
results,
|
|
22195
22202
|
totalResults: results.length,
|
|
22196
|
-
engine:
|
|
22203
|
+
engine: effectiveEngine,
|
|
22197
22204
|
duration: performance.now() - startTime
|
|
22198
22205
|
};
|
|
22199
22206
|
} catch (error) {
|