refactor(websearch): support arbitrary providers via config#29752
Open
G4brym wants to merge 1 commit into
Open
refactor(websearch): support arbitrary providers via config#29752G4brym wants to merge 1 commit into
G4brym wants to merge 1 commit into
Conversation
Replace the hardcoded exa/parallel split with a generic provider registry.
Users can register any MCP-backed websearch provider via a new
`websearch.providers` map in opencode.json; the built-ins (exa, parallel)
ship pre-registered using the same shape and remain disabled by default.
- New `ConfigWebSearch` schema: `{ default?, providers: Record<id, { enabled?,
label?, url?, tool?, headers?, args?, weight? }> }`. Headers and args support
`{env:NAME}` and `{query}` / `{numResults}` / etc. placeholders.
- `selectWebSearchProvider` now picks from N resolved providers using a
checksum-weighted deterministic split, generalizing the prior 50/50 routing.
- `mcp-websearch.ts` is trimmed to a generic `call({ url, tool, args, headers,
timeout })` transport; per-provider URLs/arg shapes live in the descriptors.
- `webSearchEnabled` takes a boolean (any provider resolved) instead of two
per-provider flags.
Backcompat preserved: `OPENCODE_ENABLE_EXA`, `OPENCODE_EXPERIMENTAL_EXA`,
`OPENCODE_EXPERIMENTAL`, `OPENCODE_ENABLE_PARALLEL`,
`OPENCODE_EXPERIMENTAL_PARALLEL`, `OPENCODE_WEBSEARCH_PROVIDER`,
`EXA_API_KEY`, and `PARALLEL_API_KEY` continue to work unchanged.
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, the related PRs I found are existing websearch feature/documentation PRs from earlier in the codebase, but none appear to be duplicates of the current refactor PR #29752. The current PR is a comprehensive architectural refactor to support arbitrary MCP-backed providers via configuration, which is distinct from:
No duplicate PRs found |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #
Type of change
What does this PR do?
The websearch tool currently hardcodes
exaandparallelas the only providers. Adding another MCP-backed websearch provider means editing the provider schema literal, theif/elsedispatch branch, and the selection logic, plus introducing new env flags.This refactor moves that knowledge out of code and into config. There is now a
websearch.providersmap inopencode.jsonwhere any MCP-backed websearch provider can be registered with{ url, tool, args, headers }. The two built-ins are pre-registered using the same shape and remain disabled by default (same as today). Selection generalises the current 50/50 checksum split to N providers with optional weights.The tool's normalised parameters schema is unchanged, so the model sees the exact same interface.
Backcompat:
OPENCODE_ENABLE_EXA,OPENCODE_EXPERIMENTAL_EXA,OPENCODE_EXPERIMENTAL,OPENCODE_ENABLE_PARALLEL,OPENCODE_EXPERIMENTAL_PARALLEL,OPENCODE_WEBSEARCH_PROVIDER,EXA_API_KEY, andPARALLEL_API_KEYall keep working with no change in behaviour.How did you verify your code works?
bun typecheckinpackages/opencode: cleanbun tsc --noEmitinpackages/sdk/js: cleanbun test test/tool/websearch.test.ts test/tool/parameters.test.ts test/effect/runtime-flags.test.ts: 113/113 passScreenshots / recordings
N/A — no UI changes.
Checklist