fix: 🔒 Simpler fix to exclude search_web tool to signed in users (#7165)
* fix: 🔒 Simpler fix to exclude search_web tool to signed in users * fix: 💡 Revise comment to clarify only sign in is required
This commit is contained in:
parent
92c1852234
commit
a4c4f79fd0
5 changed files with 36 additions and 1 deletions
|
|
@ -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,
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
|||
1
core/index.d.ts
vendored
1
core/index.d.ts
vendored
|
|
@ -1111,6 +1111,7 @@ interface ToolChoice {
|
|||
export interface ConfigDependentToolParams {
|
||||
rules: RuleWithSource[];
|
||||
enableExperimentalTools: boolean;
|
||||
isSignedIn: boolean;
|
||||
}
|
||||
|
||||
export type GetTool = (params: ConfigDependentToolParams) => Tool;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ describe("Tool Definitions", () => {
|
|||
const mockParams: ConfigDependentToolParams = {
|
||||
rules: [],
|
||||
enableExperimentalTools: false,
|
||||
isSignedIn: false,
|
||||
};
|
||||
|
||||
// Helper function to get the actual tool object
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
30
core/tools/searchWebGating.vitest.ts
Normal file
30
core/tools/searchWebGating.vitest.ts
Normal file
|
|
@ -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();
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue