@nite07/dsh-search 0.1.3 → 0.1.4
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 +1 -0
- package/README.zh.md +1 -0
- package/dist/client.js +46 -24
- package/dist/index.js +755 -323
- package/dist/index.js.map +4 -4
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -43,6 +43,7 @@ The list is grouped by the cheapest path a backend offers, so anything with a fr
|
|
|
43
43
|
|
|
44
44
|
- `web_search` — the backend fan-out described above.
|
|
45
45
|
- `web_search_plus` — search with a strategy for this call only: (can be switched off in settings, which stops registering it) `mode` (single or parallel), `backends` (a subset of the enabled ones), `allBackends` + `exclude` (everything except a few, cheaper to write than listing ids), `compact` (links and titles only, no snippets, which is the biggest lever on result size; can be made the default in settings) and `maxResults`. Saved configuration is untouched, a backend that is not enabled is reported rather than silently dropped, and the result names the backends that actually ran.
|
|
46
|
+
- `x_thread` — read one X post with its replies, so a discussion a search surfaced can be quoted. Needs the X backend in session mode; a bounded depth, reply count and character budget apply.
|
|
46
47
|
- `reddit_thread` — read one Reddit post with its comment tree, so a model can quote the discussion instead of guessing. Capped by depth, comment count and character budget.
|
|
47
48
|
- `search_manage` — inspect or change this plugin's settings from the agent side.
|
|
48
49
|
|
package/README.zh.md
CHANGED
|
@@ -43,6 +43,7 @@ dsh --profile web # 或者用你自己的方式重启 dsh web
|
|
|
43
43
|
|
|
44
44
|
- `web_search` — 上面说的多后端搜索。
|
|
45
45
|
- `web_search_plus` — 按本次调用指定搜索策略:(可在设置里关闭:关闭后不注册该工具)`mode`(单后端/并行)、`backends`(从已启用里挑子集)、`allBackends` + `exclude`(全用但排掉几家,比列 id 省字符)、`compact`(只回标题和链接,丢掉摘要,省结果 token;可在设置里设为默认)、`maxResults`。只影响这一次调用,不改配置;没启用的后端会被明确告知而不是被悄悄忽略,实际用了哪些也会回显。
|
|
46
|
+
- `x_thread` — 读一条 X 推文及其回复,让搜索到的讨论可以被引用;需要 X 后端处于会话模式,深度、回复条数和字符预算都有上限。
|
|
46
47
|
- `reddit_thread` — 读某个 Reddit 帖子的完整评论树,让模型能引用真实讨论而不是猜;按深度、评论条数和字符预算截断。
|
|
47
48
|
- `search_manage` — 从 agent 侧查看或修改本插件自己的设置。
|
|
48
49
|
|
package/dist/client.js
CHANGED
|
@@ -503,7 +503,7 @@ var NiteSearchClient = (() => {
|
|
|
503
503
|
"help.tools.compactByDefault": "\u7ED3\u679C\u53EA\u4FDD\u7559\u94FE\u63A5\u3001\u6807\u9898\u548C\u65E5\u671F\u3002agent \u53EA\u9700\u8981\u94FE\u63A5\u65F6\u80FD\u7701\u4E0B\u5927\u91CF\u4E0A\u4E0B\u6587\uFF1B\u5355\u6B21\u8C03\u7528\u4ECD\u53EF\u8981\u6C42\u5B8C\u6574\u6458\u8981\u3002"
|
|
504
504
|
};
|
|
505
505
|
|
|
506
|
-
//
|
|
506
|
+
// ../search-core/dist/catalog.js
|
|
507
507
|
var text = (en, zh) => ({ en, zh });
|
|
508
508
|
var option = (key, label, zh, value, choices) => ({ key, type: choices ? "select" : typeof value, label: text(label, zh), help: text(`Native ${key} parameter. See the backend documentation.`, `\u539F\u751F ${key} \u53C2\u6570\uFF0C\u8BE6\u89C1\u540E\u7AEF\u6587\u6863\u3002`), default: value, ...choices ? { choices } : {} });
|
|
509
509
|
var mode = (access, endpoint, tier, en, zh, pricingUrl, shape) => ({ mode: access, endpoint, tier, limits: text(en, zh), pricingUrl, ...shape ? { credentialShape: text(shape.en, shape.zh) } : {} });
|
|
@@ -534,11 +534,11 @@ var NiteSearchClient = (() => {
|
|
|
534
534
|
backend("tencent-wsa", "Tencent Cloud WSA", "https://cloud.tencent.com/document/product/1806/121811", [mode("key", "https://wsa.tencentcloudapi.com/", "paid", "\xA514/\xA520/\xA526 per 1,000 by tier. Store a JSON credential {secretId,secretKey}; no free allowance verified.", "\u5206\u6863 \xA514\uFF0F\xA520\uFF0F\xA526 \u6BCF\u5343\u6B21\u3002\u51ED\u8BC1\u586B\u5199 JSON {secretId,secretKey}\uFF1B\u514D\u8D39\u989D\u5EA6\u672A\u6838\u5B9E\u3002", "https://cloud.tencent.com/product/wsa", { en: '{"secretId":"...","secretKey":"..."}', zh: '{"secretId":"...","secretKey":"..."}' })], [{ ...option("Mode", "Search mode", "\u641C\u7D22\u6A21\u5F0F", 0), min: 0, max: 2 }])
|
|
535
535
|
];
|
|
536
536
|
|
|
537
|
-
//
|
|
537
|
+
// ../search-core/dist/locale-map.js
|
|
538
538
|
var LANGUAGES = ["", "en", "zh-Hans", "zh-Hant", "ja", "ko", "fr", "de", "es", "pt", "ru", "it", "ar", "nl", "pl", "tr", "vi", "th", "id"];
|
|
539
539
|
var REGIONS = ["", "US", "GB", "CN", "HK", "TW", "JP", "KR", "SG", "IN", "AU", "CA", "DE", "FR", "ES", "IT", "NL", "BR", "MX", "RU", "TR", "SA"];
|
|
540
540
|
|
|
541
|
-
//
|
|
541
|
+
// ../search-core/dist/config.js
|
|
542
542
|
function defaultConfig() {
|
|
543
543
|
return {
|
|
544
544
|
mode: "parallel",
|
|
@@ -566,38 +566,52 @@ var NiteSearchClient = (() => {
|
|
|
566
566
|
const issues = [];
|
|
567
567
|
const fail = (path, message) => issues.push({ path, message });
|
|
568
568
|
const object = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
569
|
-
if (!object(value))
|
|
569
|
+
if (!object(value))
|
|
570
|
+
return [{ path: "config", message: "Expected a configuration object." }];
|
|
570
571
|
function shape(v, exemplar, path) {
|
|
571
572
|
if (Array.isArray(exemplar)) {
|
|
572
573
|
if (!Array.isArray(v)) {
|
|
573
574
|
fail(path, "Expected an array.");
|
|
574
575
|
return;
|
|
575
576
|
}
|
|
576
|
-
if (v.length > 200)
|
|
577
|
+
if (v.length > 200)
|
|
578
|
+
fail(path, "Too many entries.");
|
|
577
579
|
if (path === "retry.statuses") {
|
|
578
|
-
if (v.some((n) => !Number.isInteger(n) || n < 400 || n > 599))
|
|
579
|
-
|
|
580
|
+
if (v.some((n) => !Number.isInteger(n) || n < 400 || n > 599))
|
|
581
|
+
fail(path, "Expected HTTP error status codes (400\u2013599).");
|
|
582
|
+
} else if (v.some((x) => typeof x !== "string" || x.length > 253 || !/^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/.test(x)))
|
|
583
|
+
fail(path, "Expected domain names without scheme, path, or wildcards.");
|
|
580
584
|
} else if (object(exemplar)) {
|
|
581
585
|
if (!object(v)) {
|
|
582
586
|
fail(path, "Expected an object.");
|
|
583
587
|
return;
|
|
584
588
|
}
|
|
585
|
-
for (const k of Object.keys(v))
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
+
for (const k of Object.keys(v))
|
|
590
|
+
if (!(k in exemplar) && path !== "backends")
|
|
591
|
+
fail(path ? `${path}.${k}` : k, "Unknown configuration field.");
|
|
592
|
+
for (const [k, e] of Object.entries(exemplar))
|
|
593
|
+
shape(v[k], e, path ? `${path}.${k}` : k);
|
|
594
|
+
} else if (typeof v !== typeof exemplar || typeof v === "number" && !Number.isFinite(v))
|
|
595
|
+
fail(path, `Expected ${typeof exemplar}.`);
|
|
596
|
+
else if (typeof v === "string" && v.length > 4096)
|
|
597
|
+
fail(path, "Value is too long.");
|
|
589
598
|
}
|
|
590
599
|
shape(value, defaultConfig(), "");
|
|
591
|
-
if (issues.length)
|
|
600
|
+
if (issues.length)
|
|
601
|
+
return issues;
|
|
592
602
|
const c = value;
|
|
593
603
|
const choice = (v, allowed, p) => {
|
|
594
|
-
if (!allowed.includes(v))
|
|
604
|
+
if (!allowed.includes(v))
|
|
605
|
+
fail(p, "Unsupported selection.");
|
|
595
606
|
};
|
|
596
607
|
const num = (v, min, max, p) => {
|
|
597
|
-
if (!Number.isInteger(v) || v < min || v > max)
|
|
608
|
+
if (!Number.isInteger(v) || v < min || v > max)
|
|
609
|
+
fail(p, `Expected an integer between ${min} and ${max}.`);
|
|
598
610
|
};
|
|
599
|
-
if (c.language && !LANGUAGES.includes(c.language))
|
|
600
|
-
|
|
611
|
+
if (c.language && !LANGUAGES.includes(c.language))
|
|
612
|
+
fail("language", "Unsupported language code.");
|
|
613
|
+
if (c.region && !REGIONS.includes(c.region))
|
|
614
|
+
fail("region", "Unsupported region code.");
|
|
601
615
|
choice(c.mode, ["single", "parallel"], "mode");
|
|
602
616
|
choice(c.singleBackend, catalog.map((x) => x.id), "singleBackend");
|
|
603
617
|
choice(c.recency, ["any", "day", "week", "month", "year"], "recency");
|
|
@@ -609,7 +623,8 @@ var NiteSearchClient = (() => {
|
|
|
609
623
|
num(c.retry.maxRetries, 0, 5, "retry.maxRetries");
|
|
610
624
|
num(c.retry.initialDelayMs, 0, 6e4, "retry.initialDelayMs");
|
|
611
625
|
num(c.retry.maxDelayMs, 0, 12e4, "retry.maxDelayMs");
|
|
612
|
-
if (c.retry.initialDelayMs > c.retry.maxDelayMs)
|
|
626
|
+
if (c.retry.initialDelayMs > c.retry.maxDelayMs)
|
|
627
|
+
fail("retry.maxDelayMs", "Maximum delay must not be shorter than initial delay.");
|
|
613
628
|
num(c.cache.ttlSeconds, 1, 86400, "cache.ttlSeconds");
|
|
614
629
|
num(c.cache.maxEntries, 1, 1e3, "cache.maxEntries");
|
|
615
630
|
num(c.breaker.threshold, 1, 100, "breaker.threshold");
|
|
@@ -619,25 +634,32 @@ var NiteSearchClient = (() => {
|
|
|
619
634
|
const b = c.backends[d.id];
|
|
620
635
|
const p = `backends.${d.id}`;
|
|
621
636
|
choice(b.mode, d.modes.map((m) => m.mode), `${p}.mode`);
|
|
622
|
-
if (b.enabled && d.status === "unverified")
|
|
637
|
+
if (b.enabled && d.status === "unverified")
|
|
638
|
+
fail(`${p}.enabled`, "Backend protocol is not verified.");
|
|
623
639
|
if (b.endpoint) {
|
|
624
640
|
try {
|
|
625
641
|
const url = new URL(b.endpoint);
|
|
626
|
-
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.hash || url.search)
|
|
642
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.hash || url.search)
|
|
643
|
+
throw 0;
|
|
627
644
|
const local = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]";
|
|
628
|
-
if (url.protocol === "http:" && !local)
|
|
645
|
+
if (url.protocol === "http:" && !local)
|
|
646
|
+
throw 0;
|
|
629
647
|
} catch {
|
|
630
648
|
fail(`${p}.endpoint`, "Use an HTTPS endpoint without credentials, query, or fragment; HTTP is allowed only on loopback.");
|
|
631
649
|
}
|
|
632
|
-
} else if (b.enabled)
|
|
633
|
-
|
|
650
|
+
} else if (b.enabled)
|
|
651
|
+
fail(`${p}.endpoint`, "An endpoint is required.");
|
|
652
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(b.credentialRef))
|
|
653
|
+
fail(`${p}.credentialRef`, "Expected an environment-style credential reference.");
|
|
634
654
|
num(b.timeoutMs, 1e3, 12e4, `${p}.timeoutMs`);
|
|
635
655
|
num(b.rateLimitPerMinute, 0, 1e5, `${p}.rateLimitPerMinute`);
|
|
636
656
|
num(b.dailyAttemptLimit, 0, 1e6, `${p}.dailyAttemptLimit`);
|
|
637
657
|
for (const o of d.options) {
|
|
638
658
|
const v = b.options[o.key];
|
|
639
|
-
if (o.choices && !o.choices.includes(String(v)))
|
|
640
|
-
|
|
659
|
+
if (o.choices && !o.choices.includes(String(v)))
|
|
660
|
+
fail(`${p}.options.${o.key}`, "Unsupported option.");
|
|
661
|
+
if (typeof v === "number")
|
|
662
|
+
num(v, o.min ?? 1, o.max ?? 1e5, `${p}.options.${o.key}`);
|
|
641
663
|
}
|
|
642
664
|
}
|
|
643
665
|
return issues;
|