fix: Make --tools work (#167)

This commit is contained in:
Devansh Jain
2025-12-08 18:34:00 -08:00
committed by GitHub
parent 723dd17d47
commit 38b532e8ba
2 changed files with 23 additions and 2 deletions

View File

@@ -65,6 +65,12 @@ export async function handleHeadlessCommand(
allowPositionals: true, allowPositionals: true,
}); });
// Set tool filter if provided (controls which tools are loaded)
if (values.tools !== undefined) {
const { toolFilter } = await import("./tools/filter");
toolFilter.setEnabledTools(values.tools as string);
}
// Get prompt from either positional args or stdin // Get prompt from either positional args or stdin
let prompt = positionals.slice(2).join(" "); let prompt = positionals.slice(2).join(" ");

View File

@@ -62,5 +62,20 @@ class ToolFilterManager {
} }
} }
// Singleton instance // Use globalThis to ensure singleton across bundle
export const toolFilter = new ToolFilterManager(); // This prevents Bun's bundler from creating duplicate instances
const FILTER_KEY = Symbol.for("@letta/toolFilter");
type GlobalWithFilter = typeof globalThis & {
[key: symbol]: ToolFilterManager;
};
function getFilter(): ToolFilterManager {
const global = globalThis as GlobalWithFilter;
if (!global[FILTER_KEY]) {
global[FILTER_KEY] = new ToolFilterManager();
}
return global[FILTER_KEY];
}
export const toolFilter = getFilter();