@240xu/dsh-websearch 2.8.7 → 2.8.9

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 CHANGED
@@ -8,6 +8,7 @@
8
8
  *
9
9
  * @module dsh-websearch
10
10
  */
11
+ import z from "@deepseek-ai/schemastery";
11
12
  import { credentialRef } from "@deepseek-ai/dsh-credentials";
12
13
  // NOTE (2026-09-12, dsh 0.1.5 compat): installSettingsSection +
13
14
  // settingsNamespace were removed from @deepseek-ai/dsh-settings in the 0.1.5
@@ -17,6 +18,7 @@ import { credentialRef } from "@deepseek-ai/dsh-credentials";
17
18
  // plain string "unified-search". No import needed anymore.
18
19
  import { launchEnvironmentOf } from "@deepseek-ai/dsh-launch-environment";
19
20
  import { WebError } from "@deepseek-ai/dsh-web";
21
+ import { findPluginRow } from "./util/namespace.js";
20
22
 
21
23
  // Import all backends
22
24
  import { exaBackend } from "./backends/exa.js";
@@ -32,6 +34,9 @@ import { tavilyBackend } from "./backends/tavily.js";
32
34
  import { serperBackend } from "./backends/serper.js";
33
35
  import { searxngBackend } from "./backends/searxng.js";
34
36
  import { mojeekBackend } from "./backends/mojeek.js";
37
+ // OpenCode v2 keyless MCP backends.
38
+ import { firecrawlBackend } from "./backends/firecrawl.js";
39
+ import { tinyfishBackend } from "./backends/tinyfish.js";
35
40
  import { createUnifiedSearchProvider, getLatestBackendHealth } from "./provider.js";
36
41
  import { registerHealthRoute } from "./health.js";
37
42
  import { createSearchCache, CACHE_DEFAULTS } from "./cache.js";
@@ -41,9 +46,6 @@ import { BREAKER_DEFAULTS } from "./breaker.js";
41
46
  import os from "node:os";
42
47
  import path from "node:path";
43
48
 
44
- import { Config, DEFAULT_KEY_ENV, DEFAULT_BASE_URLS, DEFAULT_MODELS, DEFAULT_LABELS } from "./config.js";
45
- export { Config };
46
-
47
49
  /** Cordis plugin name used by loader diagnostics. */
48
50
  export const name = "unified-search";
49
51
  /** The web seam this provider registers into. */
@@ -65,16 +67,258 @@ const BACKENDS = {
65
67
  deepseek: deepseekBackend,
66
68
  anthropic: anthropicBackend,
67
69
  openai: openaiBackend,
70
+ // Appended last so default fan-out order is unchanged.
71
+ // Both are opt-in (not in DEFAULT_ENABLED): their keyless tiers are metered
72
+ // and Firecrawl's exact daily ceiling is not published by the vendor.
73
+ firecrawl: firecrawlBackend,
74
+ tinyfish: tinyfishBackend,
68
75
  };
69
76
 
70
77
  /** All backend ids in registry order. */
71
78
  const ALL_BACKENDS = Object.keys(BACKENDS);
72
79
 
80
+ /** Backends enabled by default (keyless only). */
81
+ // Firecrawl/TinyFish are intentionally absent here — enable them
82
+ // explicitly via the Settings toggles once their keyless quotas are reviewed.
83
+ const DEFAULT_ENABLED = ["exa", "parallel", "ddg", "searxng"];
84
+
85
+ /** Environment-variable names each key-gated backend reads. */
86
+ const DEFAULT_KEY_ENV = {
87
+ deepseek: "DEEPSEEK_API_KEY",
88
+ anthropic: "ANTHROPIC_API_KEY",
89
+ openai: "OPENAI_API_KEY",
90
+ brave: "BRAVE_API_KEY",
91
+ tavily: "TAVILY_API_KEY",
92
+ serper: "SERPER_API_KEY",
93
+ mojeek: "MOJEEK_API_KEY",
94
+ // Optional keys; keyless works without them.
95
+ firecrawl: "FIRECRAWL_API_KEY",
96
+ tinyfish: "TINYFISH_API_KEY",
97
+ };
98
+
99
+ /** Backends whose key only raises the hosted tier's limits, not a prerequisite. */
100
+ const OPTIONAL_KEY_IDS = new Set(["searxng", "firecrawl", "tinyfish"]);
101
+ /** Metered, opt-in backends surfaced separately in the card. */
102
+ const METERED_IDS = new Set(["firecrawl", "tinyfish"]);
103
+
104
+ /** Default base URLs. */
105
+ const DEFAULT_BASE_URLS = {
106
+ exa: "https://mcp.exa.ai/mcp",
107
+ parallel: "https://search.parallel.ai/mcp",
108
+ ddg: "https://html.duckduckgo.com/html/",
109
+ searxng: "https://searx.be",
110
+ brave: "https://api.search.brave.com/res/v1/web/search",
111
+ tavily: "https://api.tavily.com/search",
112
+ serper: "https://google.serper.dev/search",
113
+ mojeek: "https://api.mojeek.com/v1/search",
114
+ deepseek: "https://api.deepseek.com/anthropic/v1",
115
+ anthropic: "https://api.anthropic.com/v1",
116
+ openai: "https://api.openai.com/v1",
117
+ // OpenCode v2 source endpoints; overridable via the
118
+ // matching *BaseURL settings so a TLS-fingerprint sidecar can be pointed at.
119
+ firecrawl: "https://mcp.firecrawl.dev/v2/mcp",
120
+ tinyfish: "https://agent.tinyfish.ai/mcp",
121
+ };
122
+
73
123
  /** Env var that overrides the default backend sweep order / enabled set. */
