dsh-web-search-plugin 0.4.1 → 0.5.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/config.js ADDED
@@ -0,0 +1,29 @@
1
+ /** Supplier-specific configuration names and their pre-prefix aliases. */
2
+ export const SUPPLIER_CONFIG_ALIASES = {
3
+ tavilyApiKey: "apiKey",
4
+ tavilyApiKeyEnv: "apiKeyEnv",
5
+ tavilyBaseURL: "baseURL",
6
+ tavilyMode: "mode",
7
+ tavilySearchDepth: "searchDepth",
8
+ tavilyIncludeAnswer: "includeAnswer",
9
+ tavilyTopic: "topic",
10
+ deepseekModel: "model",
11
+ deepseekApiVersion: "apiVersion",
12
+ deepseekMaxTokens: "maxTokens",
13
+ deepseekMaxUses: "maxUses",
14
+ braveCountry: "country",
15
+ braveSearchLang: "searchLang",
16
+ braveFreshness: "freshness",
17
+ braveProxy: "proxy",
18
+ scavioCountry: "country",
19
+ scavioSearchLang: "searchLang"
20
+ };
21
+
22
+ /** Explicit new values, including false and empty strings, override old names. */
23
+ export function resolveSupplierConfig(config) {
24
+ const resolved = { ...config };
25
+ for (const [field, legacy] of Object.entries(SUPPLIER_CONFIG_ALIASES)) {
26
+ resolved[field] = config[field] ?? config[legacy];
27
+ }
28
+ return resolved;
29
+ }
package/lib/deepseek.js CHANGED
@@ -4,16 +4,25 @@
4
4
  * and returns structured `web_search_tool_result` blocks; absence of those
5
5
  * blocks is an error rather than a prose-scraping fallback.
6
6
  *
7
- * This plugin re-hosts the `deepseek-official` provider so the DeepSeek
8
- * configuration can sit beside Tavily and Brave. The bundle patch disables
9
- * the in-box `web-search-deepseek` host plugin (its namespace feed the legacy
10
- * "plugins → web search" card, and re-registering its provider would collide).
7
+ * This plugin implements DeepSeek as an internal backend so its configuration
8
+ * can sit beside the REST engines. The bundle patch disables
9
+ * the in-box `web-search-deepseek` host plugin so this bundle owns the selected
10
+ * search provider and its configuration. The seam-facing id registered by this
11
+ * plugin is `dsh-web-search`; `deepseek-official` is an internal backend choice.
12
+ *
13
+ * Authentication follows the official provider: a search started from a
14
+ * DeepSeek-account session authenticates with the account token
15
+ * (`x-dsh-auth-token`) when the account service allows this endpoint; every
16
+ * other search reuses `DEEPSEEK_API_KEY`. When a session initiator exists,
17
+ * the secret-free request is recorded as a
18
+ * `web/deepseek-search-llm-request` session event before dispatch.
11
19
  *
12
20
  * @module dsh-web-search-plugin/deepseek
13
21
  */
22
+ import { resolveSupplierConfig } from "./config.js";
14
23
  import { WebError } from "@deepseek-ai/dsh-web";
15
24
  import { launchEnvironmentOf } from "@deepseek-ai/dsh-launch-environment";
16
- import { MAX_RESULTS_CAP, USER_AGENT, isAbortError, resolveApiKey, resolveSecret, searchAborted, throwIfSearchAborted } from "./shared.js";
25
+ import { MAX_RESULTS_CAP, USER_AGENT, abortable, isAbortError, resolveApiKey, resolveSecret, searchAborted, throwIfSearchAborted } from "./shared.js";
17
26
 
18
27
  /** Default endpoint: DeepSeek's Anthropic-compatible API (`/messages` appended). */
19
28
  export const DEEPSEEK_DEFAULT_BASE_URL = "https://api.deepseek.com/anthropic/v1";
@@ -21,7 +30,13 @@ export const DEEPSEEK_DEFAULT_BASE_URL = "https://api.deepseek.com/anthropic/v1"
21
30
  export const DEEPSEEK_DEFAULT_API_KEY_ENV = "DEEPSEEK_API_KEY";
22
31
  /** Environment variable naming this backend's endpoint override. */
23
32
  const DEEPSEEK_SEARCH_BASE_URL_ENV = "DEEPSEEK_SEARCH_BASE_URL";
24
- const DEFAULT_MODEL = "deepseek-v4-flash";
33
+ /**
34
+ * Provider route id `dsh-llm-deepseek-account` registers; the session's
35
+ * `request/context` records it per Session. Only such a session may spend
36
+ * account quota on auxiliary search.
37
+ */
38
+ const ACCOUNT_PROVIDER = "deepseek-account";
39
+ const DEFAULT_MODEL = "deepseek-flash";
25
40
  const DEFAULT_API_VERSION = "2023-06-01";
26
41
  const DEFAULT_MAX_TOKENS = 4096;
27
42
  const DEFAULT_MAX_USES = 5;
@@ -41,7 +56,7 @@ function citationSnippets(blocks) {
41
56
  }
42
57
 
43
58
  /** Map an Anthropic Messages response to a normalized search result. */
