diff --git a/core/config/profile/doLoadConfig.ts b/core/config/profile/doLoadConfig.ts index 95db22eb9..040fd3b41 100644 --- a/core/config/profile/doLoadConfig.ts +++ b/core/config/profile/doLoadConfig.ts @@ -98,6 +98,7 @@ export default async function doLoadConfig(options: { const uniqueId = await ide.getUniqueId(); const ideSettings = await ideSettingsPromise; const workOsAccessToken = await controlPlaneClient.getAccessToken(); + const isSignedIn = await controlPlaneClient.isSignedIn(); // Migrations for old config files // Removes @@ -285,6 +286,7 @@ export default async function doLoadConfig(options: { rules: newConfig.rules, enableExperimentalTools: newConfig.experimental?.enableExperimentalTools ?? false, + isSignedIn, }), ); diff --git a/core/index.d.ts b/core/index.d.ts index 0962c212b..5a958a04e 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1111,6 +1111,7 @@ interface ToolChoice { export interface ConfigDependentToolParams { rules: RuleWithSource[]; enableExperimentalTools: boolean; + isSignedIn: boolean; } export type GetTool = (params: ConfigDependentToolParams) => Tool; diff --git a/core/tools/definitions/toolDefinitions.test.ts b/core/tools/definitions/toolDefinitions.test.ts index a6e3fd717..abeac08ef 100644 --- a/core/tools/definitions/toolDefinitions.test.ts +++ b/core/tools/definitions/toolDefinitions.test.ts @@ -7,6 +7,7 @@ describe("Tool Definitions", () => { const mockParams: ConfigDependentToolParams = { rules: [], enableExperimentalTools: false, + isSignedIn: false, }; // Helper function to get the actual tool object diff --git a/core/tools/index.ts b/core/tools/index.ts index 540f4d2bb..850d89349 100644 --- a/core/tools/index.ts +++ b/core/tools/index.ts @@ -11,7 +11,6 @@ const getBaseToolDefinitions = () => [ toolDefinitions.createNewFileTool, toolDefinitions.runTerminalCommandTool, toolDefinitions.globSearchTool, - toolDefinitions.searchWebTool, toolDefinitions.viewDiffTool, toolDefinitions.readCurrentlyOpenFileTool, toolDefinitions.lsTool, @@ -27,6 +26,8 @@ export const getConfigDependentToolDefinitions = ( toolDefinitions.searchAndReplaceInFileTool, // Keep edit file tool available for models that need it toolDefinitions.editFileTool, + // Web search is only available for signed-in users + ...(params.isSignedIn ? [toolDefinitions.searchWebTool] : []), ...(params.enableExperimentalTools ? [ toolDefinitions.viewRepoMapTool, diff --git a/core/tools/searchWebGating.vitest.ts b/core/tools/searchWebGating.vitest.ts new file mode 100644 index 000000000..e68acdd52 --- /dev/null +++ b/core/tools/searchWebGating.vitest.ts @@ -0,0 +1,30 @@ +import { test, expect } from "vitest"; +import { getConfigDependentToolDefinitions } from "./index"; +import { BuiltInToolNames } from "./builtIn"; + +test("searchWeb tool is only available when user is signed in", () => { + // Test with signed-in user + const signedInTools = getConfigDependentToolDefinitions({ + rules: [], + enableExperimentalTools: false, + isSignedIn: true, + }); + + const searchWebToolSignedIn = signedInTools.find( + (tool) => tool.function.name === BuiltInToolNames.SearchWeb, + ); + expect(searchWebToolSignedIn).toBeDefined(); + expect(searchWebToolSignedIn?.displayTitle).toBe("Search Web"); + + // Test with non-signed-in user + const notSignedInTools = getConfigDependentToolDefinitions({ + rules: [], + enableExperimentalTools: false, + isSignedIn: false, + }); + + const searchWebToolNotSignedIn = notSignedInTools.find( + (tool) => tool.function.name === BuiltInToolNames.SearchWeb, + ); + expect(searchWebToolNotSignedIn).toBeUndefined(); +});