74
124
  const ENABLED_ENV = "DSH_UNIFIED_SEARCH_BACKENDS";
75
125
 
76
- /** Backends enabled by default (keyless only). */
77
- const DEFAULT_ENABLED = ["exa", "parallel", "ddg", "searxng"];
126
+ /** Default models for model-carrying backends. */
127
+ const DEFAULT_MODELS = {
128
+ deepseek: "deepseek-v4-flash",
129
+ anthropic: "claude-sonnet-4-6",
130
+ openai: "gpt-4o",
131
+ };
132
+
133
+ /**
134
+ * GUI-friendly labels for each backend (shown in the Settings panel).
135
+ */
136
+ const DEFAULT_LABELS = {
137
+ exa: "Exa (MCP, 免费无 Key)",
138
+ parallel: "Parallel (MCP, 免费无 Key)",
139
+ ddg: "DuckDuckGo (HTML 抓取, 兜底)",
140
+ searxng: "SearXNG (元搜索, 免费无 Key)",
141
+ brave: "Brave Search (独立索引, 2000/月免费)",
142
+ tavily: "Tavily (AI 专用, 含答案摘要)",
143
+ serper: "Serper.dev (Google 抓取, 2500/月免费)",
144
+ mojeek: "Mojeek (独立索引, 1000/天免费)",
145
+ deepseek: "DeepSeek (原生 web_search, 需 Key)",
146
+ anthropic: "Anthropic (Claude 原生 web_search, 需 Key)",
147
+ openai: "OpenAI (Responses API web_search, 需 Key)",
148
+ // Labels surfaced in the Settings panel; the keyless tier is rate limited,
149
+ // which is why both toggles default to off.
150
+ firecrawl: "Firecrawl (MCP, keyless with quota, off by default)",
151
+ tinyfish: "TinyFish (MCP, keyless 30/min and 50/day, off by default)",
152
+ };
153
+
154
+ /**
155
+ * Settings schema — flat, GUI-friendly. Every object property is optional by
156
+ * default in schemastery; defaults are supplied via .default(). API keys are
157
+ * credential-refs (env-var names), which the Settings UI renders as a
158
+ * credential selector / secret field.
159
+ */
160
+ export const Config = z.object({
161
+ // Global
162
+ intervention: z.union(["official", "balanced", "thorough"]).default("balanced")
163
+ .description("搜索介入程度【策略】:official=只做官方 provider 该做的(原样查询、不加结果头/遥测、沿用工具的条数上限);balanced=确定性去噪 + 去重/遥测(默认);thorough=额外启用相关性重排与深度覆盖(内部多查询仍是独立开关,默认关)"),
164
+ numResults: z.number().step(1).min(1).max(50).default(10)
165
+ .description("每次搜索返回的最大结果数(official 档沿用宿主工具的条数上限)"),
166
+ concurrency: z.number().step(1).min(1).max(10).default(6)
167
+ .description("同时并发的后端数量"),
168
+ backendTimeoutMs: z.number().step(1000).min(1000).max(120000).default(30000)
169
+ .description("单后端最大等待时间(毫秒)"),
170
+
171
+ // v2.1 result shaping
172
+ recency: z.union(["any", "day", "week", "month", "year"]).default("any")
173
+ .description("时间范围过滤(映射到各后端原生参数;any=不过滤)"),
174
+ language: z.string().default("")
175
+ .description("搜索语言(如 en、zh-CN;留空用各后端默认)"),
176
+ safeSearch: z.boolean().default(true)
177
+ .description("安全搜索(SearXNG / Brave 支持开关,其余后端忽略)"),
178
+ dedupStrategy: z.union(["url", "url+title"]).default("url")
179
+ .description("去重策略:url 仅按链接;url+title 额外合并同标题的转载镜像"),
180
+ rerank: z.boolean().default(false)
181
+ .description("按查询词相关性重排序(确定性、并列时保持后端优先级)"),
182
+ resultTelemetry: z.boolean().default(true)
183
+ .description("在搜索结果尾部附一行后端健康遥测(状态+耗时),模型可据此自诊断"),
184
+
185
+ // v2.7.0 disk cache / circuit breaker / search history
186
+ // W1 (fe-ui review): labels speak user language with a group prefix
187
+ // (【缓存】/【熔断】/【历史】) instead of camelCase keys; units are
188
+ // spelled out (秒 / 毫秒) and grouping follows the field order below.
189
+ cacheEnabled: z.boolean().default(true)
190
+ .description("启用搜索结果缓存【缓存】:相同查询+过滤+条数在有效期内直接命中,不再请求后端"),
191
+ cacheTtl: z.number().step(30).min(30).max(86400).default(900)
192
+ .description("缓存有效期【缓存】(单位:秒):默认 900 秒;不想用缓存请直接关闭上一项"),
193
+ breakerEnabled: z.boolean().default(true)
194
+ .description("后端熔断器【熔断】:连续失败达阈值后暂停该后端一段时间;全部暂停时自动放行,不会让搜索更差"),
195
+ breakerThreshold: z.number().step(1).min(1).max(20).default(BREAKER_DEFAULTS.threshold)
196
+ .description("熔断阈值【熔断】:连续失败多少次后触发(默认 3 次)"),
197
+ breakerCooldownMs: z.number().step(1000).min(0).max(3600000).default(BREAKER_DEFAULTS.cooldownMs)
198
+ .description("熔断冷却时长【熔断】(单位:毫秒):默认 60000;设为 0 表示关闭冷却(熔断仅计数)"),
199
+ historyEnabled: z.boolean().default(true)
200
+ .description("记录搜索历史【历史】:只追加,最多 50 条;可在设置 → 搜索 中查看与清空"),
201
+
202
+ // v2.8.0 查全查多
203
+ multiQueryEnabled: z.boolean().default(false)
204
+ .description("多查询融合【查全】:复杂查询(长度>60 或含 vs/and/比较/对比/和)自动派生 2-3 个子查询,各扇出后用 RRF(k=60) 融合;默认关"),
205
+ deepCoverage: z.boolean().default(false)
206
+ .description("深度覆盖【查全】:每后端请求条数上调 50% 再全局去重截断,牺牲带宽换覆盖面;Tavily 自动切 advanced 深度,SearXNG 扩展多类目;默认关"),
207
+
208
+ // Enable toggles (one per backend)
209
+ enableExa: z.boolean().default(true).description(DEFAULT_LABELS.exa),
210
+ enableParallel: z.boolean().default(true).description(DEFAULT_LABELS.parallel),
211
+ enableDdg: z.boolean().default(true).description(DEFAULT_LABELS.ddg),
212
+ enableSearxng: z.boolean().default(true).description(DEFAULT_LABELS.searxng),
213
+ enableBrave: z.boolean().default(false).description(DEFAULT_LABELS.brave),
214
+ enableTavily: z.boolean().default(false).description(DEFAULT_LABELS.tavily),
215
+ enableSerper: z.boolean().default(false).description(DEFAULT_LABELS.serper),
216
+ enableMojeek: z.boolean().default(false).description(DEFAULT_LABELS.mojeek),
217
+ enableDeepseek: z.boolean().default(false).description(DEFAULT_LABELS.deepseek),
218
+ enableAnthropic: z.boolean().default(false).description(DEFAULT_LABELS.anthropic),
219
+ enableOpenai: z.boolean().default(false).description(DEFAULT_LABELS.openai),
220
+ // Opt-in by default; see DEFAULT_ENABLED comment.
221
+ enableFirecrawl: z.boolean().default(false).description(DEFAULT_LABELS.firecrawl),
222
+ enableTinyfish: z.boolean().default(false).description(DEFAULT_LABELS.tinyfish),
223
+
224
+ // Credential refs (env-var names; secrets live in the credentials service)
225
+ braveApiKeyEnv: z.string().role("credential-ref").pattern(/^[A-Za-z_][A-Za-z0-9_]*$/).min(1).default(DEFAULT_KEY_ENV.brave)
226
+ .description("Brave API Key 的凭证引用(填环境变量名,实际密钥存凭证库)"),
227
+ tavilyApiKeyEnv: z.string().role("credential-ref").pattern(/^[A-Za-z_][A-Za-z0-9_]*$/).min(1).default(DEFAULT_KEY_ENV.tavily)
228
+ .description("Tavily API Key 的凭证引用(填环境变量名,实际密钥存凭证库)"),
229
+ serperApiKeyEnv: z.string().role("credential-ref").pattern(/^[A-Za-z_][A-Za-z0-9_]*$/).min(1).default(DEFAULT_KEY_ENV.serper)
230
+ .description("Serper API Key 的凭证引用(填环境变量名,实际密钥存凭证库)"),
231
+ mojeekApiKeyEnv: z.string().role("credential-ref").pattern(/^[A-Za-z_][A-Za-z0-9_]*$/).min(1).default(DEFAULT_KEY_ENV.mojeek)
232
+ .description("Mojeek API Key 的凭证引用(填环境变量名,实际密钥存凭证库)"),
233
+ deepseekApiKeyEnv: z.string().role("credential-ref").pattern(/^[A-Za-z_][A-Za-z0-9_]*$/).min(1).default(DEFAULT_KEY_ENV.deepseek)
234
+ .description("Deepseek API Key 的凭证引用(填环境变量名,实际密钥存凭证库)"),
235
+ anthropicApiKeyEnv: z.string().role("credential-ref").pattern(/^[A-Za-z_][A-Za-z0-9_]*$/).min(1).default(DEFAULT_KEY_ENV.anthropic)
236
+ .description("Anthropic API Key 的凭证引用(填环境变量名,实际密钥存凭证库)"),
237
+ openaiApiKeyEnv: z.string().role("credential-ref").pattern(/^[A-Za-z_][A-Za-z0-9_]*$/).min(1).default(DEFAULT_KEY_ENV.openai)
238
+ .description("Openai API Key 的凭证引用(填环境变量名,实际密钥存凭证库)"),
239
+ searxngApiKeyEnv: z.string().role("credential-ref").pattern(/^[A-Za-z_][A-Za-z0-9_]*$/).min(1).default("SEARXNG_API_KEY")
240
+ .description("SearXNG 私有实例的 API Key 凭证引用(公共实例留空)"),
241
+ // Optional: both backends work keyless. Supplying a key only raises the
242
+ // hosted tier's limits (and for TinyFish activates the session handshake).
243
+ firecrawlApiKeyEnv: z.string().role("credential-ref").pattern(/^[A-Za-z_][A-Za-z0-9_]*$/).min(1).default(DEFAULT_KEY_ENV.firecrawl)
244
+ .description("Firecrawl API key credential reference (optional; blank uses the hosted keyless tier)"),
245
+ tinyfishApiKeyEnv: z.string().role("credential-ref").pattern(/^[A-Za-z_][A-Za-z0-9_]*$/).min(1).default(DEFAULT_KEY_ENV.tinyfish)
246
+ .description("TinyFish API key credential reference (optional; blank uses keyless mode)"),
247
+
248
+ // Base URLs (defaults from built-in registry)
249
+ braveBaseURL: z.string().default(DEFAULT_BASE_URLS.brave)
250
+ .description("Brave API 端点(默认官方;自托管/代理实例改此项)"),
251
+ tavilyBaseURL: z.string().default(DEFAULT_BASE_URLS.tavily)
252
+ .description("Tavily API 端点(默认官方;自托管/代理实例改此项)"),
253
+ serperBaseURL: z.string().default(DEFAULT_BASE_URLS.serper)
254
+ .description("Serper.dev API 端点(默认官方;自托管/代理实例改此项)"),
255
+ mojeekBaseURL: z.string().default(DEFAULT_BASE_URLS.mojeek)
256
+ .description("Mojeek API 端点(默认官方;自托管/代理实例改此项)"),
257
+ searxngBaseURL: z.string().default(DEFAULT_BASE_URLS.searxng)
258
+ .description("SearXNG API 端点(默认官方;自托管/代理实例改此项)"),
259
+ searxngBaseURLs: z.array(z.string()).default([])
260
+ .description("SearXNG 备用实例列表(可选;主实例失败时按序尝试,失败实例冷却 10 分钟)"),
261
+ deepseekBaseURL: z.string().default(DEFAULT_BASE_URLS.deepseek)
262
+ .description("DeepSeek API 端点(默认官方;自托管/代理实例改此项)"),
263
+ anthropicBaseURL: z.string().default(DEFAULT_BASE_URLS.anthropic)
264
+ .description("Anthropic API 端点(默认官方;自托管/代理实例改此项)"),
265
+ openaiBaseURL: z.string().default(DEFAULT_BASE_URLS.openai)
266
+ .description("OpenAI API 端点(默认官方;自托管/代理实例改此项)"),
267
+ // resolveOptions() derives `${id}BaseURL` for every id, so these two fields
268
+ // are required for the sidecar/proxy path.
269
+ firecrawlBaseURL: z.string().default(DEFAULT_BASE_URLS.firecrawl)
270
+ .description("Firecrawl MCP endpoint (official v2 by default; may point at a TLS sidecar)"),
271
+ tinyfishBaseURL: z.string().default(DEFAULT_BASE_URLS.tinyfish)
272
+ .description("TinyFish MCP endpoint (official by default; may point at a TLS sidecar)"),
273
+
274
+ // Models
275
+ deepseekModel: z.string().default(DEFAULT_MODELS.deepseek)
276
+ .description("DeepSeek 后端使用的模型名"),
277
+ anthropicModel: z.string().default(DEFAULT_MODELS.anthropic)
278
+ .description("Anthropic 后端使用的模型名"),
279
+ openaiModel: z.string().default(DEFAULT_MODELS.openai)
280
+ .description("OpenAI 后端使用的模型名"),
281
+ tavilySearchDepth: z.union(["basic", "advanced"]).default("basic")
282
+ .description("Tavily 搜索深度"),
283
+
284
+ // Legacy compatibility: explicit enabled-backend list overrides toggles
285
+ enabledBackends: z.array(z.string())
286
+ .description("显式启用后端列表(优先于上方开关;留空则用开关)"),
287
+ });
288
+
289
+ // 0.2.0 SettingsForms adapter (cross-settings-forms.md ruling): the 0.2.0
290
+ // settings service auto-generates its form from entry.fiber.runtime.Config —
291
+ // but volatileForm (RT dsh-settings lib/index.js:122-138) keeps ONLY fields
292
+ // with meta.volatile; a Config without any yields an empty form. Marking the
293
+ // top object makes the whole Config the form. Direct meta assignment (not
294
+ // .volatile(), which returns a NEW schema and throws on re-wrap) is
295
+ // equivalent and idempotent on both the 0.1.5 and 0.2.0 schemastery lines.
296
+ Config.meta = { ...Config.meta, volatile: true };
297
+
298
+ /**
299
+ * Per-field user-language labels (fe-ui W1 remainder): the settings renderer
300
+ * falls back to camelCase keys when no label is present, so attach one to
301
+ * each v2.7 descriptor (meta.label, plus a plain .label for renderers that
302
+ * read the top level). Units live in the label tail (秒 / 毫秒). Whether the
303
+ * host actually renders them is visual-check V5; the schema layer now
304
+ * provides the field regardless.
305
+ */
306
+ const FIELD_LABELS = {
307
+ intervention: "搜索介入程度",
308
+ cacheEnabled: "启用搜索结果缓存",
309
+ cacheTtl: "缓存有效期(秒)",
310
+ breakerEnabled: "后端熔断器",
311
+ breakerThreshold: "熔断阈值(连续失败次数)",
312
+ breakerCooldownMs: "熔断冷却时长(毫秒)",
313
+ historyEnabled: "记录搜索历史",
314
+ };
315
+ for (const [key, label] of Object.entries(FIELD_LABELS)) {
316
+ const sch = Config.dict?.[key];
317
+ if (sch) {
318
+ sch.meta = { ...sch.meta, label };
319
+ sch.label = label;
320
+ }
321
+ }
78
322
 
