fix: return setup hint when web_search lacks key

This commit is contained in:
Peter Steinberger
2026-01-15 05:35:22 +00:00
parent ca1902fb4e
commit 2e70c3ceab
3 changed files with 15 additions and 2 deletions

View File

@@ -16,6 +16,7 @@
- Security: add detect-secrets CI scan and baseline guidance. (#227) — thanks @Hyaxia. - Security: add detect-secrets CI scan and baseline guidance. (#227) — thanks @Hyaxia.
- Tools: add `web_search`/`web_fetch` (Brave API), auto-enable `web_fetch` for sandboxed sessions, and remove the `brave-search` skill. - Tools: add `web_search`/`web_fetch` (Brave API), auto-enable `web_fetch` for sandboxed sessions, and remove the `brave-search` skill.
- CLI/Docs: add a web tools configure section for storing Brave API keys and update onboarding tips. - CLI/Docs: add a web tools configure section for storing Brave API keys and update onboarding tips.
- Tools: return a setup hint (docs link) when web_search runs without a Brave API key.
- Browser: add Chrome extension relay takeover mode (toolbar button), plus `clawdbot browser extension install/path` and remote browser control via `clawdbot browser serve` + `browser.controlToken`. - Browser: add Chrome extension relay takeover mode (toolbar button), plus `clawdbot browser extension install/path` and remote browser control via `clawdbot browser serve` + `browser.controlToken`.
### Fixes ### Fixes

View File

@@ -110,3 +110,4 @@ Notes:
- `web_fetch` is best-effort extraction; some sites will need the browser tool. - `web_fetch` is best-effort extraction; some sites will need the browser tool.
- Responses are cached (default 15 minutes) to reduce repeated fetches. - Responses are cached (default 15 minutes) to reduce repeated fetches.
- If you use tool profiles/allowlists, add `web_search`/`web_fetch` or `group:web`. - If you use tool profiles/allowlists, add `web_search`/`web_fetch` or `group:web`.
- If the Brave key is missing, `web_search` returns a short setup hint with a docs link.

View File

@@ -110,6 +110,15 @@ function resolveSearchApiKey(search?: WebSearchConfig): string | undefined {
return fromConfig || fromEnv || undefined; return fromConfig || fromEnv || undefined;
} }
function missingSearchKeyPayload() {
return {
error: "missing_brave_api_key",
message:
"web_search needs a Brave Search API key. Run `clawdbot configure --section web` to store it, or set BRAVE_API_KEY in the Gateway environment.",
docs: "https://docs.clawd.bot/tools/web",
};
}
function resolveSearchProvider(search?: WebSearchConfig): (typeof SEARCH_PROVIDERS)[number] { function resolveSearchProvider(search?: WebSearchConfig): (typeof SEARCH_PROVIDERS)[number] {
const raw = const raw =
search && "provider" in search && typeof search.provider === "string" search && "provider" in search && typeof search.provider === "string"
@@ -412,8 +421,6 @@ export function createWebSearchTool(options?: {
}): AnyAgentTool | null { }): AnyAgentTool | null {
const search = resolveSearchConfig(options?.config); const search = resolveSearchConfig(options?.config);
if (!resolveSearchEnabled({ search, sandboxed: options?.sandboxed })) return null; if (!resolveSearchEnabled({ search, sandboxed: options?.sandboxed })) return null;
const apiKey = resolveSearchApiKey(search);
if (!apiKey) return null;
return { return {
label: "Web Search", label: "Web Search",
name: "web_search", name: "web_search",
@@ -421,6 +428,10 @@ export function createWebSearchTool(options?: {
"Search the web using Brave Search API. Returns titles, URLs, and snippets for fast research.", "Search the web using Brave Search API. Returns titles, URLs, and snippets for fast research.",
parameters: WebSearchSchema, parameters: WebSearchSchema,
execute: async (_toolCallId, args) => { execute: async (_toolCallId, args) => {
const apiKey = resolveSearchApiKey(search);
if (!apiKey) {
return jsonResult(missingSearchKeyPayload());
}
const params = args as Record<string, unknown>; const params = args as Record<string, unknown>;
const query = readStringParam(params, "query", { required: true }); const query = readStringParam(params, "query", { required: true });
const count = const count =