44
- function mapAnthropicResponse(response) {
59
+ function mapAnthropicResponse(response, maxResults) {
45
60
  const blocks = response.content ?? [];
46
61
  const resultBlocks = blocks.filter((block) => block.type === "web_search_tool_result");
47
62
  if (resultBlocks.length === 0) throw new WebError("DeepSeek returned no web_search_tool_result blocks; the request may not have triggered native web search", "WEB_PROVIDER_ERROR");
@@ -59,7 +74,9 @@ function mapAnthropicResponse(response) {
59
74
  ...typeof item.page_age === "string" && item.page_age.length > 0 ? { publishedAt: item.page_age } : {}
60
75
  });
61
76
  }
62
- return { sources, truncated: false };
77
+ return sources.length > maxResults
78
+ ? { sources: sources.slice(0, maxResults), truncated: true }
79
+ : { sources, truncated: false };
63
80
  }
64
81
 
65
82
  /** The DeepSeek-backed search backend; HTTP redirects fail as `WEB_PROVIDER_ERROR`. */
@@ -70,7 +87,9 @@ export class DeepSeekSearchProvider {
70
87
 
71
88
  available() {
72
89
  const options = this.resolveOptions();
73
- return ((options.apiKey?.length ?? 0) > 0 || options.resolveApiKey !== void 0)
90
+ const hasKey = (options.apiKey?.length ?? 0) > 0 || options.resolveApiKey !== void 0;
91
+ const canUseAccount = options.resolveAccountToken !== void 0;
92
+ return (hasKey || canUseAccount)
74
93
  && URL.canParse(options.baseURL)
75
94
  && Number.isInteger(options.maxTokens) && options.maxTokens > 0
76
95
  && Number.isInteger(options.maxUses) && options.maxUses > 0;
@@ -78,9 +97,26 @@ export class DeepSeekSearchProvider {
78
97
 
79
98
  async search(request, signal) {
80
99
  const options = this.resolveOptions();
81
- const apiKey = await resolveApiKey(options, signal, `DeepSeek search has no API key for "${options.apiKeyEnv ?? DEEPSEEK_DEFAULT_API_KEY_ENV}"; store it through the credentials service, export it in the launching environment, or set a literal "deepseekApiKey" in the dsh-web-search-plugin config`);
82
100
  throwIfSearchAborted(signal);
83
101
  const endpoint = `${options.baseURL.replace(/\/+$/u, "")}/messages`;
102
+ // An account-authorized search spends account quota and must not need a
103
+ // stored API key; every other search resolves `DEEPSEEK_API_KEY`.
104
+ let accountToken;
105
+ try {
106
+ accountToken = await abortable(Promise.resolve().then(() => options.resolveAccountToken?.(endpoint)), signal);
107
+ } catch (error) {
108
+ if (signal?.aborted === true || isAbortError(error)) throw searchAborted(signal, error);
109
+ throw new WebError(`DeepSeek account token resolution failed: ${String(error)}`, "WEB_PROVIDER_ERROR", { cause: error });
110
+ }
111
+ throwIfSearchAborted(signal);
112
+ let authHeaders;
113
+ if (typeof accountToken === "string" && accountToken.length > 0) {
114
+ authHeaders = { "x-dsh-auth-token": accountToken };
115
+ } else {
116
+ const apiKey = await resolveApiKey(options, signal, `DeepSeek search has no API key for "${options.apiKeyEnv ?? DEEPSEEK_DEFAULT_API_KEY_ENV}"; store it through the credentials service, export it in the launching environment, or set a literal "deepseekApiKey" in the dsh-web-search-plugin config`);
117
+ authHeaders = { "x-api-key": apiKey, "authorization": `Bearer ${apiKey}` };
118
+ }
119
+ throwIfSearchAborted(signal);
84
120
  const body = {
85
121
  model: options.model,
86
122
  max_tokens: options.maxTokens,
@@ -90,6 +126,9 @@ export class DeepSeekSearchProvider {
90
126
  }],
91
127
  tools: [{ type: "web_search_20250305", name: "web_search", max_uses: options.maxUses }]
92
128
  };
129
+ // Record the exact secret-free request before it leaves; a throw here
130
+ // prevents dispatch rather than logging an unrecorded model input.
131
+ options.recordRequest?.({ endpoint, apiVersion: options.apiVersion, body });
93
132
  throwIfSearchAborted(signal);
94
133
  let response;
95
134
  try {
@@ -97,8 +136,7 @@ export class DeepSeekSearchProvider {
97
136
  method: "POST",
98
137
  redirect: "error",
99
138
  headers: {
100
- "x-api-key": apiKey,
101
- "authorization": `Bearer ${apiKey}`,
139
+ ...authHeaders,
102
140
  "anthropic-version": options.apiVersion,
103
141
  "content-type": "application/json",
104
142
  "accept": "application/json",
@@ -123,7 +161,8 @@ export class DeepSeekSearchProvider {
123
161
  throw new WebError(message, "WEB_PROVIDER_ERROR");
124
162
  }
125
163
  try {
126
- return mapAnthropicResponse(await response.json());
164
+ const maxResults = Math.min(request.maxResults ?? MAX_RESULTS_CAP, options.maxResults ?? 8, MAX_RESULTS_CAP);
165
+ return mapAnthropicResponse(await response.json(), maxResults);
127
166
  } catch (error) {
128
167
  if (signal?.aborted === true || isAbortError(error)) throw searchAborted(signal, error);
129
168
  if (error instanceof WebError) throw error;
@@ -132,17 +171,36 @@ export class DeepSeekSearchProvider {
132
171
  }
133
172
  }
134
173
 
135
- /** Project the plugin section into DeepSeek backend options. */
174
+ /**
175
+ * Project the plugin section into DeepSeek backend options.
176
+ *
177
+ * `available()` accepts a search that can authenticate *either* way: a stored
178
+ * API key, an account-authorized session, or both.
179
+ * @param ctx - plugin context supplying the credential and environment planes.
180
+ * @param config - one detached section snapshot.
181
+ * @returns options for one search.
182
+ */
136
183
  export function resolveDeepseekOptions(ctx, config) {
184
+ config = resolveSupplierConfig(config);
137
185
  return {
138
186
  ...resolveSecret(ctx, {
139
187
  literal: config.deepseekApiKey,
140
188
  envName: config.deepseekApiKeyEnv ?? DEEPSEEK_DEFAULT_API_KEY_ENV
141
189
  }),
142
- baseURL: config.deepseekBaseURL ?? launchEnvironmentOf(ctx).get(DEEPSEEK_SEARCH_BASE_URL_ENV)?.value ?? DEEPSEEK_DEFAULT_BASE_URL,
143
- model: config.model ?? DEFAULT_MODEL,
144
- apiVersion: config.apiVersion ?? DEFAULT_API_VERSION,
145
- maxTokens: config.maxTokens ?? DEFAULT_MAX_TOKENS,
146
- maxUses: config.maxUses ?? DEFAULT_MAX_USES
190
+ // Only a DeepSeek-account session may spend account quota; every other
191
+ // session falls back to the API key resolved above.
192
+ resolveAccountToken: async (endpoint) => {
193
+ if (ctx.get("agents")?.currentInitiator()?.session.requestContext()?.provider !== ACCOUNT_PROVIDER) return void 0;
194
+ return await ctx.get("deepseekAccount")?.resolveToken(endpoint);
195
+ },
196
+ recordRequest: (request) => {
197
+ ctx.get("agents")?.currentInitiator()?.session.append("web/deepseek-search-llm-request", request);
198
+ },
199
+ baseURL: config.deepseekBaseURL || launchEnvironmentOf(ctx).get(DEEPSEEK_SEARCH_BASE_URL_ENV)?.value || DEEPSEEK_DEFAULT_BASE_URL,
200
+ model: config.deepseekModel ?? DEFAULT_MODEL,
201
+ apiVersion: config.deepseekApiVersion ?? DEFAULT_API_VERSION,
202
+ maxTokens: config.deepseekMaxTokens ?? DEFAULT_MAX_TOKENS,
203
+ maxUses: config.deepseekMaxUses ?? DEFAULT_MAX_USES,
204
+ maxResults: config.maxResults ?? 8
147
205
  };
148
206
  }
package/lib/index.js CHANGED
@@ -1,22 +1,27 @@
1
1
  /**
2
2
  * Web-search provider plugin for the DeepSeek Harness web capability seam
3
3
  * (`ctx.web`). Registers a single `WebSearchProvider` under the stable id
4
- * `dsh-web-search` and dispatches each search to DeepSeek (official), Tavily,
5
- * or Brave according to the `provider` setting — so switching backends does
4
+ * `dsh-web-search` and dispatches each search to one of nine backends
5
+ * according to the `provider` setting — so switching backends does
6
6
  * not require a `web.searchProvider` patch change.
7
7
  *
8
8
  * Tavily supports `keyless` (free, rate-limited) and `keyed` modes. Brave
9
9
  * always needs a subscription token (`BRAVE_API_KEY` by default). DeepSeek
10
10
  * uses the Anthropic-compatible Messages API native `web_search_20250305`
11
- * tool and reuses `DEEPSEEK_API_KEY` (the in-box `web-search-deepseek` host
12
- * plugin is disabled by the bundle patch).
11
+ * tool and authenticates with an account token or `DEEPSEEK_API_KEY` (the
12
+ * in-box `web-search-deepseek` host plugin is disabled by the bundle patch).
13
13
  *
14
- * No backend writes custom session events; tool results already go through
15
- * the seam's own events.
14
+ * DeepSeek records a secret-free model request as a session event before
15
+ * dispatch; the REST backends do not write custom session events.
16
+ *
17
+ * Adapted to DeepSeek Harness `0.2.x`: configuration is read from `volatile()`
18
+ * Config accessors instead of the `settings.installSection()` callback pair
19
+ * removed in `0.2.0`.
16
20
  *
17
21
  * @module dsh-web-search-plugin
18
22
  */
19
23
  import z from "@deepseek-ai/schemastery";
24
+ import { SUPPLIER_CONFIG_ALIASES, resolveSupplierConfig } from "./config.js";
20
25
  import { MAX_RESULTS_CAP } from "./shared.js";
21
26
  import { TAVILY_DEFAULT_API_KEY_ENV, TAVILY_DEFAULT_BASE_URL, TavilySearchProvider, resolveTavilyOptions } from "./tavily.js";
22
27
  import { BRAVE_DEFAULT_API_KEY_ENV, BRAVE_DEFAULT_BASE_URL, BraveSearchProvider, resolveBraveOptions } from "./brave.js";
@@ -35,86 +40,112 @@ const inject = ["web"];
35
40
  /** Settings namespace carrying this plugin's backend switch and options. */
36
41
  const WEB_SEARCH_SETTINGS_NAMESPACE = "dsh-web-search-plugin";
37
42
 
38
- /** Plugin config (all optional — `apply` fills defaults). */
43
+ /**
44
+ * Plugin config. Every field is `volatile()`: DeepSeek Harness `0.2.x` saves
45
+ * settings into the active Profile's plugin configuration and only reloads a
46
+ * running instance when a *non*-volatile field changes, so a volatile field can
47
+ * be edited from the settings form without restarting the plugin. The previous
48
+ * `settings.installSection()` + `setSource` mechanism was removed in `0.2.0`,
49
+ * which makes these accessors the only way to read live configuration.
50
+ */
39
51
  const Config = z.object({
40
- /** Active backend: `deepseek-official` (default), `tavily`, `brave`, `serper`, `serpapi`, `exa`, or `searxng`. */
41
- provider: z.string().default("deepseek-official"),
52
+ // No defaults here: absent prefixed fields must still inherit legacy values.
53
+ deepseekModel: z.string().volatile(),
54
+ deepseekApiVersion: z.string().volatile(),
55
+ deepseekMaxTokens: z.number().step(1).min(1).volatile(),
56
+ deepseekMaxUses: z.number().step(1).min(1).volatile(),
57
+ tavilyApiKey: z.string().role("secret").volatile(),
58
+ tavilyApiKeyEnv: z.string().role("credential-ref").volatile(),
59
+ tavilyBaseURL: z.string().volatile(),
60
+ tavilyMode: z.string().volatile(),
61
+ tavilySearchDepth: z.string().volatile(),
62
+ tavilyIncludeAnswer: z.boolean().volatile(),
63
+ tavilyTopic: z.string().volatile(),
64
+ braveCountry: z.string().volatile(),
65
+ braveSearchLang: z.string().volatile(),
66
+ braveFreshness: z.string().volatile(),
67
+ braveProxy: z.string().volatile(),
68
+ scavioCountry: z.string().volatile(),
69
+ scavioSearchLang: z.string().volatile(),
70
+ // Legacy fields remain accepted for existing profiles.
71
+ /** Active backend: `deepseek-official` (default), `tavily`, `brave`, `serper`, `serpapi`, `exa`, `searxng`, `scavio`, or `firecrawl`. */
72
+ provider: z.string().default("deepseek-official").volatile(),
42
73
  /** Tavily auth mode: `keyless` (default) or `keyed`. */
43
- mode: z.string().default("keyless"),
74
+ mode: z.string().default("keyless").volatile(),
44
75
  /** Literal Tavily API key; prefer {@link apiKeyEnv}. */
45
- apiKey: z.string().role("secret").default(""),
76
+ apiKey: z.string().role("secret").default("").volatile(),
46
77
  /** Credential reference for keyed Tavily search. */
47
- apiKeyEnv: z.string().role("credential-ref").default(TAVILY_DEFAULT_API_KEY_ENV),
78
+ apiKeyEnv: z.string().role("credential-ref").default(TAVILY_DEFAULT_API_KEY_ENV).volatile(),
48
79
  /** Tavily REST API base. `/search` is appended. */
49
- baseURL: z.string().default(TAVILY_DEFAULT_BASE_URL),
80
+ baseURL: z.string().default("").volatile(),
50
81
  /** Upper bound on returned sources; both backends accept 1..20. */
51
- maxResults: z.number().step(1).min(1).max(MAX_RESULTS_CAP).default(8),
82
+ maxResults: z.number().step(1).min(1).max(MAX_RESULTS_CAP).default(8).volatile(),
52
83
  /** Tavily search depth: `basic` (default) or `advanced`. */
53
- searchDepth: z.string().default("basic"),
84
+ searchDepth: z.string().default("basic").volatile(),
54
85
  /** Request Tavily's generated answer text; surfaced as the result `content`. */
55
- includeAnswer: z.boolean().default(true),
86
+ includeAnswer: z.boolean().default(true).volatile(),
56
87
  /** Tavily topic: `general` (default) or `news`. */
57
- topic: z.string().default("general"),
88
+ topic: z.string().default("general").volatile(),
58
89
  /** Literal Brave subscription token; prefer {@link braveApiKeyEnv}. */
59
- braveApiKey: z.string().role("secret").default(""),
90
+ braveApiKey: z.string().role("secret").default("").volatile(),
60
91
  /** Credential reference for Brave search. */
61
- braveApiKeyEnv: z.string().role("credential-ref").default(BRAVE_DEFAULT_API_KEY_ENV),
92
+ braveApiKeyEnv: z.string().role("credential-ref").default(BRAVE_DEFAULT_API_KEY_ENV).volatile(),
62
93
  /** Brave Search API web-results endpoint. */
63
- braveBaseURL: z.string().default(BRAVE_DEFAULT_BASE_URL),
94
+ braveBaseURL: z.string().default(BRAVE_DEFAULT_BASE_URL).volatile(),
64
95
  /** Optional Brave `country` (ISO 2-letter, e.g. `cn`). */
65
- country: z.string().default(""),
96
+ country: z.string().default("").volatile(),
66
97
  /** Optional Brave `search_lang` (e.g. `zh-hans`). */
67
- searchLang: z.string().default(""),
98
+ searchLang: z.string().default("").volatile(),
68
99
  /** Optional Brave `freshness` (`pd` / `pw` / `pm` / `py`). */
69
- freshness: z.string().default(""),
100
+ freshness: z.string().default("").volatile(),
70
101
  /** Optional HTTP(S) proxy URL for Brave; blank inherits DSH's global proxy policy. */
71
- proxy: z.string().default(""),
102
+ proxy: z.string().default("").volatile(),
72
103
  /** Literal Serper API key; prefer {@link serperApiKeyEnv}. */
73
- serperApiKey: z.string().role("secret").default(""),
104
+ serperApiKey: z.string().role("secret").default("").volatile(),
74
105
  /** Credential reference for Serper search. */
75
- serperApiKeyEnv: z.string().role("credential-ref").default("SERPER_API_KEY"),
106
+ serperApiKeyEnv: z.string().role("credential-ref").default("SERPER_API_KEY").volatile(),
76
107
  /** Serper endpoint base. `/search` is appended. */
77
- serperBaseURL: z.string().default("https://google.serper.dev"),
108
+ serperBaseURL: z.string().default("https://google.serper.dev").volatile(),
78
109
  /** Literal SerpApi API key; prefer {@link serpapiApiKeyEnv}. */
79
- serpapiApiKey: z.string().role("secret").default(""),
110
+ serpapiApiKey: z.string().role("secret").default("").volatile(),
80
111
  /** Credential reference for SerpApi search. */
81
- serpapiApiKeyEnv: z.string().role("credential-ref").default("SERPAPI_API_KEY"),
112
+ serpapiApiKeyEnv: z.string().role("credential-ref").default("SERPAPI_API_KEY").volatile(),
82
113
  /** SerpApi endpoint base. `/search.json` is appended. */
83
- serpapiBaseURL: z.string().default("https://serpapi.com"),
114
+ serpapiBaseURL: z.string().default("https://serpapi.com").volatile(),
84
115
  /** Literal Exa API key; prefer {@link exaApiKeyEnv}. */
85
- exaApiKey: z.string().role("secret").default(""),
116
+ exaApiKey: z.string().role("secret").default("").volatile(),
86
117
  /** Credential reference for Exa search. */
87
- exaApiKeyEnv: z.string().role("credential-ref").default("EXA_API_KEY"),
118
+ exaApiKeyEnv: z.string().role("credential-ref").default("EXA_API_KEY").volatile(),
88
119
  /** Exa endpoint base. `/search` is appended. */
89
- exaBaseURL: z.string().default("https://api.exa.ai"),
120
+ exaBaseURL: z.string().default("https://api.exa.ai").volatile(),
90
121
  /** Optional SearXNG instance base URL (self-hosted). `/search` is appended. */
91
- searxngBaseURL: z.string().default("https://searx.be"),
122
+ searxngBaseURL: z.string().default("https://searx.be").volatile(),
92
123
  /** Literal Scavio API key; prefer {@link scavioApiKeyEnv}. */
93
- scavioApiKey: z.string().role("secret").default(""),
124
+ scavioApiKey: z.string().role("secret").default("").volatile(),
94
125
  /** Credential reference for Scavio search. */
95
- scavioApiKeyEnv: z.string().role("credential-ref").default("SCAVIO_API_KEY"),
126
+ scavioApiKeyEnv: z.string().role("credential-ref").default("SCAVIO_API_KEY").volatile(),
96
127
  /** Scavio endpoint base. `/api/v2/google` is appended. */
97
- scavioBaseURL: z.string().default("https://api.scavio.dev"),
128
+ scavioBaseURL: z.string().default("https://api.scavio.dev").volatile(),
98
129
  /** Literal Firecrawl API key; prefer {@link firecrawlApiKeyEnv}. */
99
- firecrawlApiKey: z.string().role("secret").default(""),
130
+ firecrawlApiKey: z.string().role("secret").default("").volatile(),
100
131
  /** Credential reference for Firecrawl search. */
101
- firecrawlApiKeyEnv: z.string().role("credential-ref").default("FIRECRAWL_API_KEY"),
132
+ firecrawlApiKeyEnv: z.string().role("credential-ref").default("FIRECRAWL_API_KEY").volatile(),
102
133
  /** Firecrawl endpoint base. `/v2/search` is appended. */
103
- firecrawlBaseURL: z.string().default("https://api.firecrawl.dev"),
134
+ firecrawlBaseURL: z.string().default("https://api.firecrawl.dev").volatile(),
104
135
  /** Literal DeepSeek API key; prefer {@link deepseekApiKeyEnv}. */
105
- deepseekApiKey: z.string().role("secret").default(""),
136
+ deepseekApiKey: z.string().role("secret").default("").volatile(),
106
137
  /** Credential reference for DeepSeek search. */
107
- deepseekApiKeyEnv: z.string().role("credential-ref").default(DEEPSEEK_DEFAULT_API_KEY_ENV),
138
+ deepseekApiKeyEnv: z.string().role("credential-ref").default(DEEPSEEK_DEFAULT_API_KEY_ENV).volatile(),
108
139
  /** DeepSeek Anthropic-compatible Messages base URL. `/messages` is appended. */
109
- deepseekBaseURL: z.string().default(DEEPSEEK_DEFAULT_BASE_URL),
140
+ deepseekBaseURL: z.string().default("").volatile(),
110
141
  /** Anthropic-format model name for the Messages request. */
111
- model: z.string().default("deepseek-v4-flash"),
142
+ model: z.string().default("deepseek-flash").volatile(),
112
143
  /** `anthropic-version` header value. */
113
- apiVersion: z.string().default("2023-06-01"),
144
+ apiVersion: z.string().default("2023-06-01").volatile(),
114
145
  /** Upper bound on generated tokens for the Messages request. */
115
- maxTokens: z.number().step(1).min(1).default(4096),
146
+ maxTokens: z.number().step(1).min(1).default(4096).volatile(),
116
147
  /** Maximum `web_search` server-tool uses per request. */
117
- maxUses: z.number().step(1).min(1).default(5)
148
+ maxUses: z.number().step(1).min(1).default(5).volatile()
118
149
  });
119
150
 
120
151
  /**
@@ -128,18 +159,10 @@ class PluginSearchProvider {
128
159
  constructor(resolveOptions, usage) {
129
160
  this.resolveOptions = resolveOptions;
130
161
  this.deepseek = new DeepSeekSearchProvider(() => this.resolveOptions().deepseek);
131
- this.tavily = new TavilySearchProvider(() => ({
132
- ...this.resolveOptions().tavily,
133
- onUsage: (credits) => usage?.recordTavilyCredits(credits)
134
- }));
135
- this.brave = new BraveSearchProvider(() => ({
136
- ...this.resolveOptions().brave,
137
- onRateLimit: (headers) => usage?.recordBraveHeaders(headers)
138
- }));
139
162
  this.rest = new Map();
140
163
  for (const providerId of BUILTIN_REST_IDS) {
141
164
  this.rest.set(providerId, new RestSearchProvider(providerId, () => this.resolveOptions().rest[providerId], {
142
- onUsage: providerId === "tavily" ? (credits) => usage?.recordTavilyCredits(credits) : void 0,
165
+ onUsage: providerId === "tavily" ? (credits, apiKey) => usage?.recordTavilyCredits(credits, apiKey) : void 0,
143
166
  onRateLimit: providerId === "brave" ? (headers) => usage?.recordBraveHeaders(headers) : void 0
144
167
  }));
145
168
  }
@@ -166,14 +189,16 @@ class PluginSearchProvider {
166
189
 
167
190
  /** Project one resolved section into options for each backend. */
168
191
  function resolveOptions(ctx, config) {
192
+ config = resolveSupplierConfig(config);
169
193
  const isBuiltIn = config.provider === "tavily" || config.provider === "brave" || config.provider === "deepseek-official" || BUILTIN_REST_IDS.includes(config.provider);
170
194
  const provider = isBuiltIn ? config.provider : "deepseek-official";
195
+ const tavily = provider === "tavily" ? resolveTavilyOptions(ctx, config) : void 0;
171
196
  // Per-provider literal key / optional endpoint override, used when the
172
197
  // metadata row's default is not enough (self-hosted SearXNG, proxied
173
198
  // providers, custom key refs).
174
199
  const keySourceByProvider = {
175
- brave: { literal: config.braveApiKey, envName: config.braveApiKeyEnv ?? BRAVE_DEFAULT_API_KEY_ENV, baseURL: config.braveBaseURL ?? "", proxy: config.proxy ?? "" },
176
- tavily: { literal: config.apiKey, envName: config.apiKeyEnv ?? TAVILY_DEFAULT_API_KEY_ENV, baseURL: config.baseURL ?? "" },
200
+ brave: { literal: config.braveApiKey, envName: config.braveApiKeyEnv ?? BRAVE_DEFAULT_API_KEY_ENV, baseURL: config.braveBaseURL ?? "", proxy: config.braveProxy ?? "" },
201
+ tavily: { literal: config.tavilyApiKey, envName: config.tavilyApiKeyEnv ?? TAVILY_DEFAULT_API_KEY_ENV, baseURL: tavily?.baseURL ?? "" },
177
202
  serper: { literal: config.serperApiKey, envName: config.serperApiKeyEnv ?? "SERPER_API_KEY", baseURL: config.serperBaseURL ?? "" },
178
203
  serpapi: { literal: config.serpapiApiKey, envName: config.serpapiApiKeyEnv ?? "SERPAPI_API_KEY", baseURL: config.serpapiBaseURL ?? "" },
179
204
  exa: { literal: config.exaApiKey, envName: config.exaApiKeyEnv ?? "EXA_API_KEY", baseURL: config.exaBaseURL ?? "" },
@@ -182,22 +207,22 @@ function resolveOptions(ctx, config) {
182
207
  firecrawl: { literal: config.firecrawlApiKey, envName: config.firecrawlApiKeyEnv ?? "FIRECRAWL_API_KEY", baseURL: config.firecrawlBaseURL ?? "" }
183
208
  };
184
209
  const settings = {
185
- country: config.country,
186
- searchLang: config.searchLang,
187
- freshness: config.freshness,
188
- searchDepth: config.searchDepth,
189
- topic: config.topic,
190
- includeAnswer: config.includeAnswer
210
+ country: provider === "scavio" ? config.scavioCountry : config.braveCountry,
211
+ searchLang: provider === "scavio" ? config.scavioSearchLang : config.braveSearchLang,
212
+ freshness: config.braveFreshness,
213
+ searchDepth: config.tavilySearchDepth,
214
+ topic: config.tavilyTopic,
215
+ includeAnswer: config.tavilyIncludeAnswer
191
216
  };
192
217
  const rest = {};
193
- for (const providerId of BUILTIN_REST_IDS) {
218
+ for (const providerId of provider === "deepseek-official" ? [] : [provider]) {
194
219
  const row = findProvider(providerId);
195
220
  if (row === void 0) continue;
196
221
  const source = keySourceByProvider[providerId] ?? {};
197
222
  const resolved = resolveRestProvider(ctx, row, {
198
223
  config,
199
224
  settings,
200
- keyed: providerId === "tavily" ? config.mode === "keyed" : false,
225
+ keyed: providerId === "tavily" ? config.tavilyMode === "keyed" : false,
201
226
  keySource: source
202
227
  });
203
228
  // Endpoint override: an explicit config baseURL wins over the row default.
@@ -207,9 +232,9 @@ function resolveOptions(ctx, config) {
207
232
  }
208
233
  return {
209
234
  provider,
210
- deepseek: resolveDeepseekOptions(ctx, config),
211
- tavily: resolveTavilyOptions(ctx, config),
212
- brave: resolveBraveOptions(ctx, config),
235
+ deepseek: provider === "deepseek-official" ? resolveDeepseekOptions(ctx, config) : void 0,
236
+ tavily,
237
+ brave: provider === "brave" ? resolveBraveOptions(ctx, config) : void 0,
213
238
  rest
214
239
  };
215
240
  }
@@ -246,18 +271,75 @@ function sendJson(res, statusCode, data) {
246
271
  res.end(body);
247
272
  }
248
273
 
249
- /** Register the dispatched search provider with `ctx.web`. */
274
+ /**
275
+ * Read the live configuration section.
276
+ *
277
+ * Every Config field is `volatile()`, so `field.get()` always yields the value
278
+ * the settings form last wrote — replacing the `installSection` / `setSource`
279
+ * pair this plugin used on Harness `0.1.x`. Snapshotted once per operation by
280
+ * each backend's `resolveOptions`, so one search never mixes two sections.
281
+ * @param config - the plugin's volatile Config accessors.
282
+ * @returns one detached plain section.
283
+ */
284
+ function readSection(config) {
285
+ return {
286
+ ...Object.fromEntries(Object.keys(SUPPLIER_CONFIG_ALIASES).map((field) => [field, config[field].get()])),
287
+ provider: config.provider.get(),
288
+ mode: config.mode.get(),
289
+ apiKey: config.apiKey.get(),
290
+ apiKeyEnv: config.apiKeyEnv.get(),
291
+ baseURL: config.baseURL.get(),
292
+ maxResults: config.maxResults.get(),
293
+ searchDepth: config.searchDepth.get(),
294
+ includeAnswer: config.includeAnswer.get(),
295
+ topic: config.topic.get(),
296
+ braveApiKey: config.braveApiKey.get(),
297
+ braveApiKeyEnv: config.braveApiKeyEnv.get(),
298
+ braveBaseURL: config.braveBaseURL.get(),
299
+ country: config.country.get(),
300
+ searchLang: config.searchLang.get(),
301
+ freshness: config.freshness.get(),
302
+ proxy: config.proxy.get(),
303
+ serperApiKey: config.serperApiKey.get(),
304
+ serperApiKeyEnv: config.serperApiKeyEnv.get(),
305
+ serperBaseURL: config.serperBaseURL.get(),
306
+ serpapiApiKey: config.serpapiApiKey.get(),
307
+ serpapiApiKeyEnv: config.serpapiApiKeyEnv.get(),
308
+ serpapiBaseURL: config.serpapiBaseURL.get(),
309
+ exaApiKey: config.exaApiKey.get(),
310
+ exaApiKeyEnv: config.exaApiKeyEnv.get(),
311
+ exaBaseURL: config.exaBaseURL.get(),
312
+ searxngBaseURL: config.searxngBaseURL.get(),
313
+ scavioApiKey: config.scavioApiKey.get(),
314
+ scavioApiKeyEnv: config.scavioApiKeyEnv.get(),
315
+ scavioBaseURL: config.scavioBaseURL.get(),
316
+ firecrawlApiKey: config.firecrawlApiKey.get(),
317
+ firecrawlApiKeyEnv: config.firecrawlApiKeyEnv.get(),
318
+ firecrawlBaseURL: config.firecrawlBaseURL.get(),
319
+ deepseekApiKey: config.deepseekApiKey.get(),
320
+ deepseekApiKeyEnv: config.deepseekApiKeyEnv.get(),
321
+ deepseekBaseURL: config.deepseekBaseURL.get(),
322
+ model: config.model.get(),
323
+ apiVersion: config.apiVersion.get(),
324
+ maxTokens: config.maxTokens.get(),
325
+ maxUses: config.maxUses.get()
326
+ };
327
+ }
328
+
329
+ /**
330
+ * Register the dispatched search provider with `ctx.web`.
331
+ *
332
+ * Harness `0.2.x` saves plugin settings into the active Profile's plugin
333
+ * configuration and exposes them through `settings.describe()`; a plugin with
334
+ * no custom page gets an auto-generated one for free. This plugin keeps that
335
+ * default (it never calls `settings.configure({ auto: false })`) and edits the
336
+ * `dsh-web-search-plugin` namespace through the browser card in
337
+ * `lib/client.js`.
338
+ * @param ctx - plugin context.
339
+ * @param config - volatile Config accessors supplied by the Loader.
340
+ */
250
341
  function apply(ctx, config) {
251
- let current = () => config;
252
- ctx.inject(["settings"], (settingsCtx) => {
253
- settingsCtx.settings.installSection(ctx, WEB_SEARCH_SETTINGS_NAMESPACE, Config, config, {
254
- setSource: (source) => {
255
- current = source;
256
- },
257
- onChange: () => {}
258
- });
259
- });
260
- const live = () => resolveOptions(ctx, current());
342
+ const live = () => resolveOptions(ctx, readSection(config));
261
343
  const usage = new UsageTracker({
262
344
  getTavilyOptions: () => live().tavily
263
345
  });
@@ -265,7 +347,7 @@ function apply(ctx, config) {
265
347
  let cancelled = false;
266
348
  void usage.hydrate().then(() => {
267
349
  if (cancelled) return;
268
- if (live().provider === "tavily" && live().tavily.mode === "keyed") return usage.refreshTavily(undefined, true);
350
+ if (live().provider === "tavily" && live().tavily.mode === "keyed") return usage.refreshTavily();
269
351
  }).catch(() => {});
270
352
  return () => {
271
353
  cancelled = true;
@@ -293,9 +375,7 @@ function apply(ctx, config) {
293
375
  const url = new URL(req.url ?? "/", "http://127.0.0.1");
294
376
  const force = req.method === "POST" || url.searchParams.get("force") === "1" || url.searchParams.get("force") === "true";
295
377
  const options = live();
296
- const tavilyState = usage.snapshot().tavily;
297
- const missingIdentity = tavilyState.plan == null && tavilyState.limit == null;
298
- if ((force || missingIdentity) && options.provider === "tavily" && options.tavily.mode === "keyed") {
378
+ if (options.provider === "tavily" && options.tavily.mode === "keyed") {
299
379
  try {
300
380
  if (req.method === "POST") await readJsonBody(req).catch(() => ({}));
301
381
  await usage.refreshTavily(undefined, force);
@@ -308,7 +388,7 @@ function apply(ctx, config) {
308
388
  res.end();
309
389
  return;
310
390
  }
311
- sendJson(res, 200, usage.serialize(options.provider, options.tavily.mode));
391
+ sendJson(res, 200, usage.serialize(options.provider, options.tavily?.mode));
312
392
  }
313
393
  }), "dsh-web-search-plugin: usage route");
314
394
  });
package/lib/providers.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Static metadata table for every built-in REST web-search provider.
3
3
  *
4
- * This module is intentionally **data, not code**: adding a new REST provider
5
- * means adding one row here (plus an optional official "get a key" link in the
6
- * settings card), with zero per-provider execution code. The generic backend in
4
+ * This module is intentionally **data, not code**: a new REST provider needs
5
+ * one row here, plus configuration and a browser selector entry, with zero
6
+ * per-provider execution code. The generic backend in
7
7
  * `lib/rest.js` reads a row and performs `method` / `path` / `queryParam` /
8
8
  * `countParam` / `params` / `auth` / `response` / `hooks`.
9
9
  *
@@ -118,13 +118,13 @@ export const REST_PROVIDERS = [
118
118
  path: "/search",
119
119
  queryIn: "body",
120
120
  queryParam: "query",
121
- countParam: "num_results",
121
+ countParam: "numResults",
122
122
  auth: { type: "bearer" },
123
123
  keyRequired: true,
124
124
  apiKeyRef: "EXA_API_KEY",
125
125
  response: "exa",
126
126
  params: [
127
- { key: "contents", value: "text", when: "always" }
127
+ { key: "contents", value: { highlights: true }, when: "always" }
128
128
  ],
129
129
  officialUrl: "https://dashboard.exa.ai/",
130
130
  hooks: []
@@ -138,7 +138,7 @@ export const REST_PROVIDERS = [
138
138
  path: "/search",
139
139
  queryIn: "query",
140
140
  queryParam: "q",
141
- countParam: "count",
141
+ countParam: "",
142
142
  auth: { type: "none" },
143
143
  keyRequired: false,
144
144
  apiKeyRef: "",
@@ -185,7 +185,7 @@ export const REST_PROVIDERS = [
185
185
  apiKeyRef: "FIRECRAWL_API_KEY",
186
186
  response: "firecrawl",
187
187
  params: [
188
- { key: "sources", value: "web", when: "always" }
188
+ { key: "sources", value: ["web"], when: "always" }
189
189
  ],
190
190
  officialUrl: "https://firecrawl.dev/",
191
191
  hooks: []