Repository navigation
Conversation
There was a problem hiding this comment.
The feature works as described. Running OpenCode from source with the simulated model, the websearch tool now gets an optional providerID with an enum of the live provider IDs, and a model call that names exa goes through the usual consent form. On the base, a call with providerID isn't rejected as the description says: the field is quietly ignored. I couldn't run a real search through a pinned provider (no credentials). The websearch, tool-websearch and session-ui sources tests pass, and tsc -b in packages/core is clean.
Public API: the model-facing websearch tool gains an optional providerID input (backwards compatible). POST /api/websearch with providerID while web search is disabled now returns websearch_disabled (400) instead of searching, which is a behaviour change for HTTP callers. The SDK, client, schema and plugin API are unchanged.
Concerns:
- Please rebase on
dev. #64471 replaced the tool output with a plain array of results (the provider is kept only in metadata), which conflicts with the{ provider, results }output and the newProvider:line here. #64475 madecodemodefollow thefull_codemodeflag instead offalse. After rebasing, please check that theproviderIDenum, which is written by the session context hook, still reaches the model in Code Mode. - The model can override a provider the user explicitly chose (see inline). This needs a maintainer decision.
- Tests:
tool-websearch.test.tsgains about 680 lines for one optional field. Please cut it down to a few small cases: the enum appears, an unknown ID fails, disabled beats a pinned provider, and a pinned call doesn't change the saved preference. - Scope: about 330 lines of tool code is a lot for exposing one field. The name sanitising, enum size limits, re-mapping provider-not-found errors after the consent form, and the special 429 message could mostly go, which would make the change easier to review and maintain.
| yield* permission.assertNotDenied(approval) | ||
| return yield* new WebSearch.DisabledError() | ||
| } | ||
| needsConsent = saved.value === undefined |
There was a problem hiding this comment.
When the user has saved a specific provider ("Choose another provider" in the form, or a provider set in config), a pinned providerID still overrides it for that call. A user who picked a provider for cost, privacy or account reasons loses that control, and the model decides instead. Before this change, the tool always used the user's selection. Should a pinned provider only be honoured when the saved choice is random/unset, or should this be confirmed as the intended product behaviour first?
There was a problem hiding this comment.
Taken — I adopted the conservative option.
With a specific saved provider, that choice wins: providerID must match it, and a different id is refused with Web search is pinned to "<saved>" by the user. Omit providerID or pass "<saved>". Only "random" (or no choice yet) lets the model pick. The refusal happens before the search and before any approval prompt, so it costs no provider call and leaves no saved permission.
WebSearch.selection() is now exposed on the service so the tool can read the saved choice without guessing from default() (which cannot tell "random" from a specific id). Test: saved exa + request parallel fails with the message and runs zero queries; saved random + request parallel still searches with parallel. Docs updated on websearch.mdx. See 6083d36.
| .join("\n\n") | ||
| : NO_RESULTS | ||
| const content = [ | ||
| `Provider: ${displayText(output.provider)}`, |
There was a problem hiding this comment.
#64471 just removed provider from the tool output (it is now an array of results, with the provider only in metadata). This extra Provider: line in the content also needs sources.ts to know to skip it. Please rebase and check that it fits the new output shape, or drop it: the provider is already recorded in metadata.
There was a problem hiding this comment.
Done in the rebase — the Provider: line is gone entirely. content is now byte-identical to dev (flat result array, provider only in metadata), so sources.ts needs no special case.
There was a problem hiding this comment.
Confirmed at 6083d36: the Provider: line is gone, the output and content follow #64471's flat result array with the provider only in metadata, and sources.ts is no longer touched. This thread is resolved. The only open point is the enum one from my latest review: when a specific provider is saved, the enum still lists every id.
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
f4cc7b9 to
7f70a46
Compare
|
Rebased onto Rebase
Size
On the override question Happy to defer to you here. The intent was that If you'd rather user choice be absolute, I can either drop the request path or gate it behind a flag — say which you prefer and I'll adjust. Also noted: on |
`WebSearch.Input.providerID` already exists in the schema, the HTTP API and the plugin host, but the model-facing tool only declares `query`, so a model that names a provider has it silently dropped. Wire the field through. - The input gains an optional `providerID`, and the session context hook rewrites it into a JSON-Schema enum built from the live provider registry, so providers registered by plugins appear automatically. Ids are de-duplicated and sorted, so the emitted schema is byte-identical while the set is unchanged. - A pinned provider is used as-is for that one call: no failover, no cooldown write, and no change to the saved preference — only the user's answers to the consent form write `websearch:provider`. - A provider the user saved outranks the request: with a specific saved choice, `providerID` must match it, so a search can never leave the provider the user chose. With `"random"` (or before consent) the model is free to pick. - An unknown id fails with the available ids instead of falling back, and `WebSearch.query` now also honours a saved "disabled" for explicit-provider callers.
7f70a46 to
6083d36
Compare
There was a problem hiding this comment.
Re-reviewed at 6083d36. All my earlier points are resolved: a provider the user saved (in the consent form or in config) now wins, and a different providerID is refused before the approval prompt, with policy deny rules still checked first. The PR is rebased onto #64471 and #64475, so the output follows the new array format, the Provider: line is gone, and sources.ts is no longer touched. The Code Mode limitation is documented, and the change and its tests are much smaller. The websearch tests (62 pass) and tsc -b in packages/core pass.
Public API: the model-facing websearch tool gains an optional providerID (backwards compatible). POST /api/websearch with providerID while web search is disabled now returns websearch_disabled instead of searching, which is a behaviour change for HTTP callers. WebSearch.Service.selection() is new but internal to core and not exposed to plugins. The SDK, client, schema and plugin API are unchanged.
One remaining point, not blocking: when a specific provider is saved, the enum still lists every provider (inline).
| ...properties, | ||
| providerID: { | ||
| type: "string", | ||
| enum: Array.from(new Set(providers.map((provider) => provider.id))).toSorted(), |
There was a problem hiding this comment.
When the user has saved a specific provider, the tool refuses every other id, but this enum still lists all providers. The model is invited to make calls that will always fail. Could the hook publish only the saved id in that case (or drop providerID from the schema), and keep the full list for random or no choice yet? It would only need the same websearch.selection() read the tool already does.
Issue for this PR
Closes #
Type of change
What does this PR do?
WebSearch.Input.providerIDalready exists in the schema, the HTTP API and the plugin host, but the model-facing tool only declaresquery, so a model that names a provider has that field silently dropped. This wires the existing field through to the model.The input gains an optional
providerID, and the session context hook rewrites it into a JSON-Schema enum built from the live provider registry, so providers registered by plugins appear automatically. A pinned provider is used as-is for that one call: no failover, no cooldown write, and no change to the saved preference — only the user's answers to the consent form writewebsearch:provider. An unknown id fails with the available ids instead of falling back, andWebSearch.querynow also honours a saved "disabled" for explicit-provider callers.How did you verify your code works?
Ran from source with the simulated model: the advertised schema contains the enum, a call naming
exagoes through the normal consent form, an unknown id fails with the available list, and a pinned call leaveswebsearch:provideruntouched.bun run --cwd packages/core test test/tool-websearch.test.ts test/websearch.test.ts test/plugin/websearch.test.tsandbun run --cwd packages/core typecheckpass.Screenshots / recordings
No UI change.
Checklist
Added by the opencode bot (AI-generated).
Public API: adds optional providerID to the model-facing websearch tool; POST /api/websearch with providerID now honours a disabled web search (otherwise backwards compatible)