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, allowedTools?: string,
): string { ): string {
let disallowedTools = [...DISALLOWED_TOOLS]; let disallowedTools = [...DISALLOWED_TOOLS];
// If user has explicitly allowed some hardcoded disallowed tools, remove them from disallowed list // If user has explicitly allowed some hardcoded disallowed tools, remove them from disallowed list
if (allowedTools) { if (allowedTools) {
const allowedToolsArray = allowedTools.split(",").map(tool => tool.trim()); const allowedToolsArray = allowedTools
disallowedTools = disallowedTools.filter(tool => !allowedToolsArray.includes(tool)); .split(",")
.map((tool) => tool.trim());
disallowedTools = disallowedTools.filter(
(tool) => !allowedToolsArray.includes(tool),
);
} }
let allDisallowedTools = disallowedTools.join(","); let allDisallowedTools = disallowedTools.join(",");
if (customDisallowedTools) { if (customDisallowedTools) {
if (allDisallowedTools) { if (allDisallowedTools) {

View File

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