dsh-union-search 0.19.0 → 0.19.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/lib/index.js +44 -14
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -47,6 +47,29 @@ function fenceMode(admission, restrictLoopback) {
|
|
|
47
47
|
if (admission === "rejection") return restrictLoopback ? "rejection+loopback" : "rejection";
|
|
48
48
|
return "loopback";
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* 读一个服务,**不依赖 inject 声明**(0.19.1 修)。
|
|
52
|
+
*
|
|
53
|
+
* 0.19.0 用 `ctx.get("connection")` 取连接服务,但 `get` 走的是 Proxy 的
|
|
54
|
+
* 「未注入即抛」陷阱——本插件的 inject 列表只有 `webServer`/`settings`,
|
|
55
|
+
* 于是 `connection` 永远抛错被 catch 吞掉,`requestRejection` 分支成了死代码:
|
|
56
|
+
* 真机(dsh 0.2.1-rc.5)上探测一律回 "none",被强制回环,反代部署仍然 403。
|
|
57
|
+
*
|
|
58
|
+
* `ctx.reflect.get(name)` 是 cordis 提供的「不需要 inject 声明」的读取口,用它优先;
|
|
59
|
+
* 老版 cordis 没有 reflect 时再退回 `get`(至少被 inject 过的宿主仍可用)。
|
|
60
|
+
*/
|
|
61
|
+
function readService(ctx, name) {
|
|
62
|
+
try {
|
|
63
|
+
const reflect = ctx?.reflect;
|
|
64
|
+
if (reflect !== void 0 && reflect !== null && typeof reflect.get === "function") {
|
|
65
|
+
const service = reflect.get(name);
|
|
66
|
+
if (service !== void 0 && service !== null) return service;
|
|
67
|
+
}
|
|
68
|
+
} catch {}
|
|
69
|
+
try {
|
|
70
|
+
if (typeof ctx?.get === "function") return ctx.get(name);
|
|
71
|
+
} catch {}
|
|
72
|
+
}
|
|
50
73
|
function detectHostAdmission(ctx) {
|
|
51
74
|
try {
|
|
52
75
|
if (typeof ctx?.bail === "function") {
|
|
@@ -61,10 +84,8 @@ function detectHostAdmission(ctx) {
|
|
|
61
84
|
if (verdict !== void 0 && verdict !== null) return "authorize";
|
|
62
85
|
}
|
|
63
86
|
} catch {}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (connection && typeof connection.requestRejection === "function") return "rejection";
|
|
67
|
-
} catch {}
|
|
87
|
+
const connection = readService(ctx, "connection");
|
|
88
|
+
if (connection && typeof connection.requestRejection === "function") return "rejection";
|
|
68
89
|
return "none";
|
|
69
90
|
}
|
|
70
91
|
/** 能力探测(带进程内缓存),返回本宿主走哪一代准入。 */
|
|
@@ -83,10 +104,8 @@ function probeHostAdmission(ctx) {
|
|
|
83
104
|
* 所以每请求解析一次;未注入时 ctx.get 会抛,包 try(沿用 index.ts:1415 的写法)。
|
|
84
105
|
*/
|
|
85
106
|
function getRequestRejection(ctx) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (connection && typeof connection.requestRejection === "function") return (request) => connection.requestRejection(request);
|
|
89
|
-
} catch {}
|
|
107
|
+
const connection = readService(ctx, "connection");
|
|
108
|
+
if (connection && typeof connection.requestRejection === "function") return (request) => connection.requestRejection(request);
|
|
90
109
|
return null;
|
|
91
110
|
}
|
|
92
111
|
/**
|
|
@@ -95,9 +114,11 @@ function getRequestRejection(ctx) {
|
|
|
95
114
|
*/
|
|
96
115
|
function createBridgeGate(options) {
|
|
97
116
|
const { admission, restrictLoopback, isLoopback, resolveRejection, writeJson } = options;
|
|
117
|
+
let warnedFallback = false;
|
|
98
118
|
return (req, res) => {
|
|
99
119
|
let hostGated = false;
|
|
100
|
-
if (admission === "
|
|
120
|
+
if (admission === "authorize") hostGated = true;
|
|
121
|
+
else {
|
|
101
122
|
const reject = resolveRejection();
|
|
102
123
|
if (typeof reject === "function") {
|
|
103
124
|
hostGated = true;
|
|
@@ -112,8 +133,15 @@ function createBridgeGate(options) {
|
|
|
112
133
|
return false;
|
|
113
134
|
}
|
|
114
135
|
}
|
|
115
|
-
}
|
|
116
|
-
|
|
136
|
+
}
|
|
137
|
+
const loopbackRequired = !hostGated || restrictLoopback() === true;
|
|
138
|
+
if (!hostGated && !warnedFallback) {
|
|
139
|
+
warnedFallback = true;
|
|
140
|
+
try {
|
|
141
|
+
options.onLoopbackFallback?.();
|
|
142
|
+
} catch {}
|
|
143
|
+
}
|
|
144
|
+
if (loopbackRequired && !isLoopback(req)) {
|
|
117
145
|
writeJson(res, 403, { error: "loopback requests only" });
|
|
118
146
|
return false;
|
|
119
147
|
}
|
|
@@ -5440,16 +5468,18 @@ function apply(ctx, config) {
|
|
|
5440
5468
|
hostAdmission = probeHostAdmission(ctx);
|
|
5441
5469
|
}
|
|
5442
5470
|
const structuralMode = fenceMode(hostAdmission, false);
|
|
5443
|
-
|
|
5471
|
+
const warnLoopbackFallback = () => {
|
|
5472
|
+
if (warnedLoopbackFallback) return;
|
|
5444
5473
|
warnedLoopbackFallback = true;
|
|
5445
5474
|
sctx.logger.warn("union-search: host exposes no request admission (no webserver/authorize hook, no connection.requestRejection); settings bridge stays loopback-only and reverse-proxy deployments will get 403");
|
|
5446
|
-
}
|
|
5475
|
+
};
|
|
5447
5476
|
const gate = createBridgeGate({
|
|
5448
5477
|
admission: hostAdmission,
|
|
5449
5478
|
restrictLoopback: () => current().bridgeRestrictLoopback === true,
|
|
5450
5479
|
isLoopback: isLoopbackRequest,
|
|
5451
5480
|
resolveRejection: () => getRequestRejection(ctx),
|
|
5452
|
-
writeJson
|
|
5481
|
+
writeJson,
|
|
5482
|
+
onLoopbackFallback: warnLoopbackFallback
|
|
5453
5483
|
});
|
|
5454
5484
|
const disposers = makeBridgeRoutes(sctx.settings, (request) => provider.search(request, void 0), (engine, query, timeRange) => {
|
|
5455
5485
|
if (effectiveDisabledEngines(current()).includes(engine)) return Promise.resolve({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-union-search",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.1",
|
|
4
4
|
"description": "Union web search for DeepSeek Harness (renamed from dsh-free-search): free keyless engines + many professional paid search APIs — 28 engines (Bing/DuckDuckGo/AnySearch/SearXNG multi-instance union/Exa/Tavily/Keenable/Firecrawl/Parallel keyless; Zhihu global/site via MCP and Perplexity/SerpBase/Serply/DeepSeek official/You.com/Baidu/Kimi/Aliyun/Doubao/Zhipu/Bocha/Metaso with key; OpenAI/Gemini/Claude/Grok model built-in search, explicit-only) + auto smart routing + global engine enable/disable & fallback priority + multi mode (parallel top-3 merge) + multi_search cross-source tool + failure-aware fallback + block system built-in search toggle + experimental free advance_fetch (no API key, no billing; host-twin GitHub-Flavored Markdown conversion + CSS selector/fields structured extraction) + time filtering + platform search + web_fetch, with web settings UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|