feat: add Brave Search & Baidu Search integration with sub-source support#42
feat: add Brave Search & Baidu Search integration with sub-source support#42YizukiAme wants to merge 7 commits intoTHU-MAIC:mainfrom
Conversation
- Add 'brave' and 'baidu' to WebSearchProviderId union type - Register providers in WEB_SEARCH_PROVIDERS with configs - Create brave.ts: HTML scraping provider (no API key required) - Create baidu.ts: Qianfan REST API provider (Bearer token auth) - Update API route for multi-provider dispatch via 'provider' param - Generalize resolveWebSearchApiKey for provider-agnostic key resolution - Add BRAVE_API_KEY and BAIDU_API_KEY to .env.example - Update settings store with default configs for new providers - Update i18n strings (zh-CN + en-US) to be provider-agnostic - Update web-search-settings UI with conditional API key display - Pass provider param in generation-preview page fetch call
- Fix snippet regex to match 'class=snippet svelte-...' (not exact 'class=snippet')
- Update title extraction to use 'search-snippet-title' class
- Extract descriptions from 'generic-snippet' div (current) with fallback to 'snippet-description' p (legacy)
- Handle relative date prefixes ('2 days ago -')
- Add provider icons (Brave, Baidu, Tavily)
- Update Baidu sub-source toggles to use Switch components
- Fix webSearchAvailable logic to enable search when any provider is available
- Make Brave API key optional in settings UI
# Conflicts: # components/settings/web-search-settings.tsx
- Add shared normalizeWebSearchQuery util (400-char limit) - Apply query normalization to Brave and Baidu providers - Refactor Tavily to use shared normalizer - Add isSelectedProviderUsable check in toolbar toggle - Add pre-submit web search provider validation in page.tsx - Add i18n strings for provider unavailable toast Fixes toolbar allowing web search enable when selected provider has no API key configured, while another provider (Brave) is available without a key.
edff981 to
6cc35da
Compare
|
Thanks for the contribution, and sorry for the long delay on my side. This PR is now quite far behind If you’re still interested in maintaining this PR, please rebase it onto the latest |
|
Got it! I'll rebase this onto main and update the code to fit the current architecture in a couple of days when I have some bandwidth. |
Summary
Adds Brave Search and Baidu Search as web search providers, with Baidu sub-source configuration (Web Search, Baike, Scholar).
Changes
New Search Providers
Provider Icons
public/icons/brave.png), Baidu (public/icons/baidu.png), and Tavily (public/icons/tavily.jpg)UI Improvements
Switchcomponents (consistent with rest of the UI)Technical Details
lib/web-search/brave.ts: Regex-based HTML parser for Brave's current Svelte-rendered page structurelib/web-search/baidu.ts: AcceptssubSourcesparameter, queries enabled sources in parallellib/store/settings.ts: AddedbaiduSubSourcesstate with per-source togglesapp/api/web-search/route.ts: Brave bypasses API key check; Baidu passes sub-source configcomponents/generation/generation-toolbar.tsx: FixedwebSearchAvailablelogicFiles Changed
lib/web-search/brave.tslib/web-search/baidu.tslib/web-search/types.tsBaiduSubSourcesinterfacelib/web-search/constants.tslib/store/settings.tsapp/api/web-search/route.tsapp/generation-preview/page.tsxcomponents/settings/web-search-settings.tsxcomponents/generation/generation-toolbar.tsxpublic/icons/*Testing
pnpm buildexit code 0)