79
323
  /**
80
324
  * Project one resolved settings section into the options snapshot the provider
@@ -82,7 +326,9 @@ const DEFAULT_ENABLED = ["exa", "parallel", "ddg", "searxng"];
82
326
  * service -> env.
83
327
  */
84
328
  export function resolveOptions(ctx, config) {
85
- // 1. Determine enabled backends: explicit list > toggles > env > defaults
329
+ // 1. Determine enabled backends: explicit list > toggles > env > defaults.
330
+ // The four keyless toggles default to true, so the env fallback is reachable
331
+ // only when all toggles are explicitly disabled; see README Known Limitation.
86
332
  let enabledBackends = [];
87
333
 
88
334
  if (config?.enabledBackends && config.enabledBackends.length > 0) {
@@ -90,20 +336,9 @@ export function resolveOptions(ctx, config) {
90
336
  }
91
337
 
92
338
  if (enabledBackends.length === 0) {
93
- const toggleMap = {
94
- exa: config?.enableExa,
95
- parallel: config?.enableParallel,
96
- ddg: config?.enableDdg,
97
- searxng: config?.enableSearxng,
98
- brave: config?.enableBrave,
99
- tavily: config?.enableTavily,
100
- serper: config?.enableSerper,
101
- mojeek: config?.enableMojeek,
102
- deepseek: config?.enableDeepseek,
103
- anthropic: config?.enableAnthropic,
104
- openai: config?.enableOpenai,
105
- };
106
- enabledBackends = ALL_BACKENDS.filter((id) => toggleMap[id] === true);
339
+ // The Config schema names each backend's toggle `enable<Capitalized id>`;
340
+ // deriving the key keeps this in sync with BACKENDS automatically.
341
+ enabledBackends = ALL_BACKENDS.filter((id) => config?.[`enable${id.charAt(0).toUpperCase()}${id.slice(1)}`] === true);
107
342
  }
108
343
 
109
344
  if (enabledBackends.length === 0) {
@@ -138,7 +373,9 @@ export function resolveOptions(ctx, config) {
138
373
  } : {}),
139
374
  safeSearch: config?.safeSearch !== false,
140
375
  label: DEFAULT_LABELS[id] ?? id,
141
- requiresKey: DEFAULT_KEY_ENV[id] !== undefined,
376
+ requiresKey: DEFAULT_KEY_ENV[id] !== undefined && !OPTIONAL_KEY_IDS.has(id),
377
+ optionalKey: OPTIONAL_KEY_IDS.has(id),
378
+ metered: METERED_IDS.has(id),
142
379
  resolveApiKey: async () => {
143
380
  const credentials = ctx.get("credentials");
144
381
  if (credentials !== undefined) return (await credentials.resolve(ref))?.value;
@@ -149,18 +386,33 @@ export function resolveOptions(ctx, config) {
149
386
  }
150
387
 
151
388
  const language = typeof config?.language === "string" ? config.language.trim() : "";
389
+ // Coarse intervention preset. `balanced` is the historical default and keeps
390
+ // every field independently configurable; `official` removes provider-level
391
+ // rewriting/presentation so the consumer (dsh-tool-web) owns them; `thorough`
392
+ // opts into the expensive stages. Explicit non-default flags still win under
393
+ // `balanced` only — the presets are authoritative by design.
394
+ const intervention = ["official", "balanced", "thorough"].includes(config?.intervention)
395
+ ? config.intervention
396
+ : "balanced";
397
+ const official = intervention === "official";
398
+ const thorough = intervention === "thorough";
152
399
 
153
400
  return {
154
401
  enabledBackends,
155
- numResults: config?.numResults ?? 8,
402
+ intervention,
403
+ queryShaping: !official,
404
+ // official follows the consumer's maxResults bound; the other tiers keep
405
+ // the user's explicit count (and still never exceed the host cap).
406
+ numResults: official ? undefined : (config?.numResults ?? 10),
156
407
  concurrency: config?.concurrency ?? 6,
157
408
  backendTimeoutMs: config?.backendTimeoutMs ?? 30000,
158
409
  // v2.1 shaping options consumed by the provider merge pipeline.
159
410
  dedupStrategy: config?.dedupStrategy === "url+title" ? "url+title" : "url",
160
- rerank: config?.rerank === true,
161
- resultTelemetry: config?.resultTelemetry !== false,
411
+ rerank: thorough || (!official && config?.rerank === true),
412
+ resultHeader: official ? false : config?.resultHeader !== false,
413
+ resultTelemetry: official ? false : config?.resultTelemetry !== false,
162
414
  // v2.7.0 cache / breaker / history
163
- cacheEnabled: config?.cacheEnabled === true,
415
+ cacheEnabled: config?.cacheEnabled !== false,
164
416
  cacheTtlS: Math.max(30, Math.floor(Number(config?.cacheTtl) || CACHE_DEFAULTS.ttlMs / 1000)),
165
417
  breakerEnabled: config?.breakerEnabled !== false,
166
418
  breakerThreshold: Math.max(1, Math.floor(Number(config?.breakerThreshold) || BREAKER_DEFAULTS.threshold)),
@@ -169,8 +421,12 @@ export function resolveOptions(ctx, config) {
169
421
  : BREAKER_DEFAULTS.cooldownMs,
170
422
  historyEnabled: config?.historyEnabled !== false,
171
423
  // v2.8.0 coverage / multiQuery
172
- multiQueryEnabled: config?.multiQueryEnabled === true,
173
- deepCoverage: config?.deepCoverage === true,
424
+ // Internal multi-query stays an explicit opt-in in every tier: the
425
+ // official consumer already lets the model send 1-10 queries per call and
426
+ // merges them round-robin, so a "thorough" preset must not multiply calls
427
+ // invisibly.
428
+ multiQueryEnabled: !official && config?.multiQueryEnabled === true,
429
+ deepCoverage: thorough || (!official && config?.deepCoverage === true),
174
430
  filters: {
175
431
  recency: typeof config?.recency === "string" && config.recency !== "any" ? config.recency : undefined,
176
432
  lang: language.length > 0 ? language : undefined,
@@ -215,11 +471,28 @@ export function apply(ctx, config) {
215
471
  });
216
472
  return;
217
473
  }
218
- // 0.2.x SettingsForms line: no installSection. Keep the service so the
219
- // browser settings card can read/write this profile entry through the
220
- // fenced bridge in ./settings-api.js; values keep resolving via cordis
221
- // config (the same volatile entry), so there is no second settings store.
222
- if (typeof settings?.describe === "function" && typeof settings?.mutate === "function") settingsForms = settings;
474
+ // 0.2.x SettingsForms line: no installSection. The entry-level `config`
475
+ // passed to apply() carries only schema defaults on DSH 0.2.x; the live
476
+ // profile-patch / user values live in the settings service's effective
477
+ // config. Reading them per search is what makes the Settings card actually
478
+ // drive execution. Without this, saving a toggle writes to the settings
479
+ // service but `current()` keeps returning the stale initial config, so
480
+ // the save is a no-op. Mirrors the upstream settings-inert fix.
481
+ if (typeof settings?.describe === "function" && typeof settings?.mutate === "function") {
482
+ settingsForms = settings;
483
+ // Read the live settings-service values on every resolve so a save
484
+ // from the card drives the next search. Exact namespace ids take
485
+ // priority over the shape fallback; findPluginRow is shared with the
486
+ // HTTP bridge so both resolve the same row.
487
+ current = () => {
488
+ try {
489
+ const row = findPluginRow(settings.describe());
490
+ return (row && row.value) ?? config;
491
+ } catch {
492
+ return config;
493
+ }
494
+ };
495
+ }
223
496
  });
224
497
 
225
498
  // v2.7.0 stores: disk cache + append-only search history, both under
@@ -241,10 +514,9 @@ export function apply(ctx, config) {
241
514
  ctx,
242
515
  resolveOptions: () => resolveOptions(ctx, current()),
243
516
  backends: BACKENDS,
244
- cache: {
245
- get: (key) => searchCache.get(key),
246
- set: (key, value) => searchCache.set(key, value),
247
- },
517
+ // The provider only reads and writes through get/set, both of which the
518
+ // store already exposes; wrapping them added nothing but indirection.
519
+ cache: searchCache,
248
520
  history: {
249
521
  record: (entry) => {
250
522
  if (resolveOptions(ctx, current()).historyEnabled !== true) return;
@@ -268,26 +540,48 @@ export function apply(ctx, config) {
268
540
  return undefined;
269
541
  }
270
542
  };
271
- registerHealthRoute(webCtx.webServer, {
272
- resolveOptions: () => resolveOptions(ctx, current()),
273
- backends: BACKENDS,
274
- getBackendHealth: getLatestBackendHealth,
275
- getConnection,
276
- });
277
- // v2.7.0 search history: read-only GET + explicit clear POST.
278
- // v2.8.0: GET also carries per-backend last-outcome observability.
279
- registerHistoryRoutes(webCtx.webServer, {
280
- getStore: () => historyStore,
281
- getBackendHealth: getLatestBackendHealth,
282
- getConnection,
283
- });
284
- // Settings bridge for the browser card on 0.2.x builds (no legacy
285
- // settingsScope service). Fenced by the host connection admission; writes
286
- // land in the volatile config entry above.
287
- registerSettingsRoutes(webCtx.webServer, {
288
- getSettings: () => settingsForms,
289
- getConfig: () => Config,
290
- getConnection,
291
- });
543
+ // Registrations are effects: WebServer.register() returns the disposer
544
+ // removing the route, so hand all of them to the injection fiber. Without
545
+ // this, a plugin reload leaves the old routes registered and the next
546
+ // load throws on duplicate (kind, path).
547
+ webCtx.effect(() => {
548
+ const disposers = [];
549
+ // Register incrementally: WebServer.register throws on a duplicate
550
+ // (kind, path). If one throws mid-way, roll back the routes already
551
+ // acquired, otherwise the effect exits without a disposer and those
552
+ // routes leak permanently (a later reload then conflicts with them).
553
+ const registers = [
554
+ () => registerHealthRoute(webCtx.webServer, {
555
+ resolveOptions: () => resolveOptions(ctx, current()),
556
+ backends: BACKENDS,
557
+ getBackendHealth: getLatestBackendHealth,
558
+ getConnection,
559
+ }),
560
+ // v2.7.0 search history: read-only GET + explicit clear POST.
561
+ // v2.8.0: GET also carries per-backend last-outcome observability.
562
+ () => registerHistoryRoutes(webCtx.webServer, {
563
+ getStore: () => historyStore,
564
+ getBackendHealth: getLatestBackendHealth,
565
+ getConnection,
566
+ }),
567
+ // Settings bridge for the browser card on 0.2.x builds (no legacy
568
+ // settingsScope service). Fenced by the host connection admission;
569
+ // writes land in the volatile config entry above.
570
+ () => registerSettingsRoutes(webCtx.webServer, {
571
+ getSettings: () => settingsForms,
572
+ getConfig: () => Config,
573
+ getConnection,
574
+ }),
575
+ ];
576
+ try {
577
+ for (const register of registers) disposers.push(...register());
578
+ } catch (err) {
579
+ for (const dispose of disposers.reverse()) {
580
+ try { dispose(); } catch { /* best-effort rollback */ }
581
+ }
582
+ throw err;
583
+ }
584
+ return () => disposers.forEach((dispose) => dispose());
585
+ }, "unified-search: web routes");
292
586
  });
293
587
  }
package/lib/prompting.js CHANGED
@@ -26,11 +26,20 @@
26
26
  /** 查询硬上限(Tavily:agent 查询应简短聚焦;>1500 字符视为跑题长文)。 */
27
27
  export const QUERY_MAX_CHARS = 1500;
28
28
 
29
- /** 去口语化前缀(中英常见寒暄/请求词,确定性剥离,不改写语义)。 */
29
+ /**
30
+ * Conversational prefixes that are safe to strip. Bare verbs and question
31
+ * words are deliberately absent: "search", "find", "google", "what is" can be
32
+ * part of the subject ("searching algorithms", "findability testing", "google
33
+ * search api"), and `\b` alone is not enough because "find" is a word prefix
34
+ * of "findability". Quotes are search operators and are never stripped.
35
+ */
30
36
  const FILLER_PREFIX_RE =
31
- /^(?:please|pls|kindly|could you(?: please)?|can you(?: please)?|help me(?: to)?|search for|search|look up|google|find me|find|i(?:'d| would)? like to know|tell me|what is|who is|when is|where is|"|「|『)\s*/i;
37
+ /^(?:please|pls|kindly|could you(?: please)?|can you(?: please)?|would you(?: please)?|help me(?: to)?|i(?:'d| would)? like to know|tell me)\b[\s,,]*/i;
32
38
  const FILLER_PREFIX_RE_ZH =
33
- /^(?:请|麻烦|帮我?|帮忙|帮我查一?下|查一?下|查询|搜索一?下?|搜一下?|查一下?|帮我找|找一下?|我想知道|请问)/;
39
+ /^(?:请(?:帮我|帮忙)?(?:查一?下|查询|搜索一下|搜一下|找一下)|麻烦(?:帮我)?(?:查一?下|查询|搜索|搜一下|找一下)|帮我(?:查一?下|查询|搜索|搜一下|找一下|找)|帮忙(?:查一?下|查询|搜索|搜一下|找一下)|(?:查一?下|查询一下|搜索一下|搜一下|找一下)|我想知道|我想了解|请问)/;
40
+
41
+ /** A query that is only a request word ("search", "搜索") has no subject. */
42
+ const PURE_FILLER_RE = /^(?:search|please|pls|kindly|google|find|look up|查询|搜索|搜一下|查一下|请|麻烦|帮我查一下|请问)$/i;
34
43
 
35
44
  /**
36
45
  * 确定性查询整形:剥离口语前缀(循环多次以处理叠加寒暄)、压缩空白、
@@ -41,6 +50,7 @@ const FILLER_PREFIX_RE_ZH =
41
50
  export function shapeQuery(query) {
42
51
  if (typeof query !== "string") return "";
43
52
  let q = query.replace(/\s+/g, " ").trim();
53
+ if (PURE_FILLER_RE.test(q)) return "";
44
54
  // 中文寒暄与英文寒暄交替剥离,直到稳定。
45
55
  for (let i = 0; i < 6; i++) {
46
56
  const before = q;