This commit is contained in:
Ashwin Bhat
2025-05-27 17:06:57 -07:00
parent f93fbb32ec
commit f18a16aa0f
2 changed files with 19 additions and 9 deletions

View File

@@ -61,13 +61,17 @@ export function buildDisallowedToolsString(
allowedTools?: string,
): string {
let disallowedTools = [...DISALLOWED_TOOLS];
// If user has explicitly allowed some hardcoded disallowed tools, remove them from disallowed list
if (allowedTools) {
const allowedToolsArray = allowedTools.split(",").map(tool => tool.trim());
disallowedTools = disallowedTools.filter(tool => !allowedToolsArray.includes(tool));
const allowedToolsArray = allowedTools
.split(",")
.map((tool) => tool.trim());
disallowedTools = disallowedTools.filter(
(tool) => !allowedToolsArray.includes(tool),
);
}
let allDisallowedTools = disallowedTools.join(",");
if (customDisallowedTools) {
if (allDisallowedTools) {

View File

@@ -726,11 +726,14 @@ describe("buildDisallowedToolsString", () => {
test("should remove hardcoded disallowed tools if they are in allowed tools", () => {
const customDisallowedTools = "BadTool1,BadTool2";
const allowedTools = "WebSearch,SomeOtherTool";
const result = buildDisallowedToolsString(customDisallowedTools, allowedTools);
const result = buildDisallowedToolsString(
customDisallowedTools,
allowedTools,
);
// WebSearch should be removed from disallowed since it's in allowed
expect(result).not.toContain("WebSearch");
// WebFetch should still be disallowed since it's not in allowed
expect(result).toContain("WebFetch");
@@ -746,7 +749,7 @@ describe("buildDisallowedToolsString", () => {
// Both hardcoded disallowed tools should be removed
expect(result).not.toContain("WebSearch");
expect(result).not.toContain("WebFetch");
// Result should be empty since no custom disallowed tools provided
expect(result).toBe("");
});
@@ -754,12 +757,15 @@ describe("buildDisallowedToolsString", () => {
test("should handle custom disallowed tools when all hardcoded tools are overridden", () => {
const customDisallowedTools = "BadTool1,BadTool2";
const allowedTools = "WebSearch,WebFetch";
const result = buildDisallowedToolsString(customDisallowedTools, allowedTools);
const result = buildDisallowedToolsString(
customDisallowedTools,
allowedTools,
);
// Hardcoded tools should be removed
expect(result).not.toContain("WebSearch");
expect(result).not.toContain("WebFetch");
// Only custom disallowed tools should remain
expect(result).toBe("BadTool1,BadTool2");
});