Skip to content

refactor(websearch): support arbitrary providers via config - #29752

Closed
G4brym wants to merge 1 commit into
anomalyco:devfrom
G4brym:refactor/websearch-generic-providers
Closed

G4brym wants to merge 1 commit into
anomalyco:devfrom
G4brym:refactor/websearch-generic-providers

Conversation

@G4brym

@G4brym G4brym commented May 28, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The websearch tool currently hardcodes exa and parallel as the only providers. Adding another MCP-backed websearch provider means editing the provider schema literal, the if/else dispatch 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.providers map in opencode.json where 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, and PARALLEL_API_KEY all keep working with no change in behaviour.

How did you verify your code works?

  • bun typecheck in packages/opencode: clean
  • bun tsc --noEmit in packages/sdk/js: clean
  • bun test test/tool/websearch.test.ts test/tool/parameters.test.ts test/effect/runtime-flags.test.ts: 113/113 pass
  • Updated the websearch tests to cover weighted N-way selection, env override across arbitrary ids, env-flag enable of built-ins, config-driven enable/disable, and user-defined provider registration.

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 28, 2026
@github-actions

Copy link
Copy Markdown
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

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@G4brym
G4brym marked this pull request as ready for review May 28, 2026 14:51
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.
@G4brym
G4brym force-pushed the refactor/websearch-generic-providers branch from fb0ef78 to b3d4ee1 Compare June 1, 2026 15:36
@G4brym G4brym closed this Jun 2, 2026
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