Skip to content

Commit 95be6de

Browse files
Метелев Вадим4ebuRushka
authored andcommitted
fix(websearch): make the websearch tool available to all providers
The native websearch tool was hidden for every provider except opencode/opencode-go unless undocumented env vars were set (anomalyco#44307). - drop the provider whitelist from the tool registry; inclusion is now controlled by config: websearch.enabled !== false (default on) - add a first-class websearch section to opencode.json (enabled, provider) - backend pin priority: config.websearch.provider > OPENCODE_WEBSEARCH_PROVIDER > legacy OPENCODE_ENABLE_EXA/_PARALLEL > per-session checksum split - log a one-shot deprecation warning when legacy enablement env vars are set
1 parent 88c6c7a commit 95be6de

3 files changed

Lines changed: 45 additions & 15 deletions

File tree

‎packages/core/src/v1/config/config.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,20 @@ export const Info = Schema.Struct({
127127
layout: Schema.optional(ConfigLayoutV1.Layout).annotate({ description: "@deprecated Always uses stretch layout." }),
128128
permission: Schema.optional(ConfigPermissionV1.Info),
129129
tools: Schema.optional(Schema.Record(Schema.String, Schema.Boolean)),
130+
websearch: Schema.optional(
131+
Schema.Struct({
132+
enabled: Schema.optional(Schema.Boolean).annotate({
133+
description:
134+
"Enable the native websearch tool for all model providers (default: true). Set to false to hide the tool entirely",
135+
}),
136+
provider: Schema.optional(Schema.Literals(["auto", "exa", "parallel"])).annotate({
137+
description:
138+
"Web search backend. 'auto' picks a backend per session; 'exa' or 'parallel' pins that backend for every call",
139+
}),
140+
}),
141+
).annotate({
142+
description: "Native web search tool configuration, see https://opencode.ai/docs/tools",
143+
}),
130144
attachment: Schema.optional(ConfigAttachmentV1.Info).annotate({
131145
description: "Attachment processing configuration, including image size limits and resizing behavior",
132146
}),

‎packages/opencode/src/tool/registry.ts‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,6 @@ import { MCP } from "@/mcp"
5555
import { PermissionV1 } from "@opencode-ai/core/v1/permission"
5656
import { McpCatalog } from "@/mcp/catalog"
5757

58-
export function webSearchEnabled(providerID: ProviderV2.ID, flags = { exa: false, parallel: false }) {
59-
return (
60-
providerID === ProviderV2.ID.opencode ||
61-
providerID === ProviderV2.ID.make("opencode-go") ||
62-
flags.exa ||
63-
flags.parallel
64-
)
65-
}
66-
6758
type TaskDef = Tool.InferDef<typeof TaskTool>
6859
type ReadDef = Tool.InferDef<typeof ReadTool>
6960

@@ -289,10 +280,9 @@ const layer = Layer.effect(
289280
})
290281

291282
const tools: Interface["tools"] = Effect.fn("ToolRegistry.tools")(function* (input) {
283+
const cfg = yield* config.get()
292284
const filtered = (yield* all()).filter((tool) => {
293-
if (tool.id === WebSearchTool.id) {
294-
return webSearchEnabled(input.providerID, { exa: flags.enableExa, parallel: flags.enableParallel })
295-
}
285+
if (tool.id === WebSearchTool.id) return cfg.websearch?.enabled !== false
296286

297287
const usePatch =
298288
input.modelID.includes("gpt-") && !input.modelID.includes("oss") && !input.modelID.includes("gpt-4")

‎packages/opencode/src/tool/websearch.ts‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import DESCRIPTION from "./websearch.txt"
66
import { checksum } from "@opencode-ai/core/util/encode"
77
import { InstallationVersion } from "@opencode-ai/core/installation/version"
88
import { RuntimeFlags } from "@/effect/runtime-flags"
9+
import { Config } from "@/config/config"
910

1011
export const Parameters = Schema.Struct({
1112
query: Schema.String.annotate({ description: "Websearch query" }),
@@ -27,15 +28,35 @@ export const Parameters = Schema.Struct({
2728
const WebSearchProviderSchema = Schema.Literals(["exa", "parallel"])
2829
export type WebSearchProvider = Schema.Schema.Type<typeof WebSearchProviderSchema>
2930

30-
export function selectWebSearchProvider(sessionID: string, flags = { exa: false, parallel: false }): WebSearchProvider {
31+
// Backend pin priority (decision D3): config.websearch.provider > OPENCODE_WEBSEARCH_PROVIDER
32+
// > legacy OPENCODE_ENABLE_EXA/_PARALLEL > per-session checksum split.
33+
export function selectWebSearchProvider(
34+
sessionID: string,
35+
options: {
36+
provider?: "auto" | WebSearchProvider
37+
exa?: boolean
38+
parallel?: boolean
39+
} = {},
40+
): WebSearchProvider {
41+
if (options.provider === "exa" || options.provider === "parallel") return options.provider
3142
const override = process.env.OPENCODE_WEBSEARCH_PROVIDER
3243
if (override === "exa" || override === "parallel") return override
33-
if (flags.parallel) return "parallel"
34-
if (flags.exa) return "exa"
44+
if (options.parallel) return "parallel"
45+
if (options.exa) return "exa"
3546

3647
return Number.parseInt(checksum(sessionID) ?? "0", 36) % 2 === 0 ? "exa" : "parallel"
3748
}
3849

50+
let legacyEnvWarned = false
51+
52+
function warnLegacyEnvFlags(flags: { enableExa: boolean; enableParallel: boolean }) {
53+
if (legacyEnvWarned || (!flags.enableExa && !flags.enableParallel)) return Effect.void
54+
legacyEnvWarned = true
55+
return Effect.logWarning(
56+
"OPENCODE_ENABLE_EXA / OPENCODE_ENABLE_PARALLEL no longer enable or disable websearch; the tool is available to all providers by default. They now only pin the backend — use the websearch.provider section in opencode.json instead",
57+
)
58+
}
59+
3960
export function webSearchProviderLabel(provider: unknown) {
4061
if (provider === "parallel") return "Parallel Web Search"
4162
if (provider === "exa") return "Exa Web Search"
@@ -101,6 +122,9 @@ export const WebSearchTool = Tool.define(
101122
Effect.gen(function* () {
102123
const http = yield* HttpClient.HttpClient
103124
const flags = yield* RuntimeFlags.Service
125+
const config = yield* Config.Service
126+
127+
yield* warnLegacyEnvFlags(flags)
104128

105129
return {
106130
get description() {
@@ -109,7 +133,9 @@ export const WebSearchTool = Tool.define(
109133
parameters: Parameters,
110134
execute: (params: Schema.Schema.Type<typeof Parameters>, ctx: Tool.Context) =>
111135
Effect.gen(function* () {
136+
const cfg = yield* config.get()
112137
const provider = selectWebSearchProvider(ctx.sessionID, {
138+
provider: cfg.websearch?.provider,
113139
exa: flags.enableExa,
114140
parallel: flags.enableParallel,
115141
})

0 commit comments

Comments
 (0)