effect: move tool flags into RuntimeFlags (#27198)

This commit is contained in:
Kit Langton
2026-05-12 21:45:53 -04:00
committed by GitHub
parent c9df833d2c
commit da689d77c4
7 changed files with 88 additions and 47 deletions
+7 -6
View File
@@ -3,9 +3,9 @@ import { HttpClient } from "effect/unstable/http"
import * as Tool from "./tool"
import * as McpWebSearch from "./mcp-websearch"
import DESCRIPTION from "./websearch.txt"
import { Flag } from "@opencode-ai/core/flag/flag"
import { checksum } from "@opencode-ai/core/util/encode"
import { InstallationVersion } from "@opencode-ai/core/installation/version"
import { RuntimeFlags } from "@/effect/runtime-flags"
export const Parameters = Schema.Struct({
query: Schema.String.annotate({ description: "Websearch query" }),
@@ -27,10 +27,7 @@ export const Parameters = Schema.Struct({
const WebSearchProviderSchema = Schema.Literals(["exa", "parallel"])
export type WebSearchProvider = Schema.Schema.Type<typeof WebSearchProviderSchema>
export function selectWebSearchProvider(
sessionID: string,
flags = { exa: Flag.OPENCODE_ENABLE_EXA, parallel: Flag.OPENCODE_ENABLE_PARALLEL },
): WebSearchProvider {
export function selectWebSearchProvider(sessionID: string, flags = { exa: false, parallel: false }): WebSearchProvider {
const override = process.env.OPENCODE_WEBSEARCH_PROVIDER
if (override === "exa" || override === "parallel") return override
if (flags.parallel) return "parallel"
@@ -103,6 +100,7 @@ export const WebSearchTool = Tool.define(
"websearch",
Effect.gen(function* () {
const http = yield* HttpClient.HttpClient
const flags = yield* RuntimeFlags.Service
return {
get description() {
@@ -111,7 +109,10 @@ export const WebSearchTool = Tool.define(
parameters: Parameters,
execute: (params: Schema.Schema.Type<typeof Parameters>, ctx: Tool.Context) =>
Effect.gen(function* () {
const provider = selectWebSearchProvider(ctx.sessionID)
const provider = selectWebSearchProvider(ctx.sessionID, {
exa: flags.enableExa,
parallel: flags.enableParallel,
})
const title = webSearchProviderLabel(provider)
yield* ctx.metadata({ title: `${title} "${params.query}"`, metadata: { provider } })