Skip to content

feat: add optional you.com search provider for web_search - #55

Open
mouse-value-add wants to merge 1 commit into
LiuMengxuan04:mainfrom
mouse-value-add:feat/youcom-search-integration
Open

mouse-value-add wants to merge 1 commit into
LiuMengxuan04:mainfrom
mouse-value-add:feat/youcom-search-integration

Conversation

@mouse-value-add

Copy link
Copy Markdown

What this adds

An optional You.com engine for the built-in web_search tool. src/utils/web.ts already has a SearchProvider fallback chain (duckduckgo-litesogou), so this adds a third provider that reuses the same loop, retry helper, and SearchResult shape:

  • youcom is only tried first when YDC_API_KEY is set in the environment
  • whitespace-only keys are treated as unset
  • if the request fails, returns non-200, or the JSON payload has no usable hits, the chain continues to DuckDuckGo Lite and Sogou exactly as before

So with no key configured, nothing changes for existing users.

Setup

export YDC_API_KEY=***   # from https://you.com/platform/api-keys

That's it — no config file changes, no new dependencies (plain fetch with an X-API-Key header against https://api.ydc-index.io/search), keeping with the lightweight principle in CONTRIBUTING.md.

What changed

  • src/utils/web.ts: new youcom member of SearchProvider, getSearchProviders() builds the chain (youcom first only when the key is set), a JSON fetch branch, and parseYoucomResults() mapping hits[] to the existing SearchResult type
  • USAGE.md: short "Web search backends" subsection under Configuration documenting the chain and the opt-in
  • test/web-search-provider.test.ts: new suite (node:test, same style as the rest of test/) covering:
    • default chain is unchanged without the key
    • youcom is first when the key is set
    • whitespace-only key is ignored
    • a malformed youcom response falls back to DuckDuckGo (fetch stubbed)

Validation

  • npm run check (tsc --noEmit) — clean
  • npm run lint — clean
  • npm test — 278 passing, 0 failing (274 baseline + 4 new)
  • Live API check (with a real key): YDC_API_KEY=*** npx tsx -e "import('./src/utils/web.js').then(m => m.searchDuckDuckGoLite({ query: 'mcp spec' })).then(r => console.log(r.base_resp.source, r.organic.length))" — expected youcom 5

Happy to adjust the shape if you'd rather have the provider list configurable via settings.json instead of env-only, or drop the docs change.

Add a 'youcom' engine to the existing SearchProvider fallback chain in
src/utils/web.ts. It is only tried first when YDC_API_KEY is set;
DuckDuckGo Lite and Sogou remain the defaults, and requests fall back
to them on failure, so default behavior is unchanged.

- opt-in via YDC_API_KEY (whitespace-only treated as unset)
- no new dependencies (global fetch, X-API-Key header)
- JSON response parsed into the existing SearchResult shape
- docs in USAGE.md; tests in test/web-search-provider.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant