@openclaw/brave-plugin 2026.9.8 → 2026.10.1-beta.2
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/.setup/{brave-web-search-provider-DJmw8wv_.mjs → brave-web-search-provider-BMkqethI.mjs} +1 -1
- package/dist/.setup/{brave-web-search-provider.runtime-B7NtRbBA.mjs → brave-web-search-provider.runtime-Di4Yotfh.mjs} +51 -85
- package/dist/index.js +1 -1
- package/dist/web-search-contract-api.js +1 -1
- package/dist/web-search-provider.js +1 -1
- package/package.json +4 -4
|
@@ -8,7 +8,7 @@ import { asOptionalRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
|
8
8
|
* Brave web-search provider factory. It builds the agent tool definition and
|
|
9
9
|
* lazy-loads HTTP execution only when a search is run.
|
|
10
10
|
*/
|
|
11
|
-
const loadBraveWebSearchRuntime = createLazyRuntimeModule(() => import("./brave-web-search-provider.runtime-
|
|
11
|
+
const loadBraveWebSearchRuntime = createLazyRuntimeModule(() => import("./brave-web-search-provider.runtime-Di4Yotfh.mjs"));
|
|
12
12
|
const BraveSearchSchema = {
|
|
13
13
|
type: "object",
|
|
14
14
|
properties: {
|
|
@@ -170,8 +170,8 @@ const DEFAULT_BRAVE_BASE_URL = "https://api.search.brave.com";
|
|
|
170
170
|
const BRAVE_SEARCH_ENDPOINT_PATH = "/res/v1/web/search";
|
|
171
171
|
const BRAVE_LLM_CONTEXT_ENDPOINT_PATH = "/res/v1/llm/context";
|
|
172
172
|
const braveHttpLogger = createSubsystemLogger("brave/http");
|
|
173
|
-
function logBraveHttp(
|
|
174
|
-
if (!
|
|
173
|
+
function logBraveHttp(diagnosticsEnabled, event, meta) {
|
|
174
|
+
if (!diagnosticsEnabled) return;
|
|
175
175
|
braveHttpLogger.info(`brave http ${event}`, meta);
|
|
176
176
|
}
|
|
177
177
|
function resolveBraveApiKey(searchConfig) {
|
|
@@ -180,12 +180,6 @@ function resolveBraveApiKey(searchConfig) {
|
|
|
180
180
|
function resolveBraveBaseUrl(braveConfig) {
|
|
181
181
|
return readConfiguredSecretString(braveConfig?.baseUrl, "plugins.entries.brave.config.webSearch.baseUrl")?.replace(/\/+$/u, "") || DEFAULT_BRAVE_BASE_URL;
|
|
182
182
|
}
|
|
183
|
-
function buildBraveEndpointUrl(params) {
|
|
184
|
-
const url = new URL(params.baseUrl);
|
|
185
|
-
url.pathname = `${url.pathname.replace(/\/+$/u, "")}${params.endpointPath}`;
|
|
186
|
-
url.search = "";
|
|
187
|
-
return url;
|
|
188
|
-
}
|
|
189
183
|
async function braveEndpointTargetsPrivateNetwork(url, signal) {
|
|
190
184
|
if (isBlockedHostnameOrIp(url.hostname)) return true;
|
|
191
185
|
try {
|
|
@@ -219,29 +213,22 @@ async function validateBraveBaseUrl(baseUrl, signal) {
|
|
|
219
213
|
}
|
|
220
214
|
return await braveEndpointTargetsPrivateNetwork(parsed, signal) ? "selfHosted" : "strict";
|
|
221
215
|
}
|
|
222
|
-
function
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
docs: "https://docs.openclaw.ai/tools/web"
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
function setBraveSearchUrlParams(url, params) {
|
|
216
|
+
async function runBraveSearch(params) {
|
|
217
|
+
const url = new URL(params.baseUrl);
|
|
218
|
+
url.pathname = `${url.pathname.replace(/\/+$/u, "")}${params.mode === "llm-context" ? BRAVE_LLM_CONTEXT_ENDPOINT_PATH : BRAVE_SEARCH_ENDPOINT_PATH}`;
|
|
219
|
+
url.search = "";
|
|
230
220
|
url.searchParams.set("q", params.query);
|
|
231
221
|
if (params.country) url.searchParams.set("country", params.country);
|
|
232
222
|
if (params.search_lang) url.searchParams.set("search_lang", params.search_lang);
|
|
233
223
|
if (params.freshness) url.searchParams.set("freshness", params.freshness);
|
|
234
224
|
else if (params.dateAfter && params.dateBefore) url.searchParams.set("freshness", `${params.dateAfter}to${params.dateBefore}`);
|
|
235
225
|
else if (params.dateAfter) url.searchParams.set("freshness", `${params.dateAfter}to${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}`);
|
|
236
|
-
else if (params.
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
});
|
|
243
|
-
params.configureUrl(url);
|
|
244
|
-
logBraveHttp(params.diagnostics, "request", {
|
|
226
|
+
else if (params.mode === "web" && params.dateBefore) url.searchParams.set("freshness", `1970-01-01to${params.dateBefore}`);
|
|
227
|
+
if (params.mode === "web") {
|
|
228
|
+
url.searchParams.set("count", String(params.count));
|
|
229
|
+
if (params.ui_lang) url.searchParams.set("ui_lang", params.ui_lang);
|
|
230
|
+
}
|
|
231
|
+
logBraveHttp(params.diagnosticsEnabled, "request", {
|
|
245
232
|
mode: params.mode,
|
|
246
233
|
url: url.toString(),
|
|
247
234
|
query: url.searchParams.get("q") ?? "",
|
|
@@ -259,61 +246,48 @@ async function runBraveJsonRequest(params, errorLabel) {
|
|
|
259
246
|
}
|
|
260
247
|
}
|
|
261
248
|
}, async ({ response }) => {
|
|
262
|
-
logBraveHttp(params.
|
|
249
|
+
logBraveHttp(params.diagnosticsEnabled, "response", {
|
|
263
250
|
mode: params.mode,
|
|
264
251
|
status: response.status,
|
|
265
252
|
ok: response.ok,
|
|
266
253
|
durationMs: Date.now() - startedAt
|
|
267
254
|
});
|
|
255
|
+
const errorLabel = params.mode === "llm-context" ? "Brave LLM Context API error" : "Brave Search API error";
|
|
268
256
|
await assertOkOrThrowProviderError(response, errorLabel);
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
mode: "llm-context",
|
|
277
|
-
configureUrl: (url) => {
|
|
278
|
-
setBraveSearchUrlParams(url, params);
|
|
279
|
-
}
|
|
280
|
-
}, "Brave LLM Context API error");
|
|
281
|
-
return {
|
|
282
|
-
results: mapBraveLlmContextResults(data),
|
|
283
|
-
sources: data.sources
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
async function runBraveWebSearch(params) {
|
|
287
|
-
const data = await runBraveJsonRequest({
|
|
288
|
-
...params,
|
|
289
|
-
endpointPath: BRAVE_SEARCH_ENDPOINT_PATH,
|
|
290
|
-
mode: "web",
|
|
291
|
-
configureUrl: (url) => {
|
|
292
|
-
setBraveSearchUrlParams(url, {
|
|
293
|
-
...params,
|
|
294
|
-
allowDateBeforeOnly: true
|
|
295
|
-
});
|
|
296
|
-
url.searchParams.set("count", String(params.count));
|
|
297
|
-
if (params.ui_lang) url.searchParams.set("ui_lang", params.ui_lang);
|
|
257
|
+
if (params.mode === "llm-context") {
|
|
258
|
+
const data = await readProviderJsonResponse(response, errorLabel);
|
|
259
|
+
return {
|
|
260
|
+
mode: "llm-context",
|
|
261
|
+
results: mapBraveLlmContextResults(data),
|
|
262
|
+
sources: data.sources
|
|
263
|
+
};
|
|
298
264
|
}
|
|
299
|
-
|
|
300
|
-
return (Array.isArray(data.web?.results) ? data.web.results : []).slice(0, params.count).map((entry) => {
|
|
301
|
-
const description = entry.description ?? "";
|
|
302
|
-
const title = entry.title ?? "";
|
|
303
|
-
const url = entry.url ?? "";
|
|
265
|
+
const data = await readProviderJsonResponse(response, errorLabel);
|
|
304
266
|
return {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
267
|
+
mode: "web",
|
|
268
|
+
results: (Array.isArray(data.web?.results) ? data.web.results : []).slice(0, params.count).map((entry) => {
|
|
269
|
+
const description = entry.description ?? "";
|
|
270
|
+
const title = entry.title ?? "";
|
|
271
|
+
const resultUrl = entry.url ?? "";
|
|
272
|
+
return {
|
|
273
|
+
title: title ? wrapWebContent(title, "web_search") : "",
|
|
274
|
+
url: resultUrl,
|
|
275
|
+
description: description ? wrapWebContent(description, "web_search") : "",
|
|
276
|
+
published: entry.page_age || void 0,
|
|
277
|
+
siteName: resolveSiteName(resultUrl) || void 0
|
|
278
|
+
};
|
|
279
|
+
})
|
|
310
280
|
};
|
|
311
281
|
});
|
|
312
282
|
}
|
|
313
283
|
/** Execute one Brave Search request using web or LLM-context mode. */
|
|
314
284
|
async function executeBraveSearch(args, searchConfig, options) {
|
|
315
285
|
const apiKey = resolveBraveApiKey(searchConfig);
|
|
316
|
-
if (!apiKey) return
|
|
286
|
+
if (!apiKey) return {
|
|
287
|
+
error: "missing_brave_api_key",
|
|
288
|
+
message: `web_search (brave) needs a Brave Search API key. Run \`${formatCliCommand("openclaw configure --section web")}\` to store it, or set BRAVE_API_KEY in the Gateway environment. If you do not want to configure a search API key, use web_fetch for a specific URL or the browser tool for interactive pages.`,
|
|
289
|
+
docs: "https://docs.openclaw.ai/tools/web"
|
|
290
|
+
};
|
|
317
291
|
const braveConfig = asNonArrayRecord(searchConfig?.brave);
|
|
318
292
|
const braveMode = resolveBraveMode(braveConfig);
|
|
319
293
|
const braveBaseUrl = resolveBraveBaseUrl(braveConfig);
|
|
@@ -398,47 +372,39 @@ async function executeBraveSearch(args, searchConfig, options) {
|
|
|
398
372
|
dateAfter,
|
|
399
373
|
llmContextDateEnd
|
|
400
374
|
]);
|
|
401
|
-
const
|
|
375
|
+
const diagnosticsEnabled = options?.diagnosticsEnabled === true;
|
|
402
376
|
const cacheTtlMs = resolveSearchCacheTtlMs(searchConfig);
|
|
403
377
|
const cached = readCachedSearchPayload(cacheKey, cacheTtlMs);
|
|
404
378
|
if (cached) {
|
|
405
|
-
logBraveHttp(
|
|
379
|
+
logBraveHttp(diagnosticsEnabled, "cache hit", {
|
|
406
380
|
mode: braveMode,
|
|
407
381
|
query,
|
|
408
382
|
cacheKey
|
|
409
383
|
});
|
|
410
384
|
return cached;
|
|
411
385
|
}
|
|
412
|
-
logBraveHttp(
|
|
386
|
+
logBraveHttp(diagnosticsEnabled, "cache miss", {
|
|
413
387
|
mode: braveMode,
|
|
414
388
|
query,
|
|
415
389
|
cacheKey
|
|
416
390
|
});
|
|
417
391
|
const start = Date.now();
|
|
418
|
-
const
|
|
392
|
+
const response = await runBraveSearch({
|
|
419
393
|
baseUrl: braveBaseUrl,
|
|
420
394
|
endpointMode: braveEndpointMode,
|
|
421
395
|
query,
|
|
422
396
|
apiKey,
|
|
423
|
-
|
|
397
|
+
diagnosticsEnabled,
|
|
424
398
|
signal,
|
|
425
399
|
country: country ?? void 0,
|
|
426
400
|
search_lang: normalizedLanguage.search_lang,
|
|
427
401
|
freshness,
|
|
428
402
|
dateAfter,
|
|
429
|
-
dateBefore
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
} : {
|
|
435
|
-
results: await runBraveWebSearch({
|
|
436
|
-
...request,
|
|
437
|
-
count: requestedCount,
|
|
438
|
-
ui_lang: normalizedLanguage.ui_lang
|
|
439
|
-
}),
|
|
440
|
-
mode: "web"
|
|
441
|
-
};
|
|
403
|
+
dateBefore,
|
|
404
|
+
mode: braveMode,
|
|
405
|
+
count: requestedCount,
|
|
406
|
+
ui_lang: normalizedLanguage.ui_lang
|
|
407
|
+
});
|
|
442
408
|
signal?.throwIfAborted();
|
|
443
409
|
const results = response.mode === "llm-context" ? response.results.slice(0, requestedCount).map((entry) => ({
|
|
444
410
|
title: entry.title ? wrapWebContent(entry.title, "web_search") : "",
|
|
@@ -463,7 +429,7 @@ async function executeBraveSearch(args, searchConfig, options) {
|
|
|
463
429
|
...response.mode === "llm-context" ? { sources: response.sources } : {}
|
|
464
430
|
};
|
|
465
431
|
writeCachedSearchPayload(cacheKey, payload, cacheTtlMs);
|
|
466
|
-
logBraveHttp(
|
|
432
|
+
logBraveHttp(diagnosticsEnabled, "cache write", {
|
|
467
433
|
mode: response.mode,
|
|
468
434
|
query,
|
|
469
435
|
cacheKey,
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as createBraveWebSearchProvider } from "./.setup/brave-web-search-provider-
|
|
1
|
+
import { t as createBraveWebSearchProvider } from "./.setup/brave-web-search-provider-BMkqethI.mjs";
|
|
2
2
|
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
3
3
|
//#region extensions/brave/index.ts
|
|
4
4
|
/**
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as createBraveWebSearchProvider } from "./.setup/brave-web-search-provider-
|
|
1
|
+
import { t as createBraveWebSearchProvider } from "./.setup/brave-web-search-provider-BMkqethI.mjs";
|
|
2
2
|
import "./web-search-provider.js";
|
|
3
3
|
export { createBraveWebSearchProvider };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createBraveWebSearchProvider } from "./.setup/brave-web-search-provider-
|
|
1
|
+
import { t as createBraveWebSearchProvider } from "./.setup/brave-web-search-provider-BMkqethI.mjs";
|
|
2
2
|
export { createBraveWebSearchProvider };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/brave-plugin",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.10.1-beta.2",
|
|
4
4
|
"description": "OpenClaw Brave Search provider plugin for web search.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"allowInvalidConfigRecovery": true
|
|
20
20
|
},
|
|
21
21
|
"compat": {
|
|
22
|
-
"pluginApi": ">=2026.
|
|
22
|
+
"pluginApi": ">=2026.10.1-beta.2"
|
|
23
23
|
},
|
|
24
24
|
"build": {
|
|
25
|
-
"openclawVersion": "2026.
|
|
25
|
+
"openclawVersion": "2026.10.1-beta.2"
|
|
26
26
|
},
|
|
27
27
|
"release": {
|
|
28
28
|
"publishToClawHub": true,
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"assets/activity.svg"
|
|
41
41
|
],
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"openclaw": ">=2026.
|
|
43
|
+
"openclaw": ">=2026.10.1-beta.2"
|
|
44
44
|
},
|
|
45
45
|
"peerDependenciesMeta": {
|
|
46
46
|
"openclaw": {
|