@sandagent/runner-cli 0.9.20 → 0.9.21
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/bundle.mjs +62 -41
- package/package.json +4 -4
package/dist/bundle.mjs
CHANGED
|
@@ -1379,20 +1379,33 @@ ${body}`);
|
|
|
1379
1379
|
return results;
|
|
1380
1380
|
}
|
|
1381
1381
|
};
|
|
1382
|
-
var
|
|
1382
|
+
var AUTO_DETECT_ORDER = [braveProvider, tavilyProvider];
|
|
1383
1383
|
function getEnv(env, key) {
|
|
1384
1384
|
const v = env[key] ?? process.env[key];
|
|
1385
1385
|
return v && v.length > 0 ? v : void 0;
|
|
1386
1386
|
}
|
|
1387
|
-
function
|
|
1388
|
-
|
|
1387
|
+
function resolveSearchProviders(env) {
|
|
1388
|
+
const available = [];
|
|
1389
|
+
for (const p of AUTO_DETECT_ORDER) {
|
|
1389
1390
|
for (const key of p.envKeys) {
|
|
1390
1391
|
const val = getEnv(env, key);
|
|
1391
|
-
if (val)
|
|
1392
|
-
|
|
1392
|
+
if (val) {
|
|
1393
|
+
available.push({ provider: p, apiKey: val });
|
|
1394
|
+
break;
|
|
1395
|
+
}
|
|
1393
1396
|
}
|
|
1394
1397
|
}
|
|
1395
|
-
return
|
|
1398
|
+
return available;
|
|
1399
|
+
}
|
|
1400
|
+
function resolveSearchProvider(env) {
|
|
1401
|
+
const all = resolveSearchProviders(env);
|
|
1402
|
+
return all.length > 0 ? all[0] : null;
|
|
1403
|
+
}
|
|
1404
|
+
function isRateLimitError(err) {
|
|
1405
|
+
if (!(err instanceof Error))
|
|
1406
|
+
return false;
|
|
1407
|
+
const msg = err.message;
|
|
1408
|
+
return msg.includes("429") || msg.includes("rate") || msg.includes("quota") || msg.includes("limit");
|
|
1396
1409
|
}
|
|
1397
1410
|
var BROWSER_UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
|
|
1398
1411
|
function htmlToText(html) {
|
|
@@ -1481,14 +1494,13 @@ var webFetchSchema = {
|
|
|
1481
1494
|
}
|
|
1482
1495
|
};
|
|
1483
1496
|
function buildWebSearchTool(env) {
|
|
1484
|
-
const
|
|
1485
|
-
if (
|
|
1497
|
+
const providers = resolveSearchProviders(env);
|
|
1498
|
+
if (providers.length === 0) {
|
|
1486
1499
|
throw new Error("web_search: no search provider available. Set BRAVE_API_KEY or TAVILY_API_KEY.");
|
|
1487
1500
|
}
|
|
1488
|
-
const { provider, apiKey } = resolved;
|
|
1489
1501
|
return {
|
|
1490
1502
|
name: "web_search",
|
|
1491
|
-
label:
|
|
1503
|
+
label: "web search",
|
|
1492
1504
|
description: "Search the web for information. Returns titles, URLs, and snippets. Use for documentation lookups, fact-checking, current events, or any query requiring web results.",
|
|
1493
1505
|
promptSnippet: "web_search(query, count?, freshness?, country?, fetch_content?) - search the web",
|
|
1494
1506
|
promptGuidelines: [
|
|
@@ -1505,40 +1517,49 @@ function buildWebSearchTool(env) {
|
|
|
1505
1517
|
const country = p.country ?? "US";
|
|
1506
1518
|
const freshness = p.freshness;
|
|
1507
1519
|
const shouldFetchContent = p.fetch_content ?? false;
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1520
|
+
let lastError;
|
|
1521
|
+
for (const { provider, apiKey } of providers) {
|
|
1522
|
+
try {
|
|
1523
|
+
const results = await provider.search({
|
|
1524
|
+
apiKey,
|
|
1525
|
+
query,
|
|
1526
|
+
count,
|
|
1527
|
+
country,
|
|
1528
|
+
freshness
|
|
1529
|
+
});
|
|
1530
|
+
if (shouldFetchContent) {
|
|
1531
|
+
for (const r of results) {
|
|
1532
|
+
r.content = await fetchPageContent(r.link);
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
return {
|
|
1536
|
+
content: [
|
|
1537
|
+
{
|
|
1538
|
+
type: "text",
|
|
1539
|
+
text: formatSearchResults(results, provider.label)
|
|
1540
|
+
}
|
|
1541
|
+
],
|
|
1542
|
+
details: void 0
|
|
1543
|
+
};
|
|
1544
|
+
} catch (e) {
|
|
1545
|
+
lastError = e;
|
|
1546
|
+
if (isRateLimitError(e) && providers.length > 1) {
|
|
1547
|
+
console.error(`[sandagent:pi] ${provider.label} rate-limited, trying next provider...`);
|
|
1548
|
+
continue;
|
|
1519
1549
|
}
|
|
1550
|
+
break;
|
|
1520
1551
|
}
|
|
1521
|
-
return {
|
|
1522
|
-
content: [
|
|
1523
|
-
{
|
|
1524
|
-
type: "text",
|
|
1525
|
-
text: formatSearchResults(results, provider.label)
|
|
1526
|
-
}
|
|
1527
|
-
],
|
|
1528
|
-
details: void 0
|
|
1529
|
-
};
|
|
1530
|
-
} catch (e) {
|
|
1531
|
-
const msg = e instanceof Error ? e.message : String(e);
|
|
1532
|
-
return {
|
|
1533
|
-
content: [
|
|
1534
|
-
{
|
|
1535
|
-
type: "text",
|
|
1536
|
-
text: `Web search error (${provider.label}): ${msg}`
|
|
1537
|
-
}
|
|
1538
|
-
],
|
|
1539
|
-
details: void 0
|
|
1540
|
-
};
|
|
1541
1552
|
}
|
|
1553
|
+
const msg = lastError instanceof Error ? lastError.message : String(lastError);
|
|
1554
|
+
return {
|
|
1555
|
+
content: [
|
|
1556
|
+
{
|
|
1557
|
+
type: "text",
|
|
1558
|
+
text: `Web search error: ${msg}`
|
|
1559
|
+
}
|
|
1560
|
+
],
|
|
1561
|
+
details: void 0
|
|
1562
|
+
};
|
|
1542
1563
|
}
|
|
1543
1564
|
};
|
|
1544
1565
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sandagent/runner-cli",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.21",
|
|
4
4
|
"description": "SandAgent Runner CLI - Like gemini-cli or claude-code, runs in your local terminal with AI SDK UI streaming",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -54,11 +54,11 @@
|
|
|
54
54
|
"typescript": "^5.3.0",
|
|
55
55
|
"vitest": "^1.6.1",
|
|
56
56
|
"@sandagent/runner-core": "0.1.1-beta.0",
|
|
57
|
-
"@sandagent/runner-
|
|
57
|
+
"@sandagent/runner-codex": "0.6.2",
|
|
58
58
|
"@sandagent/runner-gemini": "0.6.2",
|
|
59
59
|
"@sandagent/runner-opencode": "0.6.2",
|
|
60
|
-
"@sandagent/runner-
|
|
61
|
-
"@sandagent/runner-
|
|
60
|
+
"@sandagent/runner-claude": "0.6.2",
|
|
61
|
+
"@sandagent/runner-pi": "0.6.4-beta.0"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "tsc && pnpm bundle",
|