feat: add optional you.com search integration - #173
Open
mouse-value-add wants to merge 1 commit into
Open
mouse-value-add wants to merge 1 commit into
mouse-value-add wants to merge 1 commit into
Conversation
When YDC_API_KEY is set, WebSearch prefers the You.com Search API (stable JSON results with snippets) over the DuckDuckGo HTML scrape. Any You.com failure falls back to the existing DuckDuckGo path, so default behaviour with no key set is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an optional You.com provider to the existing
WebSearchtool. WhenYDC_API_KEYis set in the environment, searches go through the You.com Search API (https://api.ydc-index.io/search,X-API-Keyheader) and return stable JSON results with snippets. When the key is unset — the default — behaviour is exactly as before (DuckDuckGo HTML scrape with the lite-endpoint fallback). If the You.com call fails for any reason (bad key, network, HTTP error), the tool silently falls back to the DuckDuckGo path, so a misconfigured key can never break web search.Why this is useful here
src/agent/tools/web.tscurrently depends on regex-parsing DuckDuckGo's HTML layout — the file itself documents three fallback parse strategies because the layout shifts. This PR gives the tool an API-backed engine that doesn't depend on page structure, while keeping the zero-config path intact. The result header now labels the engine used (via you.com/via duckduckgo) so it's visible which path served a query.Changes
src/agent/tools/web.ts—ydcApiKey()(env read, trim, empty-reject),parseYdcResults()(tolerant JSON parser: accepts{hits:[...]}or a bare array, joinssnippetsarrays, falls back todescription, dedupes by URL, respects the limit),ydcSearch()(fetch + error handling), and engine selection insidewebSearchToolwith automatic DDG fallback. Exposed a small_internalsseam for tests.src/agent/tools/web.test.ts— 11 new tests: parser (shapes, dedupe, limit, junk bodies), key handling (unset default, whitespace, empty), and engine selection (You.com used when key set + results returned, DDG fallback on You.com failure, You.com never called without a key). All fetch/network is mocked; no live calls in CI.README.md— one-line mention of the optional provider in the tools table.CHANGELOG.md— Unreleased entry.Setup
No other configuration; nothing changes for users who don't set the variable. No new dependencies (plain
fetch).Usage example
For anyone who prefers MCP instead of a direct API key: You.com also ships a remote MCP server (
https://api.you.com/mcp, keyless basic search athttps://api.you.com/mcp?profile=free) that can be added through OpenCursor's existing MCP client config — this PR is just the lighter built-in path for theWebSearchtool itself.Validation
pnpm run check-types— passpnpm run lint— passpnpm vitest run src/agent/tools/web.test.ts— 23/23 pass (12 existing + 11 new)pnpm run test:unit— 935 pass; 1 pre-existing failure inwaitTools.test.ts > Rg > runs ripgrep when available, reproduced on a clean checkout ofmain(environment-specific, unrelated to this change)https://api.ydc-index.io/searchverified reachable and correctly 403s an invalid key (exercising the fallback path); no valid key available in this environment, so live authenticated result parsing is covered by the mocked tests insteadFallback/error handling
via duckduckgolabel.via you.comlabel.I kept this fully optional and followed the existing tool structure in
web.ts— happy to adjust the shape if you'd prefer a config setting over an env var, or to drop the engine label from the header.